get_mcp() to connect to any MCP-compatible server and expose its tools to your agent.
Connect via stdio
The server runs as a child process. Communication happens over stdin/stdout. This example uses a filesystem MCP server vianpx (requires Node.js):
Connect via HTTP
Point to a running MCP endpoint. Pass authentication headers as needed:Connect via Docker
Run an MCP server inside a container to isolate file system access, network calls, and dependencies from the host:image parameter pulls and starts the container automatically. Use port to expose the server’s listening port. Pass a pre-configured sandbox= object for finer control over volumes, environment variables, and network policies.
Session lifecycle
get_mcp() returns an MCPSession. You can let the runtime manage the lifecycle (lazy mode) or control it explicitly:
Lazy (default) — connect on first use, no cleanup needed:
async with block when you need to inspect tools before building the agent, validate the connection, or control the exact teardown point:
Filtering tools
An MCP server can expose dozens of tools. Usetools() to filter, rename, and attach guardrails before handing them to the agent:
tools() accepts the same options whether you’re wrapping an MCP session or a plain class:
| Parameter | Description |
|---|---|
prefix | Prepend to all tool names (e.g. "fs_") |
allowlist | Only expose these tools |
blocklist | Exclude these tools |
input_guardrails | Default input guardrails for all tools |
output_guardrails | Default output guardrails for all tools |
tool():
Attaching to an agent
Pass one or more MCP sessions directly in thetools list. MCP sessions mix freely with every other tool type:
Connection summary
| What you have | How to connect |
|---|---|
| Local MCP server (stdio) | get_mcp(command=..., args=...) |
| Remote MCP server (HTTP) | get_mcp(url=..., headers=...) |
| MCP server in Docker | get_mcp(image=..., command=..., port=...) |
| Filtered subset of tools | tools(session, allowlist=..., blocklist=...) |
| Single tool with guardrails | tool(session.tool_name, input_guardrails=...) |

