mcp_servers: their tools are added to the agent’s own, and each call is forwarded to the server.
A local server over stdio
MCPServerStdioParams takes command, and optionally args, env, cwd, encoding and encoding_error_handler.
A remote server over HTTP (SSE)
How calls are made
- The agent asks the server for its tools, with the schemas it publishes, when it is built and when it dispatches tool calls, so a server that changes its tools is picked up.
- Each tool call opens a session to the server, calls the tool, returns its result as text and closes the session. Servers need no lifecycle management on your side.
- A tool error is returned to the model like any tool error.
The agent talks to its MCP servers synchronously, each time with an event loop of its own (
asyncio.run). Build and run an agent that has MCP servers from synchronous code, or from a worker thread (asyncio.to_thread) when your application is async.Limits
MCP servers are not available to durable agents yet:TemporalDurability raises an error when such an agent is built.