Skip to content

Commit e01606c

Browse files
fix(mcp): rewrite RFC 9728 well-known paths for OAuth discovery
Claude Desktop looks for OAuth metadata at RFC-standard paths: /.well-known/oauth-protected-resource/api/mcp /.well-known/oauth-authorization-server/api/mcp But our catch-all proxy serves them at /api/mcp/.well-known/*. Add rewrite rules in proxy.ts to map the RFC paths to our proxy, so Claude Desktop can discover the OAuth endpoints correctly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a5c3a4e commit e01606c

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

proxy.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff 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)

0 commit comments

Comments
 (0)