Fix Claude Desktop MCP handshake on /mcp.

GET holds a short SSE stream, auth failures return JSON-RPC 401, and OAuth discovery advertises bearer-only.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Towsty
2026-11-02 22:00:29 -06:00
co-authored by Cursor
parent 96776ed493
commit 1834ac4af9
6 changed files with 105 additions and 30 deletions
+6 -3
View File
@@ -13,21 +13,24 @@ export default defineEventHandler((event) => {
path.startsWith('/api/monitor') ||
path.startsWith('/_nuxt') ||
path.startsWith('/favicon') ||
path === '/login'
path === '/login' ||
path === '/.well-known/oauth-protected-resource' ||
path.startsWith('/.well-known/oauth-protected-resource/')
) {
return
}
const method = String(event.method || getMethod(event) || 'GET').toUpperCase()
// /mcp auth + 401 JSON-RPC bodies are handled in the route — do not 401 here.
if (path === '/mcp') {
applyMcpCors(event)
if (method === 'OPTIONS') return
return
}
if (aigenApiPathAllowed(path, method) && aigenBearerAuthorized(event)) {
return
}
const user = getSessionUser(event)
if (user) return
if (path === '/mcp' || path.startsWith('/api/')) {
if (path.startsWith('/api/')) {
throw createError({ statusCode: 401, statusMessage: 'Authentication required' })
}
return sendRedirect(event, path === '/studio-2' ? '/login?next=/studio-2' : '/login', 302)