.agents/features/mcp.md
Exposes an Activepieces project as a Model Context Protocol (MCP) server so that AI clients (Claude Desktop, Cursor, Windsurf) can read and manipulate flows, connections, tables, and other project resources through a typed tool interface. Each project gets exactly one MCP server record with a bearer token for authentication; the server is built per-request from a combination of static locked/controllable tools and dynamic flow-as-tool entries.
packages/server/api/src/app/mcp/mcp-service.ts — server build logic, tool registration, token authpackages/server/api/src/app/mcp/mcp-server-controller.ts — HTTP endpoints (get, update, rotate, protocol handler, agent validator)packages/server/api/src/app/mcp/mcp-entity.ts — McpServer entitypackages/server/api/src/app/mcp/tools/index.ts — static tool exportspackages/server/api/src/app/mcp/oauth/ — OAuth 2.0 PKCE flow for MCP clients that require OAuthpackages/shared/src/lib/automation/mcp/mcp.ts — McpServer schema, McpToolDefinition type, McpServerStatus enumpackages/shared/src/lib/automation/mcp/mcp-oauth.ts — MCP OAuth typespackages/web/src/app/components/project-settings/mcp-server/index.tsx — project settings panel for MCPpackages/web/src/app/components/project-settings/mcp-server/mcp-credentials.tsx — token display and rotate UIpackages/web/src/app/components/project-settings/mcp-server/mcp-flows.tsx — list of flows exposed as toolspackages/web/src/app/components/project-settings/mcp-server/mcp-tools.tsx — controllable tool toggle UIpackages/web/src/app/routes/mcp-authorize/index.tsx — OAuth authorization page for MCP clientspackages/web/src/features/agents/agent-tools/mcp-tool-dialog/index.tsx — dialog to add an external MCP server as an agent toolpackages/web/src/features/agents/agent-tools/mcp-tool-dialog/add-mcp-tool-form.tsx — form inside the dialogpackages/web/src/features/agents/agent-tools/components/mcp-tool.tsx — inline display of an MCP tool in agent settingspackages/web/src/app/builder/test-step/custom-test-step/mcp-tool-testing-dialog.tsx — test an individual MCP tool from the builder{toolName}_{flowId[0..4]}/http endpoint@activepieces/piece-mcp; a flow with this trigger is exposed as a callable tool via MCPnull means all controllable tools are enabledMcpServer: id, projectId (UNIQUE — one per project), status (ENABLED/DISABLED), token (72-char auth), enabledTools[] (JSONB, nullable — defaults to ALL_CONTROLLABLE_TOOL_NAMES).
Locked tools (always enabled if MCP is on):
ap_list_flows — list all flows in projectap_flow_structure — get flow definition and structureap_list_pieces — browse available piecesap_list_connections — list app connectionsControllable tools (can be toggled per-project):
ap_create_flow, ap_rename_flow — flow managementap_update_trigger — change flow triggerap_add_step, ap_update_step, ap_delete_step — step managementap_add_branch, ap_delete_branch — conditional branchingap_lock_and_publish — publish flow versionap_change_flow_status — enable/disable flowap_manage_notes — add/update flow annotationsap_create_table, ap_delete_table, ap_list_tables — table managementap_manage_fields, ap_insert_records, ap_find_records, ap_update_record, ap_delete_records — record operationsap_test_flow, ap_test_step, ap_validate_flow, ap_validate_step_config, ap_get_piece_props — build/test helpersap_list_runs, ap_get_run, ap_retry_run — run managementap_list_ai_models, ap_setup_guide — discoveryDynamic flow tools: Each enabled flow with MCP trigger piece is registered as a callable tool. Name format: {toolName}_{flowId.substring(0, 4)}. Execution: submits webhook to flow (sync if returnsResponse, async otherwise).
{ title: 'ap_xxx', description: '...', inputSchema: zodSchema, annotations: { readOnlyHint, destructiveHint }, execute: async (args) => ({ content: [{ type: 'text', text: '...' }] }) }
GET /v1/mcp/:projectId — get MCP server config + populated flowsPOST /v1/mcp/:projectId — update status and/or enabledToolsPOST /v1/mcp/:projectId/rotate — rotate auth tokenPOST /v1/mcp/:projectId/http — StreamableHTTP MCP protocol endpoint (main protocol handler)External MCP server validation for the agent piece lives under packages/server/api/src/app/agents/ (endpoint: POST /v1/projects/:projectId/agent-tools/mcp/validate), not here — it's a probe for URLs the agent will later connect to, not part of the Activepieces-as-MCP-server feature.
Bearer token (Authorization: Bearer {token}) or query param (?token={token}). Returns 401 if invalid.
OAuth 2.0 PKCE flow is supported for AI clients that require OAuth. The MCP OAuth module (mcp-oauth.module.ts) registers metadata, authorization, token, and revocation endpoints.
mcpServerService.buildServer() — built per-request:
McpServer instance with metadata (name, version, icons)AI pieces use MCP tools via 3 transport protocols:
SIMPLE_HTTP — basic HTTPSTREAMABLE_HTTP — streaming with StreamableHTTPClientTransportSSE — server-sent events