feat(workflow-as-mcp): wrapping workflows in the same workspace as MCP tools to particular MCP servers
Summary
We wrap the existing API calls as MCP tool endpoints and use them to trigger workflows from MCP servers.
Type of Change
- [x] New feature
Testing
Tested manually with @Sg312
Checklist
- [x] Code follows project style guidelines
- [x] Self-reviewed my changes
- [x] Tests added/updated and passing
- [x] No new warnings introduced
- [x] I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)
The latest updates on your projects. Learn more about Vercel for GitHub.
| Project | Deployment | Review | Updated (UTC) |
|---|---|---|---|
| docs | Preview, Comment | Dec 31, 2025 0:49am |
Greptile Summary
This PR implements a comprehensive MCP (Model Context Protocol) server system that wraps deployed workflows as callable tools. The implementation adds infrastructure for users to create workspace-scoped MCP servers, register deployed workflows as tools, and expose them via standard MCP protocol endpoints for external clients.
Key Changes:
- Added
workflow_mcp_serverandworkflow_mcp_tooldatabase tables with proper foreign keys and cascade deletes - Implemented
/api/mcp/serve/[serverId]endpoint with full JSON-RPC 2.0 MCP protocol support (initialize,tools/list,tools/call) - Created CRUD APIs for managing workflow MCP servers and tools with workspace-level authorization
- Built automatic schema sync system that updates tool parameter schemas when workflows deploy/undeploy
- Added
mcpas a new trigger type across execution logging and rate limiting systems - Integrated workflow MCP tool management into deploy modal UI with parameter description editing
- Tool execution flows through internal workflow execute API with proper authentication and 5-minute timeout
Architecture: The implementation maintains clear separation between external MCP servers (for consuming tools) and workflow MCP servers (for exposing workflows). Tool registration validates that workflows are deployed and have valid start blocks. Schema generation converts workflow input formats to JSON Schema and Zod schemas compatible with MCP clients.
Security:
All workflow MCP server endpoints use withMcpAuth middleware for workspace-level authorization. Tool execution uses checkHybridAuth and only executes deployed workflows. The serve endpoint accepts API keys via headers for external MCP client authentication.
Confidence Score: 4/5
- Safe to merge with one potential timeout concern in workflow execution flow
- The implementation is well-structured with proper authorization, validation, and error handling. Database schema changes are clean with appropriate constraints. The automatic schema sync is non-critical and won't break workflows if it fails. Minor concern: the serve endpoint's internal fetch to workflow execute API could potentially hang despite the 5-minute timeout if the execute endpoint itself has issues, but this is handled gracefully with error responses.
- Pay close attention to
apps/sim/app/api/mcp/serve/[serverId]/route.tsfor the internal API fetch timeout handling
Important Files Changed
| Filename | Overview |
|---|---|
| packages/db/schema.ts | Added two new tables (workflow_mcp_server and workflow_mcp_tool) with proper foreign keys, indexes, and cascade deletes |
| packages/db/migrations/0134_parallel_galactus.sql | Migration creates workflow MCP tables with proper constraints and unique index on server-workflow pairs |
| apps/sim/lib/mcp/workflow-tool-schema.ts | Schema generation converts workflow input format to JSON Schema and Zod schemas for MCP tools |
| apps/sim/lib/mcp/workflow-mcp-sync.ts | Syncs MCP tool schemas when workflows deploy/undeploy, removes tools when start block removed |
| apps/sim/app/api/mcp/serve/[serverId]/route.ts | MCP protocol server endpoint with JSON-RPC handling, workflow execution via internal API call with 5-minute timeout |
| apps/sim/app/api/mcp/workflow-servers/route.ts | CRUD API for workflow MCP servers with proper workspace authorization via withMcpAuth middleware |
| apps/sim/app/api/mcp/workflow-servers/[id]/tools/route.ts | Tool management API validates deployed status, start block presence, and workspace membership before adding tools |
| apps/sim/app/api/workflows/[id]/deploy/route.ts | Integrated MCP tool sync on deploy/undeploy to keep parameter schemas updated |
Sequence Diagram
sequenceDiagram
participant Client as MCP Client
participant ServeAPI as /api/mcp/serve/[serverId]
participant ExecAPI as /api/workflows/[id]/execute
participant DB as Database
participant Workflow as Workflow Engine
Note over Client,Workflow: MCP Tool Execution Flow
Client->>ServeAPI: POST tools/call {name, arguments}
ServeAPI->>ServeAPI: checkHybridAuth()
ServeAPI->>DB: Query workflow_mcp_tool by serverId + toolName
DB-->>ServeAPI: Return tool with workflowId
ServeAPI->>DB: Check workflow.isDeployed
DB-->>ServeAPI: Return deployment status
alt Workflow not deployed
ServeAPI-->>Client: Error: Workflow not deployed
else Workflow deployed
ServeAPI->>ExecAPI: POST /api/workflows/{workflowId}/execute<br/>{input: arguments, triggerType: 'mcp'}
ExecAPI->>Workflow: Execute workflow with input
Workflow-->>ExecAPI: Return execution result
ExecAPI-->>ServeAPI: Return {success, output}
ServeAPI-->>Client: JSONRPCResponse with result
end
Note over Client,Workflow: Tool Registration & Sync Flow
participant UI as Deploy UI
participant ToolAPI as /api/mcp/workflow-servers/[id]/tools
participant DeployAPI as /api/workflows/[id]/deploy
participant Sync as workflow-mcp-sync
UI->>ToolAPI: POST {workflowId, toolName, description}
ToolAPI->>DB: Verify workflow.isDeployed = true
ToolAPI->>DB: Verify hasValidStartBlock()
ToolAPI->>DB: Insert workflow_mcp_tool
DB-->>ToolAPI: Return created tool
ToolAPI-->>UI: Success
Note over DeployAPI,Sync: On workflow deploy/undeploy
DeployAPI->>Sync: syncMcpToolsForWorkflow()
Sync->>DB: Load workflow blocks
Sync->>Sync: Extract inputFormat from start block
Sync->>Sync: Generate parameter schema
Sync->>DB: Update workflow_mcp_tool.parameterSchema
DB-->>Sync: Schema updated
Sync-->>DeployAPI: Sync complete
@greptile
@greptile
@greptile
Greptile's behavior is changing!
From now on, if a review finishes with no comments, we will not post an additional "statistics" comment to confirm that our review found nothing to comment on. However, you can confirm that we reviewed your changes in the status check section.
This feature can be toggled off in your Code Review Settings by deselecting "Create a status check for each PR".
@greptile