@@ -50,10 +50,31 @@ const SCOPE_HIERARCHY: ScopeHierarchy = {
5050 'Contacts.ReadWrite' : [ 'Contacts.Read' ] ,
5151} ;
5252
53- function buildScopesFromEndpoints ( includeWorkAccountScopes : boolean = false ) : string [ ] {
53+ function buildScopesFromEndpoints (
54+ includeWorkAccountScopes : boolean = false ,
55+ enabledToolsPattern ?: string
56+ ) : string [ ] {
5457 const scopesSet = new Set < string > ( ) ;
5558
59+ // Create regex for tool filtering if pattern is provided
60+ let enabledToolsRegex : RegExp | undefined ;
61+ if ( enabledToolsPattern ) {
62+ try {
63+ enabledToolsRegex = new RegExp ( enabledToolsPattern , 'i' ) ;
64+ logger . info ( `Building scopes with tool filter pattern: ${ enabledToolsPattern } ` ) ;
65+ } catch ( error ) {
66+ logger . error (
67+ `Invalid tool filter regex pattern: ${ enabledToolsPattern } . Building scopes without filter.`
68+ ) ;
69+ }
70+ }
71+
5672 endpoints . default . forEach ( ( endpoint ) => {
73+ // Skip endpoints that don't match the tool filter
74+ if ( enabledToolsRegex && ! enabledToolsRegex . test ( endpoint . toolName ) ) {
75+ return ;
76+ }
77+
5778 // Skip endpoints that only have workScopes if not in work mode
5879 if ( ! includeWorkAccountScopes && ! endpoint . scopes && endpoint . workScopes ) {
5980 return ;
@@ -77,7 +98,12 @@ function buildScopesFromEndpoints(includeWorkAccountScopes: boolean = false): st
7798 }
7899 } ) ;
79100
80- return Array . from ( scopesSet ) ;
101+ const scopes = Array . from ( scopesSet ) ;
102+ if ( enabledToolsPattern ) {
103+ logger . info ( `Built ${ scopes . length } scopes for filtered tools: ${ scopes . join ( ', ' ) } ` ) ;
104+ }
105+
106+ return scopes ;
81107}
82108
83109interface LoginTestResult {
0 commit comments