Expose cached MCP server tools to AI chat through a tool provider
What
Third step of the MCP servers plan (after #28597 and #28835): the tools cached on each mcpServer become callable from AI chat.
ToolCategory.MCPand aMcpToolProviderexpose every cached tool of every active, reachable server asmcp_<server>_<tool>. Colliding names, or names over the 64-character provider limit, get a short hash suffix. Schemas come from the cache, so a chat turn does not list tools remotely.McpServerClientService.callToolreuses the sync's SDK client and connected-account resolution. Results keep structured content, text and embedded resource text, and drop binary payloads. A protocol error or a missing account returns a failed output instead of throwing.- The workspace assistant sees the tools under "MCP Server Tools" in its catalog and reaches them through
learn_tools/execute_tool. No mention UI. App-driven agents are a one-line follow-up inOPEN_ENDED_AGENT_REGISTRY_TOOL_CATEGORIES.
Approval
Per the MCP annotation defaults, a tool may change data unless it declares readOnlyHint: true or destructiveHint: false. Such a tool only runs once approved through propose_tool_call; the provider refuses a direct call, like publish_front_component does.
Trade-off: most servers do not annotate their tools, so most MCP calls ask for approval, and runs with no human (agent triggers, workflow agent steps) cannot use those tools. The permissive alternative is one line in is-destructive-mcp-server-tool.util.ts: require approval only when destructiveHint is explicitly true.
Keeping the cache honest
Two guards agreed in the #28835 review thread:
- A never-synced server (typically created before the caller had an account) is synced while building the catalog, once the caller can connect: in parallel, under a 5 second deadline, retried at most every 5 minutes via the row's
updatedAt. It is the only remote call on the catalog path and also runs when the front loads the tool index. - When the server says it does not know the tool, as a protocol error or an error result, the list is re-synced and the agent is told to learn the tools again.
The per-conversation cache for user-scoped servers stays a follow-up (twentyhq/core-team-issues#3172). Until then a user without a connected account sees the workspace list and gets a "connect an account" failure on call.
Wiring
The client and tool sync services move to McpServerClientModule, so ToolProviderModule imports them without the GraphQL resolver module.
Test
- Unit: unique tool names, annotation defaults, retry window, unknown-tool message pattern, result mapping.
- Integration against a fake MCP server: listed in
getToolIndexunderMCP, schema served bygetToolInputSchema, executed throughresolveAndExecute, refused until approved, never-synced list filled on the next catalog build, re-synced when the server drops a tool.
Open question
Twenty's own MCP endpoint. It builds its tool list from the whole registry, so external MCP clients now see third-party MCP tools through Twenty. Tools that may change data are refused there, read-only ones run. Do we want Twenty to proxy these, or should the endpoint exclude the MCP category?