File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -80,6 +80,22 @@ export default async function proxy(request: NextRequest) {
8080 return NextResponse . next ( )
8181 }
8282
83+ // --- OAuth well-known metadata (RFC 9728 path-aware format) ---
84+ // Claude Desktop looks for:
85+ // /.well-known/oauth-protected-resource/api/mcp
86+ // /.well-known/oauth-authorization-server/api/mcp
87+ // Rewrite these to our catch-all proxy at /api/mcp/.well-known/*
88+ if ( pathname . startsWith ( '/.well-known/oauth-protected-resource/api/mcp' ) ||
89+ pathname . startsWith ( '/.well-known/oauth-authorization-server/api/mcp' ) ) {
90+ // Extract which well-known type: oauth-protected-resource or oauth-authorization-server
91+ const wellKnownType = pathname . startsWith ( '/.well-known/oauth-protected-resource' )
92+ ? 'oauth-protected-resource'
93+ : 'oauth-authorization-server'
94+ const rewriteUrl = request . nextUrl . clone ( )
95+ rewriteUrl . pathname = `/api/mcp/.well-known/${ wellKnownType } `
96+ return NextResponse . rewrite ( rewriteUrl )
97+ }
98+
8399 // --- Tenant Resolution (runs for ALL routes including /api) ---
84100 const host = request . headers . get ( 'host' ) || ''
85101 const tenantSlug = getTenantSlugFromHost ( host )
You can’t perform that action at this time.
0 commit comments