crewAI opens a new MCP session for every tool call

Kind: idiosyncrasy · Status: current · Last verified: 2026-11-16 · Clients: crewai · Revisions: 2025-11-25

At 758b2c1d, MCPToolResolver._resolve_native builds a discovery MCPClient, connects, calls list_tools, and disconnects. It keeps no client. Each MCPNativeTool it returns holds a client_factory closure that builds a new transport and a new MCPClient.

MCPNativeTool._run_async calls the factory, connects, calls the tool, and disconnects in finally. The class docstring gives the reason: parallel calls that shared connection state caused anyio cancel-scope errors.

What a server sees

The probe's stdio capture of 1.15.37 for one agent turn that calls one tool (probe/runs/crewai@1.15.37/default/both-stdio/tools.result.summary_and_data/wire.jsonl) has this order:

  1. initialize, notifications/initialized and tools/list on the discovery session.
  2. initialize, notifications/initialized and tools/call on a second session.
  3. tools/list on the second session.

The last request is the SDK's. ClientSession.call_tool validates structuredContent against the tool's outputSchema when the result is not an error, and a session that has not listed tools lists them first. A per-call session never has. The HTTP capture has the same order.

What follows from it

Each point is read from the code at 758b2c1d.

The other routes

The https:// string route has the same shape. _discover_mcp_tools opens one session to list tools and MCPToolWrapper._execute_tool opens one per call. The adapter route differs: mcpadapt keeps one session per server open on a background thread until MCPServerAdapter.stop(). [[crewai-reaches-mcp-through-four-entry-points]] compares the routes.

Sources