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:
initialize,notifications/initializedandtools/liston the discovery session.initialize,notifications/initializedandtools/callon a second session.tools/liston 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.
- A stdio server is one process for discovery and one more for each call. State held in the server process does not carry from one call to the next.
- A Streamable HTTP server that issues session ids sees one session per call.
HTTPTransportpassesterminate_on_close=True, so the SDK sends a DELETE as each one closes. - No session is open between calls, and
ClientSessiongets nomessage_handlerorlogging_callback.notifications/tools/list_changed, log messages and progress have nothing to arrive on. get_mcp_toolsbuilds a new resolver each time it runs, so the tool list is read again when a crew prepares the next task or an agent kicks off again.cache_tools_list=Truekeeps the first list for five minutes in a module-level dict.MCPClient._retry_operationsends a failed or timed-outtools/callagain on the same per-call session, up to three attempts with a one and then two second wait. The execution timeout is 30 seconds.
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
- lib/crewai/src/crewai/tools/mcp_native_tool.py, MCPNativeTool, commit
77237aec,lib/crewai/src/crewai/tools/mcp_native_tool.py:MCPNativeTool,MCPNativeTool._run_async, 2026-11-27 - lib/crewai/src/crewai/mcp/tool_resolver.py, _resolve_native and its client factory, commit
77237aec,lib/crewai/src/crewai/mcp/tool_resolver.py:MCPToolResolver._resolve_native,MCPToolResolver._client_factory, 2026-11-27 - lib/crewai/src/crewai/mcp/client.py, timeouts, the tool list cache and _retry_operation, commit
77237aec,lib/crewai/src/crewai/mcp/client.py:MCPClient.connect,MCPClient.list_tools,MCPClient._retry_operation, 2026-11-27 - lib/crewai/src/crewai/mcp/transports/http.py, terminate_on_close, commit
77237aec,lib/crewai/src/crewai/mcp/transports/http.py:HTTPTransport.connect, 2026-11-27 - lib/crewai/src/crewai/agent/core.py, get_mcp_tools builds a new resolver each time, commit
77237aec,lib/crewai/src/crewai/agent/core.py:Agent.get_mcp_tools,Agent._prepare_kickoff, 2026-11-27 - lib/crewai/src/crewai/crew.py, MCP tools injected per task, commit
77237aec,lib/crewai/src/crewai/crew.py:Crew._prepare_tools,Crew._inject_mcp_tools, 2026-11-27 - mcp 1.30.0, ClientSession.call_tool and _validate_tool_result,
mcp/client/session.py, 2026-11-16 - mcp 1.30.0, streamable_http_client session termination,
mcp/client/streamable_http.py, 2026-11-16