Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions apps/sim/app/api/mcp/workflow-servers/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions apps/sim/app/api/mcp/workflow-servers/[id]/tools/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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)
)
}

Expand Down
8 changes: 6 additions & 2 deletions apps/sim/app/api/mcp/workflow-servers/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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)
)
}

Expand Down
4 changes: 3 additions & 1 deletion apps/sim/lib/mcp/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Comment thread
waleedlatif1 marked this conversation as resolved.

Expand Down
Loading