Stop advertising OAuth so Claude MCP discovery can succeed.

Drop empty authorization_servers well-known ads, 404 discovery probes as JSON, and keep bearer-only /mcp auth.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Towsty
2026-11-02 22:25:17 -06:00
co-authored by Cursor
parent 8c9b4d5f7d
commit 7fd040ad62
5 changed files with 23 additions and 24 deletions
+3 -2
View File
@@ -14,8 +14,9 @@ export default defineEventHandler((event) => {
path.startsWith('/_nuxt') || path.startsWith('/_nuxt') ||
path.startsWith('/favicon') || path.startsWith('/favicon') ||
path === '/login' || path === '/login' ||
path === '/.well-known/oauth-protected-resource' || // Claude MCP discovery — never 302 to /login (JSON 404 handlers serve these).
path.startsWith('/.well-known/oauth-protected-resource/') path === '/.well-known/oauth-authorization-server' ||
path === '/.well-known/openid-configuration'
) { ) {
return return
} }
@@ -1,7 +1,7 @@
import { mcpOauthProtectedResource } from '~/server/utils/aigenMcp' /** Claude discovery probe — no OAuth; never redirect to /login. */
export default defineEventHandler((event) => { export default defineEventHandler((event) => {
setResponseStatus(event, 404)
setResponseHeader(event, 'Content-Type', 'application/json') setResponseHeader(event, 'Content-Type', 'application/json')
setResponseHeader(event, 'Cache-Control', 'no-store') setResponseHeader(event, 'Cache-Control', 'no-store')
return mcpOauthProtectedResource() return { error: 'not found' }
}) })
@@ -1,7 +1,7 @@
import { mcpOauthProtectedResource } from '~/server/utils/aigenMcp' /** Claude discovery probe — no OAuth; never redirect to /login. */
export default defineEventHandler((event) => { export default defineEventHandler((event) => {
setResponseStatus(event, 404)
setResponseHeader(event, 'Content-Type', 'application/json') setResponseHeader(event, 'Content-Type', 'application/json')
setResponseHeader(event, 'Cache-Control', 'no-store') setResponseHeader(event, 'Cache-Control', 'no-store')
return mcpOauthProtectedResource() return { error: 'not found' }
}) })
+2 -9
View File
@@ -8,7 +8,6 @@ import { readAigenJob } from '~/server/utils/aigenJob'
export const MCP_PROTOCOL_VERSION = '2025-03-26' export const MCP_PROTOCOL_VERSION = '2025-03-26'
export const MCP_SERVER_INFO = { name: 'aigen', version: '1.0.0' } export const MCP_SERVER_INFO = { name: 'aigen', version: '1.0.0' }
export const MCP_SUPPORTED_PROTOCOL_VERSIONS = ['2025-03-26', '2025-06-18', '2025-11-25'] as const export const MCP_SUPPORTED_PROTOCOL_VERSIONS = ['2025-03-26', '2025-06-18', '2025-11-25'] as const
export const MCP_RESOURCE = 'https://aigen.carrgarage.com/mcp'
const ENGINE_ENUM = [...STUDIO2_IMAGE_ENGINES] const ENGINE_ENUM = [...STUDIO2_IMAGE_ENGINES]
@@ -68,13 +67,6 @@ export function applyMcpCors(event: H3Event) {
if (origin) setResponseHeader(event, 'Vary', 'Origin') if (origin) setResponseHeader(event, 'Vary', 'Origin')
} }
export function mcpOauthProtectedResource() {
return {
resource: MCP_RESOURCE,
authorization_servers: [] as string[]
}
}
export function resolveMcpProtocolVersion(requested: unknown) { export function resolveMcpProtocolVersion(requested: unknown) {
const version = String(requested || '').trim() const version = String(requested || '').trim()
if ((MCP_SUPPORTED_PROTOCOL_VERSIONS as readonly string[]).includes(version)) return version if ((MCP_SUPPORTED_PROTOCOL_VERSIONS as readonly string[]).includes(version)) return version
@@ -97,11 +89,12 @@ export function jsonRpcResult(id: unknown, result: unknown) {
} }
} }
/** 401 with JSON-RPC body — never a Nuxt error page. */ /** 401 with JSON-RPC body — never a Nuxt error page, never WWW-Authenticate (no OAuth). */
export function mcpUnauthorized(event: H3Event, id: unknown = null) { export function mcpUnauthorized(event: H3Event, id: unknown = null) {
applyMcpCors(event) applyMcpCors(event)
setResponseStatus(event, 401) setResponseStatus(event, 401)
setResponseHeader(event, 'Content-Type', 'application/json') setResponseHeader(event, 'Content-Type', 'application/json')
removeResponseHeader(event, 'WWW-Authenticate')
return jsonRpcError(id, -32001, 'Unauthorized') return jsonRpcError(id, -32001, 'Unauthorized')
} }
+12 -7
View File
@@ -1,6 +1,6 @@
import test from 'node:test' import test from 'node:test'
import assert from 'node:assert/strict' import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs' import { existsSync, readFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url' import { fileURLToPath } from 'node:url'
import { dirname, join } from 'node:path' import { dirname, join } from 'node:path'
import { import {
@@ -75,7 +75,9 @@ test('aigen routes exist, stay on the studio-2 enqueue path, and 404 on xAIGen',
assert.match(job, /stillAbsoluteUrl/) assert.match(job, /stillAbsoluteUrl/)
assert.match(middleware, /aigenBearerAuthorized/) assert.match(middleware, /aigenBearerAuthorized/)
assert.match(middleware, /aigenApiPathAllowed/) assert.match(middleware, /aigenApiPathAllowed/)
assert.match(middleware, /\/\.well-known\/oauth-protected-resource/) assert.match(middleware, /\/\.well-known\/oauth-authorization-server/)
assert.match(middleware, /\/\.well-known\/openid-configuration/)
assert.doesNotMatch(middleware, /oauth-protected-resource/)
assert.match(authPaths, /path === '\/mcp'/) assert.match(authPaths, /path === '\/mcp'/)
assert.match(mcp, /mcpBearerOk/) assert.match(mcp, /mcpBearerOk/)
assert.match(mcp, /text\/event-stream/) assert.match(mcp, /text\/event-stream/)
@@ -88,15 +90,18 @@ test('aigen routes exist, stay on the studio-2 enqueue path, and 404 on xAIGen',
assert.match(mcpUtil, /aigen_job/) assert.match(mcpUtil, /aigen_job/)
assert.match(mcpUtil, /queueAigenGenerate/) assert.match(mcpUtil, /queueAigenGenerate/)
assert.match(mcpUtil, /readAigenJob/) assert.match(mcpUtil, /readAigenJob/)
assert.match(mcpUtil, /authorization_servers/) assert.match(mcpUtil, /removeResponseHeader\(event,\s*'WWW-Authenticate'\)/)
assert.doesNotMatch(mcpUtil, /authorization_servers/)
assert.match(mcpUtil, /2025-06-18/) assert.match(mcpUtil, /2025-06-18/)
assert.match(nuxt, /aigenApiKey:\s*process\.env\.AIGEN_API_KEY/) assert.match(nuxt, /aigenApiKey:\s*process\.env\.AIGEN_API_KEY/)
assert.match(bench, /studio2EngineDefaults/) assert.match(bench, /studio2EngineDefaults/)
const oauthRoot = readFileSync(join(root, 'server/routes/.well-known/oauth-protected-resource.get.ts'), 'utf8') const as = readFileSync(join(root, 'server/routes/.well-known/oauth-authorization-server.get.ts'), 'utf8')
const oauthMcp = readFileSync(join(root, 'server/routes/.well-known/oauth-protected-resource/mcp.get.ts'), 'utf8') const oidc = readFileSync(join(root, 'server/routes/.well-known/openid-configuration.get.ts'), 'utf8')
assert.match(oauthRoot, /mcpOauthProtectedResource/) assert.match(as, /not found/)
assert.match(oauthMcp, /mcpOauthProtectedResource/) assert.match(oidc, /not found/)
assert.equal(existsSync(join(root, 'server/routes/.well-known/oauth-protected-resource.get.ts')), false)
assert.equal(existsSync(join(root, 'server/routes/.well-known/oauth-protected-resource/mcp.get.ts')), false)
}) })
test('defaultLibraryFolderId prefers Inbox then the first folder', () => { test('defaultLibraryFolderId prefers Inbox then the first folder', () => {