fix: OAuth scope filtering to respect enabled tools filter #153
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🐛 Problem
When using the
--enabled-toolsflag orENABLED_TOOLSenvironment variable to filter available tools, the OAuth authorization flow was still requesting permissions for all tools instead of only the filtered ones.Example:
🔍 Root Cause
The architecture had a timing mismatch:
buildScopesFromEndpoints()) happened early in initializationendpoints.jsonregardless of tool filteringregisterGraphTools()) happened later during tool registration✅ Solution
Modified the scope building pipeline to respect tool filtering:
src/auth.ts: AddedenabledToolsPatternparameter tobuildScopesFromEndpoints()src/index.ts: Passargs.enabledToolsto scope builder during initializationsrc/server.ts: Passthis.options.enabledToolsto scope builder in OAuth discovery endpoints/.well-known/oauth-authorization-server/.well-known/oauth-protected-resource📝 Changes
Modified Files:
src/auth.ts- EnhancedbuildScopesFromEndpoints()with tool filteringsrc/index.ts- Pass enabled tools pattern to scope buildersrc/server.ts- Pass enabled tools pattern in OAuth endpoints🧪 Testing
Before:
After:
Test Steps:
npm run buildnpx @softeria/ms-365-mcp-server --logoutnpx @softeria/ms-365-mcp-server --http 3000 --enabled-tools "mail|calendar" -vBuilding scopes with tool filter pattern: mail|calendar💡 Benefits
🔄 Backward Compatibility
✅ Fully backward compatible
📚 Related
--read-onlymode for granular access control