|
| 1 | +# OAuth Scope Filtering |
| 2 | + |
| 3 | +The GitHub MCP Server automatically filters available tools based on your Personal Access Token's (PAT) OAuth scopes. This ensures you only see tools that your token has permission to use, reducing clutter and preventing errors from attempting operations your token can't perform. |
| 4 | + |
| 5 | +## How It Works |
| 6 | + |
| 7 | +When the server starts, it makes a lightweight HTTP HEAD request to the GitHub API to discover your token's scopes from the `X-OAuth-Scopes` header. Tools that require scopes your token doesn't have are automatically hidden. |
| 8 | + |
| 9 | +**Example:** If your token only has `repo` and `gist` scopes, you won't see tools that require `admin:org`, `project`, or `notifications` scopes. |
| 10 | + |
| 11 | +## Checking Your Token's Scopes |
| 12 | + |
| 13 | +To see what scopes your token has, you can run: |
| 14 | + |
| 15 | +```bash |
| 16 | +curl -sI -H "Authorization: Bearer $GITHUB_PERSONAL_ACCESS_TOKEN" \ |
| 17 | + https://api.github.com/user | grep -i x-oauth-scopes |
| 18 | +``` |
| 19 | + |
| 20 | +Example output: |
| 21 | +``` |
| 22 | +x-oauth-scopes: delete_repo, gist, read:org, repo |
| 23 | +``` |
| 24 | + |
| 25 | +## Scopes and Tools |
| 26 | + |
| 27 | +The following table shows which OAuth scopes are required for each category of tools: |
| 28 | + |
| 29 | +| Scope | Tools Enabled | |
| 30 | +|-------|---------------| |
| 31 | +| `repo` | Repository operations, issues, PRs, commits, branches, code search, workflows | |
| 32 | +| `public_repo` | Star/unstar public repositories (implicit with `repo`) | |
| 33 | +| `read:org` | Read organization info, list teams, team members | |
| 34 | +| `write:org` | Organization management (includes `read:org`) | |
| 35 | +| `admin:org` | Full organization administration (includes `write:org`, `read:org`) | |
| 36 | +| `gist` | Create, update, and manage gists | |
| 37 | +| `notifications` | List, manage, and dismiss notifications | |
| 38 | +| `read:project` | Read GitHub Projects | |
| 39 | +| `project` | Create and manage GitHub Projects (includes `read:project`) | |
| 40 | +| `security_events` | Code scanning, Dependabot, secret scanning alerts (implicit with `repo`) | |
| 41 | +| `user` | Update user profile | |
| 42 | +| `read:user` | Read user profile information | |
| 43 | + |
| 44 | +### Scope Hierarchy |
| 45 | + |
| 46 | +Some scopes implicitly include others: |
| 47 | + |
| 48 | +- `repo` → includes `public_repo`, `security_events` |
| 49 | +- `admin:org` → includes `write:org` → includes `read:org` |
| 50 | +- `project` → includes `read:project` |
| 51 | + |
| 52 | +This means if your token has `repo`, tools requiring `security_events` will also be available. |
| 53 | + |
| 54 | +## Recommended Token Scopes |
| 55 | + |
| 56 | +For full functionality, we recommend these scopes: |
| 57 | + |
| 58 | +| Use Case | Recommended Scopes | |
| 59 | +|----------|-------------------| |
| 60 | +| Basic development | `repo`, `read:org` | |
| 61 | +| Full development | `repo`, `admin:org`, `gist`, `notifications`, `project` | |
| 62 | +| Read-only access | `repo` (with `--read-only` flag) | |
| 63 | +| Security analysis | `repo` (includes `security_events`) | |
| 64 | + |
| 65 | +## Graceful Degradation |
| 66 | + |
| 67 | +If the server cannot fetch your token's scopes (e.g., network issues, rate limiting), it logs a warning and continues **without filtering**. This ensures the server remains usable even when scope detection fails. |
| 68 | + |
| 69 | +``` |
| 70 | +WARN: failed to fetch token scopes, continuing without scope filtering |
| 71 | +``` |
| 72 | + |
| 73 | +## Fine-Grained Personal Access Tokens |
| 74 | + |
| 75 | +Fine-grained PATs use a different permission model and don't return OAuth scopes in the `X-OAuth-Scopes` header. When using fine-grained PATs, scope filtering will be skipped and all tools will be available. The GitHub API will still enforce permissions at the API level. |
| 76 | + |
| 77 | +## Troubleshooting |
| 78 | + |
| 79 | +| Problem | Cause | Solution | |
| 80 | +|---------|-------|----------| |
| 81 | +| Missing expected tools | Token lacks required scope | Add the scope to your PAT | |
| 82 | +| All tools visible despite limited PAT | Scope detection failed | Check logs for warnings about scope fetching | |
| 83 | +| "Insufficient permissions" errors | Tool visible but scope insufficient | This shouldn't happen with scope filtering; report as bug | |
| 84 | + |
| 85 | +## Related Documentation |
| 86 | + |
| 87 | +- [Server Configuration Guide](./server-configuration.md) |
| 88 | +- [GitHub PAT Documentation](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens) |
| 89 | +- [OAuth Scopes Reference](https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/scopes-for-oauth-apps) |
0 commit comments