-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Add PAT scope filtering for stdio server #1741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds PAT (Personal Access Token) scope filtering for the stdio server, enabling the server to hide tools that require OAuth scopes not granted to the token. The implementation fetches token scopes via an HTTP HEAD request to GitHub's API and applies filtering at server startup.
Key changes:
- New
pkg/scopespackage with scope hierarchy-aware filtering and HTTP-based scope fetching - Integration with the inventory system to filter tools based on token scopes
- Opt-in
--enable-scope-filteringCLI flag (disabled by default for graceful degradation)
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pkg/scopes/filter.go | Package documentation for scope filtering utilities |
| pkg/scopes/scopes.go | Adds HasRequiredScopes function and internal expandScopeSet helper for hierarchy-aware scope checking |
| pkg/scopes/scopes_test.go | Comprehensive test coverage for scope expansion and filtering logic |
| pkg/scopes/fetcher.go | HTTP fetcher implementation that retrieves token scopes via HEAD request to GitHub API |
| pkg/scopes/fetcher_test.go | Unit tests for scope fetcher with mock HTTP servers |
| pkg/github/scope_filter.go | Creates CreateToolScopeFilter function that bridges scopes package with inventory system |
| pkg/github/scope_filter_test.go | Tests for scope filter integration with inventory builder |
| internal/ghmcp/server.go | Integrates scope filtering into server startup, adding TokenScopes config field and fetchTokenScopesForHost helper |
| cmd/github-mcp-server/main.go | Adds --enable-scope-filtering CLI flag with viper binding |
| README.md | Auto-generated documentation updates showing reordered accepted scopes (cosmetic) |
c4c6491 to
742dfe3
Compare
a496f06 to
7c31fda
Compare
omgitsads
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
The base branch was changed.
Add the ability to filter tools based on token scopes for PAT users. This uses an HTTP HEAD request to GitHub's API to discover token scopes. New components: - pkg/scopes/filter.go: HasRequiredScopes checks if scopes satisfy tool requirements - pkg/scopes/fetcher.go: FetchTokenScopes gets scopes via HTTP HEAD to GitHub API - pkg/github/scope_filter.go: CreateScopeFilter creates inventory.ToolFilter Integration: - Add --filter-by-scope flag to stdio command (disabled by default) - When enabled, fetches token scopes on startup - Tools requiring unavailable scopes are hidden from tool list - Gracefully continues without filtering if scope fetch fails (logs warning) This allows the OSS server to have similar scope-based tool visibility as the remote server, and the filter logic can be reused by remote server.
Scope filtering is now a built-in feature rather than a configurable option. The server automatically fetches token scopes at startup and filters tools accordingly. If scope detection fails, it logs a warning and continues with all tools available.
- Scope filtering only applies to classic PATs which return X-OAuth-Scopes - Fine-grained PATs and other token types skip filtering (all tools shown) - Updated docs to clarify PAT filtering vs OAuth scope challenges
The README already has auto-generated tool documentation with scopes. Keep only the scope hierarchy explanation which is structural.
Co-authored-by: Copilot <[email protected]>
e04a578 to
9bf0cf5
Compare
Summary
Automatically filter tools based on the user's PAT OAuth scopes. This ensures users only see tools their token has permission to use, reducing clutter and preventing errors from attempting operations without the required scopes.
How It Works
ghp_prefix)X-OAuth-ScopesheaderToken Type Behavior
ghp_)github_pat_)Changes
New Components in
pkg/scopes/filter.go:HasRequiredScopes()checks if user scopes satisfy tool requirements using the scope hierarchyfetcher.go:FetchTokenScopes()gets token scopes via HTTP HEAD request (readsX-OAuth-Scopesheader)New Components in
pkg/github/scope_filter.go:CreateScopeFilter()creates aninventory.ToolFilterfor scope-based filteringIntegration
docs/scope-filtering.mdLibrary Usage (for Remote Server)
The scope filtering logic is designed to be reusable:
Testing
HasRequiredScopesFetchTokenScopeswith mock HTTP serverCreateScopeFilterStacked On
This PR is stacked on #1740 (scope hierarchy PR) which provides the
ExpandScopesfunction and scope definitions used here.