brain/wiki/ai-intelligence/mcp-server.md
Exposes an Activepieces project as an MCP server so AI clients (Claude Desktop, Cursor, Windsurf) can read and manipulate flows, connections, tables, and runs through a typed tool interface. One McpServer record per project (UNIQUE projectId), authenticated by a bearer token. Available in CE, EE, and Cloud.
id, projectId (unique), token (72-char), disabledTools[] (JSONB, nullable; null/[] means all controllable tools enabled).mcpServerService.buildServer() — builds the server per-request: metadata → dynamic flow tools → controllable + locked static tools → empty resources/prompts (spec compliance).mcp/mcp-service.ts, mcp/mcp-server-controller.ts, mcp/tools/, mcp/oauth/.ap_list_flows, ap_flow_structure, ap_research_pieces, ap_get_piece_props, ap_list_connections, ap_list_tables, ap_get_run).ap_search_actions / ap_search_triggers: semantic (pgvector) search over the action and trigger catalog with a keyword-floor fallback. Registered only when AP_TOOL_SEARCH_ENABLED is on — that env flag is the master switch, so their LOCKED_TOOL_NAMES entries are inert while it is off. The settings panel lists them via the TOOL_SEARCH_ENABLED flag.disabledTools (flow/step/branch management, publish, table + record ops, testing, run management).@activepieces/piece-mcp) becomes a callable tool named {toolName}_{flowId[0..4]}; execution submits a webhook (sync if returnsResponse, else async).POST /v1/mcp/:projectId/http (StreamableHTTP). Config: GET/POST /v1/mcp/:projectId, rotate token via .../rotate.Authorization: Bearer {token} or ?token=. OAuth 2.0 PKCE also supported for clients that need it.SIMPLE_HTTP, STREAMABLE_HTTP, SSE.authorizeMcp() (in-embed OAuth consent), mcpSettings(), and generateMcpToken() (mints { mcpServerUrl, mcpToken } with no OAuth flow, backed by POST /v1/projects/:projectId/mcp-server/token — a short-lived 15-min project-scoped token).ap_create_flow/ap_build_flow/ap_duplicate_flow stamp ownerId (OAuth user) and createdBy: { type: 'MCP', id }.MCP_SERVER_CONNECTED is deduped to at most one/user/server/day (telemetryDedupe.onceToday) — a daily-active signal, not request volume. Per-call usage is MCP_TOOL_CALLED.domainHelper.getPublicUrlFromRequest so subpath-hosted instances advertise the right prefix. 401s carry an RFC 9728 WWW-Authenticate: Bearer resource_metadata="…" header. Host-root .well-known/oauth-* must still be forwarded to AP by the operator.x-ap-conversation-id header (EE chat) rebinds the server to a conversation's project, but only when scoping matches the token — it can never widen the grant.agents/, NOT here (it's a probe, not the AP-as-server feature).Entry point: mcpServerModule, the Fastify plugin in mcp/mcp-module.ts registered from packages/server/api/src/app/app.ts.
packages/server/api/src/app/mcp/ — module, service, entity, project + platform controllers, and the per-request buildMcpServerpackages/server/api/src/app/mcp/tools/ — locked and controllable tool definitions, plus curated piece expertise notespackages/server/api/src/app/mcp/oauth/ — OAuth 2.0 PKCE flow: metadata, authorize, token, revokepackages/core/shared/src/lib/automation/mcp/ — McpServer schema, McpToolDefinition, MCP OAuth typespackages/web/src/app/components/project-settings/mcp-server/ — settings panel: credentials, flows-as-tools, tool togglespackages/web/src/app/routes/mcp-authorize/ — standalone OAuth consent page and its permission itempackages/web/src/app/routes/embed/ — the embedded-mcp-* dialogs for managed-auth consent and settingspackages/ee/embed-sdk/src/index.ts — embed SDK public methods authorizeMcp(), mcpSettings(), generateMcpToken()packages/web/src/features/agents/agent-tools/ — adding an external MCP server as an agent toolpackages/web/src/app/builder/test-step/custom-test-step/mcp-tool-testing-dialog.tsx — test one MCP tool from the builderPaths verified 2026-07-17.