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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user