Skip to content

Add MCP OAuth 2.1 compliance — browser flow replaces copy-paste URLs#8

Merged
rianvdm merged 19 commits intomainfrom
feature/oauth-flow
Mar 16, 2026
Merged

Add MCP OAuth 2.1 compliance — browser flow replaces copy-paste URLs#8
rianvdm merged 19 commits intomainfrom
feature/oauth-flow

Conversation

@rianvdm
Copy link
Copy Markdown
Owner

@rianvdm rianvdm commented Mar 16, 2026

Summary

  • Replaces the manual copy-paste /login?session_id=... flow with full MCP OAuth 2.1 compliance via @cloudflare/workers-oauth-provider — all MCP clients (Claude Code, Claude Desktop, opencode) now open a browser automatically for first-time auth
  • Adds src/auth/oauth-handler.ts to bridge Discogs OAuth 1.0a with MCP OAuth 2.1 (/authorize, /discogs-callback, /login, /callback, /.well-known/oauth-protected-resource)
  • Refactors src/mcp/server.ts into a createMcpServer() factory returning { server, setContext } so both OAuth and session paths inject auth context consistently
  • Removes JWT session tokens; replaces with direct KV storage (7-day sessions) + OAuth bearer tokens
  • Security fix: removes OAuth signing key from console logs

Rollback

Change main = "src/index-oauth.ts" back to main = "src/index.ts" in wrangler.toml and redeploy. src/index.ts is intentionally kept until production is verified stable.

Test Plan

  • 103 automated tests passing (unit + integration + round-trip)
  • Verified live on production with opencode MCP auth
  • Monitor for a few days, then delete src/index.ts when confident

🤖 Generated with Claude Code

rianvdm and others added 19 commits March 15, 2026 16:49
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… paths

Replace createServer(env, request, sessionId) with createMcpServer(env, baseUrl)
returning { server, setContext, getContext }. Session extraction is moved to
src/index.ts so the MCP server is context-agnostic and both OAuth and legacy
session paths can inject auth via setContext before the MCP handler runs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ation

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Update wrangler.toml main field to src/index-oauth.ts
- Remove JWT_SECRET from secrets comments
- Delete src/auth/jwt.ts which is replaced by OAuth session management
- Update tsconfig.json to exclude old index.ts from compilation
- Update integration test to use index-oauth and mock OAuth sessions

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Update MockMCPClient to use ?session_id query param (KV session path)
instead of Cookie header, which is not supported by index-oauth.ts.
Authenticate before the initialize handshake test since the OAuth
provider now intercepts all /mcp requests without a bearer token.
Update unauthenticated test expectation to match the OAuth provider's
401 invalid_token response instead of a JSON-RPC error.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The jwt.ts file was deleted but server.ts still imported SessionPayload from it.
Moved the SessionPayload interface definition inline to maintain backward-compatible
tool access patterns for user credentials.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@rianvdm rianvdm merged commit 9fdbb97 into main Mar 16, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant