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.

1 Skipped Deployment
Project Deployment Review Updated (UTC)
docs Skipped Skipped Dec 21, 2025 10:47am

@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 adds MCP (Model Context Protocol) integration allowing workflows to be exposed as tools to external MCP clients. The implementation wraps existing workflow execution APIs as MCP-compliant JSON-RPC endpoints.

Key Changes:

  • New database tables (workflow_mcp_server, workflow_mcp_tool) for managing MCP servers and tool mappings
  • MCP serve endpoint at /api/mcp/serve/[serverId] implementing JSON-RPC protocol for tool listing and execution
  • CRUD APIs for managing workflow MCP servers and tools with proper authentication middleware
  • UI components in deployment modal for configuring workflows as MCP tools
  • Added 'mcp' trigger type throughout logging and execution pipeline
  • Schema conversion utilities to transform workflow input formats into MCP tool schemas

Issues Found:

  • Missing timeout on workflow execution fetch call could cause indefinite hangs
  • Database queries load all tools then filter in memory instead of using database-level filtering
  • All workflow parameters marked as required by default with no optional field support
  • Auto-sync logic in UI could cause race conditions with rapid edits

Confidence Score: 4/5

  • Safe to merge with minor issues that should be addressed in follow-up
  • The implementation is well-structured with proper database design, authentication middleware, and thorough validation. The critical issue is the missing timeout on workflow execution fetch calls which could cause hangs. Other issues are optimization opportunities (database filtering) and UX improvements (optional fields, race condition handling) rather than blocking problems.
  • apps/sim/app/api/mcp/serve/[serverId]/route.ts needs timeout added to fetch call

Important Files Changed

Filename Overview
apps/sim/app/api/mcp/serve/[serverId]/route.ts New MCP protocol endpoint that exposes workflows as tools, handles JSON-RPC requests, and executes workflows via internal API calls
apps/sim/lib/mcp/workflow-tool-schema.ts Schema conversion logic that transforms workflow input formats to MCP tool schemas; marks all fields as required by default which may be too restrictive
packages/db/schema.ts Adds two new tables (workflow_mcp_server, workflow_mcp_tool) with proper indexes, foreign keys, and cascade deletes
apps/sim/app/api/mcp/workflow-servers/[id]/tools/route.ts CRUD operations for MCP tools with proper validation including deployed status checks, start block verification, and workspace permission checks
apps/sim/lib/mcp/middleware.ts New authentication middleware for MCP endpoints with permission level checks (read/write/admin) and workspace verification
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/components/deploy-modal/components/mcp-tool/mcp-tool.tsx UI component for configuring workflows as MCP tools with real-time syncing, multi-server deployment, and parameter description editing

Sequence Diagram

sequenceDiagram
    participant Client as MCP Client
    participant Serve as MCP Serve Route
    participant DB as Database
    participant WorkflowAPI as Workflow Execute API
    participant Executor as Workflow Executor
    
    Note over Client,Executor: MCP Tool Call Flow
    
    Client->>Serve: POST tools/call request
    Serve->>DB: Query workflow_mcp_tool table
    DB-->>Serve: Tool metadata
    
    Serve->>DB: Check workflow deployment
    DB-->>Serve: isDeployed status
    
    alt Not deployed
        Serve-->>Client: Error: Not deployed
    end
    
    Serve->>WorkflowAPI: Fetch execute endpoint
    WorkflowAPI->>Executor: Run workflow blocks
    Executor-->>WorkflowAPI: Result
    WorkflowAPI-->>Serve: Execution output
    
    Serve-->>Client: CallToolResult
    
    Note over Client,Executor: Tool Registration
    
    Client->>Serve: POST tools/list request
    Serve->>DB: Query tool schemas
    DB-->>Serve: Tools with parameters
    Serve-->>Client: ListToolsResult
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

@icecrasher321
Copy link
Collaborator

@greptile

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.

31 files reviewed, 5 comments

Edit Code Review Agent Settings | Greptile

@icecrasher321 icecrasher321 changed the title feat(workflow-as-mcp): wrapping workflows in the same workspace as MCP tools to particular MCP servers. feat(workflow-as-mcp): wrapping workflows in the same workspace as MCP tools to particular MCP servers Dec 21, 2025
@icecrasher321
Copy link
Collaborator

@greptile

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.

41 files reviewed, 4 comments

Edit Code Review Agent Settings | Greptile

for (const field of inputFormat) {
if (!field.name) continue

const zodType = fieldTypeToZod(field.type, true)
Copy link
Contributor

Choose a reason for hiding this comment

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

style: hardcoded true for isRequired - all Zod schemas created will be required even if workflow parameters should be optional

Consider passing field.required or a similar flag if available from InputFormatField

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/lib/mcp/workflow-tool-schema.ts
Line: 84:84

Comment:
**style:** hardcoded `true` for `isRequired` - all Zod schemas created will be required even if workflow parameters should be optional

Consider passing `field.required` or a similar flag if available from `InputFormatField`

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines 206 to 246
useEffect(() => {
if (!hasLoadedInitialData.current) return
if (!toolName.trim()) return

const toolsToUpdate: Array<{ serverId: string; toolId: string }> = []
for (const server of servers) {
const toolInfo = serverToolsMap[server.id]
if (toolInfo?.tool) {
toolsToUpdate.push({ serverId: server.id, toolId: toolInfo.tool.id })
}
}

if (toolsToUpdate.length === 0) return

const timeoutId = setTimeout(async () => {
for (const { serverId, toolId } of toolsToUpdate) {
try {
await updateToolMutation.mutateAsync({
workspaceId,
serverId,
toolId,
toolName: toolName.trim(),
toolDescription: toolDescription.trim() || undefined,
parameterSchema,
})
} catch (error) {
logger.error(`Failed to sync tool ${toolId}:`, error)
}
}
}, 500)

return () => clearTimeout(timeoutId)
}, [
toolName,
toolDescription,
parameterSchema,
servers,
serverToolsMap,
workspaceId,
updateToolMutation,
])
Copy link
Contributor

Choose a reason for hiding this comment

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

style: auto-sync logic updates all deployed tools whenever any field changes - could cause race conditions if user rapidly edits fields, or conflicts if multiple users edit the same workflow

Consider adding optimistic locking or version tracking

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/components/deploy-modal/components/mcp-tool/mcp-tool.tsx
Line: 206:246

Comment:
**style:** auto-sync logic updates all deployed tools whenever any field changes - could cause race conditions if user rapidly edits fields, or conflicts if multiple users edit the same workflow

Consider adding optimistic locking or version tracking

How can I resolve this? If you propose a fix, please make it concise.

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.

5 participants