feat: add OAuth authentication support for HTTP MCP servers#18
Closed
bvolpato-dd wants to merge 2 commits intophilschmid:mainfrom
Closed
feat: add OAuth authentication support for HTTP MCP servers#18bvolpato-dd wants to merge 2 commits intophilschmid:mainfrom
bvolpato-dd wants to merge 2 commits intophilschmid:mainfrom
Conversation
Owner
|
Thank you for the PR. Do you have an MCP server i could use to test? Especially how this work with an LLM using the cli |
Add support for OAuth 2.0 authentication with PKCE for HTTP-based MCP
servers that require authorization.
Features:
- OAuth 2.0 Authorization Code flow with PKCE (RFC 7636)
- Dynamic client registration support
- Persistent token storage in ~/.config/mcp/oauth_tokens.json
- Automatic token refresh using refresh tokens
- Local callback server for OAuth redirects (port 80 by default)
- Browser-based authorization flow
Usage:
Add "oauth": true to HTTP server config:
```json
{
"mcpServers": {
"my-server": {
"url": "https://example.com/mcp",
"oauth": true
}
}
}
```
On first connection, the browser opens for authorization. Tokens are
cached for subsequent connections.
New files:
- src/auth/token-storage.ts - Persistent OAuth token storage
- src/auth/callback-server.ts - Local HTTP server for OAuth callbacks
- src/auth/oauth-provider.ts - OAuthClientProvider implementation
- src/auth/index.ts - Re-exports
Modified files:
- src/config.ts - Added OAuthConfig type and oauth field
- src/client.ts - Added OAuth support for HTTP transports
- src/index.ts - Updated help text with OAuth documentation
dbce5f7 to
55c0670
Compare
Author
https://github.com/bvolpato/mcp-server-oauth-toy Deployed to https://mcp-server-oauth-toy.brunovolpato.com/mcp So just add {
"mcpServers": {
"oauth-toy": {
"url": "https://mcp-server-oauth-toy.brunovolpato.com/mcp",
"oauth": true
}
}
}And give that a try mcp-cli oauth-toy/whoami '{}' |
- Make redirectUrl getter use actual port from callback server - Update clientMetadata to dynamically resolve redirect_uris - Fixes OAuth flow when port 80 is unavailable (common on macOS/Linux)
7 tasks
|
Heya, I happened to vibe-code SSO support for my own needs a few days ago as well, I've tested this branch against my implementation and this PR didn't work with Notion, Linear or Datadog for me when running I opened up a PR with my changes here #22 |
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR adds OAuth 2.0 authentication support for HTTP-based MCP servers that require authorization.
~/.config/mcp/oauth_tokens.jsonfor reuse across sessionsUsage
Add
"oauth": trueto any HTTP server configuration:{ "mcpServers": { "my-server": { "url": "https://example.com/mcp", "oauth": true } } }On first connection, the browser opens for authorization. Tokens are cached for subsequent connections.
New Files
src/auth/token-storage.ts- Persistent OAuth token storagesrc/auth/callback-server.ts- Local HTTP server for OAuth callbackssrc/auth/oauth-provider.ts- OAuthClientProvider implementation for the MCP SDKsrc/auth/index.ts- Re-exportsModified Files
src/config.ts- AddedOAuthConfigtype andoauthfield toHttpServerConfigsrc/client.ts- Added OAuth support for HTTP transports with proper flow handlingsrc/index.ts- Updated help text with OAuth documentationTest plan
bun run lint)bun run typecheck)bun test)