What is MCP?
MCP (Model Context Protocol) provides:- Standardized Tool Interface: Unified protocol for tool integration
- Dynamic Discovery: Automatically discover available tools from MCP servers
- Multi-Server Support: Connect to multiple MCP servers simultaneously
- Type Safety: Automatic schema validation for tool calls
- Flexible Transport: Support for HTTP, WebSocket, and stdio transports
Quick Start
Let the agent do it
The simplest integration: give the agent a URL and it discovers and calls the tools itself.MCPManager — reachable as agent.mcp_manager — which handles transport, auth, discovery, and routing.
Several servers at once
Without an agent
MCPManager works standalone when you want tools, not autonomy:
aget_tools, acall_tool, aexecute_tool_calls.
Connection Configuration
Agent-level settings
Authentication and transport can be set directly on the agent and apply to every server it uses:Per-server settings with MCPConnection
For different credentials per server, passMCPConnection objects:
Secrets from the environment
Keep keys out of source — bothenv:NAME and ${NAME} are resolved when the connection is made:
Transport
Transport is auto-detected from the URL. Force it when you need to:streamable_http, sse, and stdio. Hyphenated forms such as streamable-http are normalized automatically.
OAuth 2.1
Multi-Server Integration
One manager, many servers, automatic routing:Tool Execution
Executing what a model asked for
When an LLM replies with tool calls, hand the response straight to the manager. Each call is routed and the results come back in order — this is the step anAgent performs between turns.
When a tool returns structured data, its payload arrives as a JSON string in
result:Calling one tool directly
Async
Real-World Example
Error Handling
Failures raise the agent MCP exceptions, and operations retry with exponential backoff up toretry_attempts (default 3) before raising:
Inspecting Configuration
to_dict() gives a serializable, secret-redacted view — safe to log:
Caching
Tool schemas are cached per manager after the first fetch:Best Practices
Connection Pooling
Reuse MCP connections when fetching tools multiple times
Timeout Configuration
Set appropriate timeouts based on server response times
Error Recovery
Implement fallback strategies for MCP server failures
Verbose Logging
Enable verbose mode during development for debugging
Troubleshooting
Common Issues
Connection TimeoutsNext Steps
Model Providers
Configure different LLM providers
Custom Tools
Create your own tool integrations