Skip to content

Conversation

@Pbonmars-20031006
Copy link
Contributor

@Pbonmars-20031006 Pbonmars-20031006 commented Dec 17, 2025

Summary

We wrap the existing API calls as MCP tool endpoints and use them to trigger workflows from MCP servers.

Type of Change

  • New feature

Testing

Tested manually with @Sg312

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

vercel bot commented Dec 17, 2025

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

Project Deployment Review Updated (UTC)
docs Ready Ready Preview, Comment Dec 31, 2025 0:49am

@Pbonmars-20031006 Pbonmars-20031006 changed the base branch from main to staging December 17, 2025 00:48
@Pbonmars-20031006 Pbonmars-20031006 marked this pull request as ready for review December 17, 2025 02:42
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 17, 2025

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_server and workflow_mcp_tool database 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 mcp as 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.ts for 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
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

29 files reviewed, 4 comments

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 29, 2025

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".

@icecrasher321 icecrasher321 changed the base branch from main to staging December 29, 2025 23:29
@icecrasher321
Copy link
Collaborator

@greptile

@waleedlatif1 waleedlatif1 merged commit c77268c into staging Dec 31, 2025
10 checks passed
@waleedlatif1 waleedlatif1 deleted the feat/workflow-as-mcp branch December 31, 2025 00:52
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.

6 participants