Skip to content

Redirect legacy OAuth routes on hosted MCP origins to the Go auth server - #263

Draft
Jayko001 wants to merge 1 commit into
mainfrom
hypeship/redirect-legacy-oauth-routes
Draft

Jayko001 wants to merge 1 commit into
mainfrom
hypeship/redirect-legacy-oauth-routes

Conversation

@Jayko001

Copy link
Copy Markdown

Summary

MCP clients that cached mcp.onkernel.com's own OAuth endpoints (from its /.well-known/oauth-authorization-server or saved /register, /authorize, /token URLs) still go through the TypeScript OAuth routes. The Kernel API does not recognize the tokens those routes issue: GET /auth/context finds no org record for the JWT, so every MCP request fails with 401 Organization context not found. This happens even right after a successful authorization or refresh.

Production request logs show the pattern across several clients. The client gets a 401 on /mcp, refreshes at mcp.onkernel.com/token (200, outcome: success), and gets 401 again with the new token. Clients registered against auth.onkernel.com are unaffected.

This PR sends those clients to the hosted Go authorization server instead of keeping the TypeScript path alive:

  • On mcp.onkernel.com and mcp.dev.onkernel.com, /authorize, /register, /token and /.well-known/oauth-authorization-server now return a 308 to the same path and query on auth.onkernel.com / auth.dev.onkernel.com. 308 preserves the method and body for POST /token and POST /register.
  • OPTIONS preflights still reach the existing route handlers, so browser clients get CORS headers before following the redirect.
  • Local, preview and any other host keep serving OAuth from this app, using the same host mapping as oauthResourceMetadata. hostedAuthorizationServer is factored out of it.
  • /mcp and /.well-known/oauth-protected-resource/mcp are unchanged; they already point at the hosted server.

Behavior for existing credentials

Credentials issued by the TypeScript routes are intentionally not migrated:

  • Client IDs registered through the TypeScript /register exist only in Clerk, not in the Go server's client registry, so the Go server rejects them.
  • Refresh tokens issued here have no context the Go server can find, so the Go server answers invalid_grant / re-authorize.

Affected clients need to reconnect once. Re-registration now lands on the Go server. Clients whose HTTP stack does not follow redirects on POST /token see a failed refresh and prompt the user to reconnect. Clients that pinned https://mcp.onkernel.com as the issuer and validate RFC 9207 iss strictly may also need a reconnect.

Follow-up, not in this PR: remove the now-unreachable TypeScript OAuth handlers and the Redis proxy path they depend on.

Testing

  • bun test: 1140 pass, 0 fail. New cases in src/proxy.test.ts cover both hosted origins, the Host header behind Next, OPTIONS passthrough, non-hosted origins (localhost, preview, look-alike host), and /mcp plus resource metadata staying put.
  • bunx tsc --noEmit is clean.
  • bun run format:check flags only AGENTS.md, which also fails on main.
  • Not exercised against a deployed preview; the redirect only triggers on the production and dev hostnames.

🤖 Generated with Claude Code

Clients that cached mcp.onkernel.com's own OAuth endpoints still register,
authorize and exchange tokens against the TypeScript routes. The Kernel API
does not recognize the tokens those routes issue, so every MCP request with
them fails with 401 "Organization context not found".

On mcp.onkernel.com and mcp.dev.onkernel.com, 308 /authorize, /register,
/token and /.well-known/oauth-authorization-server to the matching hosted
authorization server. Credentials issued by the TypeScript routes are not
migrated; the hosted server rejects them and clients register again. Local,
preview and other hosts keep serving OAuth from this app.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 30, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
mcp Ready Ready Preview Oct 30, 2026 9:35pm UTC

This branch was successfully deployed

1 active deployment
Preview — af5877fc Deployed Oct 30, 2026 by vercel[bot]
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