Add hosted MCP endpoint at POST /mcp for remote agents.

Bearer-auth JSON-RPC exposes engines, generate, and job tools without duplicating the aigen API path.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Towsty
2026-11-02 21:41:31 -06:00
co-authored by Cursor
parent 08caeb51de
commit 96776ed493
9 changed files with 430 additions and 169 deletions
+6 -1
View File
@@ -1,4 +1,5 @@
import { aigenApiPathAllowed, aigenBearerAuthorized } from '~/server/utils/aigenApiAuth'
import { applyMcpCors } from '~/server/utils/aigenMcp'
export default defineEventHandler((event) => {
if (!authEnabled()) return
@@ -17,12 +18,16 @@ export default defineEventHandler((event) => {
return
}
const method = String(event.method || getMethod(event) || 'GET').toUpperCase()
if (path === '/mcp') {
applyMcpCors(event)
if (method === 'OPTIONS') return
}
if (aigenApiPathAllowed(path, method) && aigenBearerAuthorized(event)) {
return
}
const user = getSessionUser(event)
if (user) return
if (path.startsWith('/api/')) {
if (path === '/mcp' || path.startsWith('/api/')) {
throw createError({ statusCode: 401, statusMessage: 'Authentication required' })
}
return sendRedirect(event, path === '/studio-2' ? '/login?next=/studio-2' : '/login', 302)