Skip to content

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

Merged
waleedlatif1 merged 2 commits into
stagingfrom
fix/mcp-orchestration-codes
May 16, 2026
Merged

fix(mcp): map validation and conflict orchestration errors to 400/409#4628
waleedlatif1 merged 2 commits into
stagingfrom
fix/mcp-orchestration-codes

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

Summary

  • mcpOrchestrationStatus was missing validation and conflict error codes, defaulting both to 500
  • validation now maps to 400, conflict to 409 — matching how workflow MCP server routes handle these codes

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link
Copy Markdown

vercel Bot commented May 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped May 16, 2026 1:44am

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented May 16, 2026

PR Summary

Medium Risk
Changes HTTP status codes returned by MCP workflow-server APIs for certain orchestration failures, which could affect client error handling despite being a bug fix.

Overview
Fixes incorrect HTTP status mapping for MCP orchestration errors. mcpOrchestrationStatus now explicitly maps validation to 400 and conflict to 409 (instead of falling back to 500).

Workflow MCP server routes (workflow-servers create/update/delete and tool creation) are updated to use mcpOrchestrationStatus consistently rather than ad-hoc status selection, aligning error responses across endpoints.

Reviewed by Cursor Bugbot for commit c81b3ea. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 16, 2026

Greptile Summary

This PR fixes incorrect HTTP status codes for MCP orchestration errors by adding validation → 400 and conflict → 409 mappings to mcpOrchestrationStatus, then migrating three workflow-server routes off their inline ternaries to use the shared utility.

  • utils.ts: adds validation and conflict branches to mcpOrchestrationStatus, making the function the single source of truth for all orchestration error codes.
  • Three workflow-server routes (workflow-servers/route.ts, [id]/route.ts, [id]/tools/route.ts): inline ternary status logic replaced with mcpOrchestrationStatus.
  • [id]/tools/[toolId]/route.ts was not included in the migration and still uses inline ternaries in its PATCH and DELETE handlers.

Confidence Score: 5/5

Safe to merge — the three migrated routes have equivalent or improved status-code behaviour and no existing error path regresses.

The change is a narrow, well-scoped fix: two new branches in a pure mapping function and three call-site migrations. All currently emitted error codes map to the same HTTP statuses as before. The only unmigrated file already produces correct statuses with its own inline logic.

apps/sim/app/api/mcp/workflow-servers/[id]/tools/[toolId]/route.ts — PATCH and DELETE handlers still use inline ternaries instead of mcpOrchestrationStatus.

Important Files Changed

Filename Overview
apps/sim/lib/mcp/utils.ts Adds validation → 400 and conflict → 409 branches to mcpOrchestrationStatus and reorders existing entries.
apps/sim/app/api/mcp/workflow-servers/route.ts POST handler migrated to mcpOrchestrationStatus; behaviour is equivalent for all currently emitted codes.
apps/sim/app/api/mcp/workflow-servers/[id]/route.ts PATCH and DELETE handlers migrated to mcpOrchestrationStatus; inline ternaries removed.
apps/sim/app/api/mcp/workflow-servers/[id]/tools/route.ts POST handler migrated to mcpOrchestrationStatus; two-step inline ternary replaced with the unified utility.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Workflow-server route error] --> B[mcpOrchestrationStatus]
    B --> C{errorCode?}
    C -->|validation| D[400 Bad Request]
    C -->|forbidden| E[403 Forbidden]
    C -->|not_found| F[404 Not Found]
    C -->|conflict| G[409 Conflict]
    C -->|bad_gateway| H[502 Bad Gateway]
    C -->|internal / undefined| I[500 Internal Server Error]
Loading

Reviews (2): Last reviewed commit: "fix(mcp): migrate workflow-server routes..." | Re-trigger Greptile

Comment thread apps/sim/lib/mcp/utils.ts
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit c81b3ea. Configure here.

@waleedlatif1 waleedlatif1 merged commit 674dd8d into staging May 16, 2026
10 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/mcp-orchestration-codes branch May 16, 2026 01:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant