feat: add OAuth discovery endpoints for ChatGPT MCP compatibility#91
feat: add OAuth discovery endpoints for ChatGPT MCP compatibility#91
Conversation
Add /.well-known/oauth-protected-resource (root-level) and /.well-known/oauth-authorization-server to satisfy RFC 9728 and RFC 8414 discovery requirements expected by ChatGPT's MCP connector. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Risk assessment for this PR: Medium.
Rationale based on the actual diff:
- Adds two new public
/.well-known/*OAuth discovery endpoints in production code. - Changes externally consumed auth metadata (
issuer,authorization_endpoint,token_endpoint, andauthorization_servers) that OAuth clients depend on. - Touches auth-adjacent behavior and interoperability surface area, where regressions can break login/connect flows.
Decision:
- Code review required before merge.
- Not self-approving due to Medium risk and required review.
- Requested reviewer:
@masnwilliams(primary recent contributor/expert in related OAuth route codepaths).
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| }, | ||
| }); | ||
|
|
||
| export { handler as GET }; |
There was a problem hiding this comment.
Root protected-resource route duplicates existing mcp route
Low Severity
The new oauth-protected-resource/route.ts is a byte-for-byte duplicate of the existing oauth-protected-resource/mcp/route.ts. Both files share the same handler logic, CORS headers, and metadata construction. Extracting the shared handler into a common module would avoid the risk of the two copies drifting apart when future changes are made to only one of them.
|
@ehfeng were you able to test this out to see if it works with ChatGPT? happy to help test — we've tried something similar before and it ended up breaking other MCP clients like Cursor for some reason, so want to make sure we validate across clients before merging. |
masnwilliams
left a comment
There was a problem hiding this comment.
some notes from reviewing:
-
cors duplication — the same 3-header cors block is copy-pasted ~6 times across the well-known routes (OPTIONS handler, GET response, times 3 files). might be worth extracting a shared
corsHeadersconstant to keep them in sync. -
issuer derived from request host (line 28 in oauth-authorization-server) —
issuerwill reflect whatever hostname the request arrives at (e.g.localhost:3000in dev). works fine in prod assuming no CDN/proxy rewrites the host, but worth confirming there are no surprises there. -
metadata is fully hardcoded — unlike the protected-resource route which calls
protectedResourceHandlerClerkand overrides fields, the authorization-server route builds the entire metadata object from scratch. if clerk's capabilities change (new grant types, etc.), this won't pick that up. probably fine since this server is the auth server facade, but a brief code comment noting that would help future readers. -
mixed routing pattern —
registration_endpointpoints directly to clerk (clerkBaseUrl/oauth/register) while auth/token are proxied through this server. consistent with how the protected-resource route does it, just noting the pattern.
nothing blocking — overall looks good for unblocking chatgpt compatibility.




Summary
/.well-known/oauth-protected-resourceroot-level route — ChatGPT strips the/mcppath suffix and checks the base URL, which was returning 404/.well-known/oauth-authorization-serverroute (RFC 8414) — the protected resource metadata declaresauthorization_servers: ["https://mcp.onkernel.com"], so OAuth clients follow that to discover AS capabilities; the missing endpoint caused ChatGPT to report "does not implement OAuth"Context
ChatGPT's MCP connector failed with: "MCP server https://mcp.onkernel.com/ does not implement OAuth"
The existing
/.well-known/oauth-protected-resource/mcproute was correct per RFC 9728 path construction, but ChatGPT also checks the root/.well-known/oauth-protected-resourceand then followsauthorization_serversto discover/.well-known/oauth-authorization-server— both of which were 404ing.Test plan
https://mcp.onkernel.com/.well-known/oauth-protected-resourcereturns JSON (not 404)https://mcp.onkernel.com/.well-known/oauth-authorization-serverreturns JSON withissuer,authorization_endpoint,token_endpoint, etc.https://mcp.onkernel.com/mcpfrom ChatGPT Apps / MCP connector and confirm OAuth flow completes🤖 Generated with Claude Code
Note
Medium Risk
Adds new public
/.well-known/*OAuth discovery endpoints (with permissive CORS) that affect how clients locate auth/token servers; misconfiguration could break OAuth interoperability but does not change core token verification logic.Overview
Adds RFC-style OAuth discovery metadata endpoints to improve MCP client compatibility.
Introduces
/.well-known/oauth-authorization-serverto publish authorization server capabilities (issuer, auth/token endpoints, JWKS, supported grants, and auth methods) derived from the current host plusNEXT_PUBLIC_CLERK_DOMAIN. Also adds a root/.well-known/oauth-protected-resourceendpoint (in addition to the existing/mcpvariant) that proxies Clerk-provided metadata and rewrites it to point clients at this server’s/authorizeand/token, returning CORS-enabled JSON responses for bothGETandOPTIONS.Written by Cursor Bugbot for commit 40a0a2e. This will update automatically on new commits. Configure here.