fix(mcp): map validation and conflict orchestration errors to 400/409 (#4628)

* fix(mcp): map validation and conflict orchestration errors to 400/409

* fix(mcp): migrate workflow-server routes to mcpOrchestrationStatus
This commit is contained in:
Waleed
2026-05-15 18:49:07 -07:00
committed by GitHub
parent 93f7be4097
commit 674dd8d91f
4 changed files with 22 additions and 11 deletions
@@ -14,7 +14,11 @@ import {
performDeleteWorkflowMcpServer,
performUpdateWorkflowMcpServer,
} from '@/lib/mcp/orchestration'
import { createMcpErrorResponse, createMcpSuccessResponse } from '@/lib/mcp/utils'
import {
createMcpErrorResponse,
createMcpSuccessResponse,
mcpOrchestrationStatus,
} from '@/lib/mcp/utils'
const logger = createLogger('WorkflowMcpServerAPI')
@@ -112,8 +116,7 @@ export const PATCH = withRouteHandler(
isPublic: body.isPublic,
})
if (!result.success || !result.server) {
const status =
result.errorCode === 'not_found' ? 404 : result.errorCode === 'validation' ? 400 : 500
const status = mcpOrchestrationStatus(result.errorCode)
return createMcpErrorResponse(
new Error(result.error || 'Failed to update workflow MCP server'),
result.error || 'Failed to update workflow MCP server',
@@ -160,7 +163,7 @@ export const DELETE = withRouteHandler(
return createMcpErrorResponse(
new Error(result.error || 'Server not found'),
result.error || 'Server not found',
result.errorCode === 'not_found' ? 404 : 500
mcpOrchestrationStatus(result.errorCode)
)
}
const deletedServer = result.server
@@ -11,7 +11,11 @@ import {
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
import { getParsedBody, withMcpAuth } from '@/lib/mcp/middleware'
import { performCreateWorkflowMcpTool } from '@/lib/mcp/orchestration'
import { createMcpErrorResponse, createMcpSuccessResponse } from '@/lib/mcp/utils'
import {
createMcpErrorResponse,
createMcpSuccessResponse,
mcpOrchestrationStatus,
} from '@/lib/mcp/utils'
const logger = createLogger('WorkflowMcpToolsAPI')
@@ -117,12 +121,10 @@ export const POST = withRouteHandler(
parameterSchema: body.parameterSchema,
})
if (!result.success || !result.tool) {
const status =
result.errorCode === 'not_found' ? 404 : result.errorCode === 'conflict' ? 409 : 400
return createMcpErrorResponse(
new Error(result.error || 'Failed to add tool'),
result.error || 'Failed to add tool',
result.errorCode === 'internal' ? 500 : status
mcpOrchestrationStatus(result.errorCode)
)
}
@@ -8,7 +8,11 @@ import { createWorkflowMcpServerBodySchema } from '@/lib/api/contracts/workflow-
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
import { getParsedBody, withMcpAuth } from '@/lib/mcp/middleware'
import { performCreateWorkflowMcpServer } from '@/lib/mcp/orchestration'
import { createMcpErrorResponse, createMcpSuccessResponse } from '@/lib/mcp/utils'
import {
createMcpErrorResponse,
createMcpSuccessResponse,
mcpOrchestrationStatus,
} from '@/lib/mcp/utils'
const logger = createLogger('WorkflowMcpServersAPI')
@@ -121,7 +125,7 @@ export const POST = withRouteHandler(
return createMcpErrorResponse(
new Error(result.error || 'Failed to create workflow MCP server'),
result.error || 'Failed to create workflow MCP server',
result.errorCode === 'validation' ? 400 : 500
mcpOrchestrationStatus(result.errorCode)
)
}
+3 -1
View File
@@ -82,9 +82,11 @@ export function createMcpSuccessResponse<T>(data: T, status = 200): NextResponse
* Maps MCP orchestration error codes to safe HTTP statuses.
*/
export function mcpOrchestrationStatus(errorCode: string | undefined): number {
if (errorCode === 'validation') return 400
if (errorCode === 'forbidden') return 403
if (errorCode === 'bad_gateway') return 502
if (errorCode === 'not_found') return 404
if (errorCode === 'conflict') return 409
if (errorCode === 'bad_gateway') return 502
return 500
}