Skip to content

Commit 70a8646

Browse files
Merge pull request #263 from guillermoscript/feature/mcp
fix(mcp): rewrite RFC 9728 well-known paths for OAuth discovery
2 parents 447d8ad + e01606c commit 70a8646

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)