-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Add OAuth scopes customization, GitHub Apps support, and improve authentication documentation #1650
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
Add OAuth scopes customization, GitHub Apps support, and improve authentication documentation #1650
Conversation
- Fix OAuth client ID comment to clarify it's production-ready - Replace custom joinScopes function with strings.Join - Fix URL parsing fallback to avoid double-https:// prefix - Fix typo in auth success message - Update server instructions to remove auth_verify references - Add comprehensive OAuth authentication documentation - Update README with authentication method comparison and links to OAuth docs Co-authored-by: SamMorrowDrums <4811358+SamMorrowDrums@users.noreply.github.com>
- Add --oauth-scopes CLI flag to allow users to limit requested scopes - Add GITHUB_OAUTH_SCOPES environment variable support - Update OAuth authentication documentation with scopes customization guide - Add examples for minimal, read-only, and custom scope configurations - Update OAuth client ID comment to indicate it's a testing app (TODO for production) Co-authored-by: SamMorrowDrums <4811358+SamMorrowDrums@users.noreply.github.com>
|
@copilot So we should also mention this will work with Github apps, not just oauth apps (but they have different permissions so ships and access are controlled by the app itself in this case. |
- Add new "Using GitHub Apps" section explaining device flow with GitHub Apps - Document key differences between OAuth Apps and GitHub Apps - Explain that scopes are controlled by app configuration, not --oauth-scopes flag - Include instructions for creating and using GitHub Apps - Update table of contents and overview to mention GitHub Apps support - No code changes needed - existing implementation already supports both OAuth Apps and GitHub Apps Co-authored-by: SamMorrowDrums <4811358+SamMorrowDrums@users.noreply.github.com>
Added comprehensive GitHub Apps documentation in commit 75c76ea. The existing code already supports both OAuth Apps and GitHub Apps without any modifications - the device flow implementation uses the same endpoints and accepts both client ID formats (Ov for OAuth Apps, Iv for GitHub Apps). Key points documented:
|
|
@copilot also run editors knife along docs, and review code for clarity, elegance, duplication, redundancy, naming, separation of concerns and even question whether an entire new server constructir is paying off versus configuration approach for the one. Ideally we'd apply tool filters only once so we can ensure the oauth ones never get stale. |
- Add comprehensive doc comments explaining NewMCPServer initialization steps - Document the two-phase initialization pattern in NewUnauthenticatedMCPServer - Explain architectural tradeoffs and acknowledge code duplication - Add notes about future refactoring opportunities for common setup logic - Clarify manual tool filtering approach and suggest toolset-based alternative - Document MCPServerConfig as shared configuration struct - No functional changes - documentation and comments only Co-authored-by: SamMorrowDrums <4811358+SamMorrowDrums@users.noreply.github.com>
Completed in commit f39e730. After reviewing the code for clarity, elegance, duplication, and separation of concerns: Documentation polished: The OAuth authentication guide is comprehensive and clear (no editorial issues found). Code review findings:
Improvements made:
Decision: Maintained current architecture rather than major refactor to avoid risk. The code is now well-documented with clear notes on future improvements. A future PR can extract common logic into helper functions while preserving the two-phase pattern. |
|
@copilot You didn’t need to add arch documentation, and it doesn’t have to be huge re-arch if you just define the inventory before forking logic, and just don’t call register all in the same place. |
- Move inventory building outside OnAuthenticated callback in NewUnauthenticatedMCPServer - Build inventory once before creating auth tools, eliminating duplication - Reuse the same inventory instance in OnAuthenticated via closure - Tool filters are now applied only once, preventing stale auth tools - Reduces code duplication without changing architecture - All tests pass, 0 lint issues Co-authored-by: SamMorrowDrums <4811358+SamMorrowDrums@users.noreply.github.com>
Done in commit 8a48cad. Removed the architectural documentation and implemented the simpler refactoring you suggested:
Much cleaner approach - no architectural documentation needed, just moved the logic before the fork and didn't call |
|
@copilot > Updated server instructions to accurately describe single auth_login call. I don’t. We need server instructions. Tool schema is enough and auth tool only conditionally present |
- Remove custom Instructions text from unauthenticated server - Tool schema is sufficient - auth tool describes itself - Auth tool is conditionally present only when needed - Simplifies server initialization Co-authored-by: SamMorrowDrums <4811358+SamMorrowDrums@users.noreply.github.com>
Removed in commit f3b0d1b. You're right - the tool schema is sufficient to explain what to do. The auth tool describes itself and is only present when needed. Removed the custom Instructions text from the unauthenticated server initialization. |
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 enhances the GitHub MCP Server's OAuth device flow authentication by adding OAuth scope customization capabilities and comprehensive documentation. It enables users to limit OAuth permissions for security and compliance while providing detailed guidance for different GitHub environments including GitHub Apps support.
Key changes:
- Added
--oauth-scopesCLI flag andGITHUB_OAUTH_SCOPESenvironment variable for OAuth scope customization - Created comprehensive OAuth authentication documentation covering OAuth Apps, GitHub Apps, GHES, and GHEC
- Refactored
NewUnauthenticatedMCPServerto build tool inventory once, eliminating duplication and ensuring tool filters are applied correctly - Fixed minor issues in auth messaging, URL parsing, and code style
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
pkg/github/auth_tools.go |
Fixed typo and improved clarity in authentication success message |
pkg/github/auth.go |
Fixed URL parsing to prevent double-https prefix in GHES fallback; simplified joinScopes function using strings.Join; updated OAuth client ID comment |
internal/ghmcp/server.go |
Added OAuthScopes field to configs; refactored NewUnauthenticatedMCPServer to build inventory once before authentication, eliminating ~20 lines of duplication; added comprehensive documentation comments |
cmd/github-mcp-server/main.go |
Added OAuth scopes flag parsing and binding to viper configuration |
docs/oauth-authentication.md |
Created comprehensive 570-line OAuth authentication guide covering device flow, CLI flags, environment variables, custom OAuth Apps, GitHub Apps, GHES/GHEC setup, and troubleshooting |
README.md |
Added authentication methods comparison section with OAuth device flow as recommended option for interactive use; updated prerequisites and added links to OAuth documentation |
2b89711
into
sammorrowdrums/oauth-device-flow-auth
Summary
Adds
--oauth-scopesflag andGITHUB_OAUTH_SCOPESenvironment variable to allow users to limit OAuth permissions. Creates comprehensive OAuth authentication documentation covering all GitHub environments including OAuth Apps and GitHub Apps. Addresses PR #1649 review feedback. Refactors code to reduce duplication and ensure tool filters are applied once.Why
Users need control over OAuth scope requests for security and compliance. Documentation was missing for OAuth device flow setup across different GitHub environments (GHES, GHEC) and GitHub Apps. Review feedback required code improvements and documentation updates. Code review identified duplication in inventory building that needed refactoring.
What changed
--oauth-scopesCLI flag andGITHUB_OAUTH_SCOPESenv var for scope customizationdocs/oauth-authentication.mdwith OAuth setup, CLI flags, environment variables, GHES/GHEC configuration, troubleshootingjoinScopesto usestrings.Join(more idiomatic)NewUnauthenticatedMCPServerto build inventory once before authentication forkMCP impact
auth_logintool behavior unchanged, but requested OAuth scopes now customizable via configuration rather than hardcoded. Works with both OAuth Apps and GitHub Apps. Server no longer provides custom instructions for auth mode - tool schema is self-documenting.Prompts tested (tool changes only)
--oauth-scopes repo,read:org,gist--oauth-client-idand--oauth-scopestogetherSecurity / limits
Users can now limit OAuth scopes to minimum required permissions. Default scopes remain unchanged for backward compatibility. Documentation includes security considerations for scope selection and examples for minimal, read-only, and custom configurations. GitHub Apps use fine-grained permissions controlled by app configuration rather than scopes.
Lint & tests
./script/lint./script/testDocs
Created
docs/oauth-authentication.md(500+ lines) covering OAuth device flow, CLI flags, environment variables, GHES/GHEC setup, scope customization, and GitHub Apps support with examples. Updated README.md with authentication options and links to OAuth guide.Usage examples:
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.