Quick Start
Connect an agent to an MCP server:Basic Usage
Single MCP Server
The simplest way to use MCP is with a single server:Multiple MCP Servers
UseMultiMCPToolProvider to connect to multiple servers:
Transport Methods
Laddr supports three MCP transport methods:1. Stdio Transport
For local command-based MCP servers:- Running local MCP servers
- Server is launched via command line
- Examples: filesystem, git, database servers
2. HTTP Transport (Streamable HTTP)
For remote HTTP-based MCP servers:- Connecting to remote MCP servers
- Server exposes HTTP endpoint
- Examples: hosted MCP services, cloud-based tools
3. SSE Transport (Server-Sent Events)
For real-time streaming MCP servers:- Server uses Server-Sent Events
- Real-time event streaming needed
- Examples: live data feeds, streaming APIs
Connection Lifecycle
Automatic Connection Management
When you passMCPToolProvider to an Agent, connections are managed automatically:
Manual Connection Management
For more control, useconnect() and disconnect():
Async Context Manager
You can also use MCP providers as async context managers:Auto Refresh
Enableauto_refresh to reconnect and refresh tools on each agent run:
- MCP server tools change frequently
- Server may restart between runs
- Tool schema updates are common
Tool Name Collision Handling
When multiple MCP servers provide tools with the same name, Laddr automatically prefixes tool names with the server identifier:server_name is not provided, the transport type is used as prefix (e.g., stdio_read_file).
Example: Filesystem Agent
Complete example of a filesystem exploration agent:Example: Multiple MCP Servers
Combining filesystem and git MCP servers:Best Practices
1. Resource Cleanup
Always disconnect MCP connections when done:2. Error Handling
Handle connection failures gracefully:3. Server Names
Always provideserver_name when using multiple servers:
4. Auto Refresh
Useauto_refresh=True for hosted servers that may restart:
5. Tool Discovery
Tools are automatically discovered and registered - no need to explicitly list them.Troubleshooting
Connection Failures
If MCP connection fails:- Check that the MCP server command is correct
- Verify network connectivity for HTTP/SSE transports
- Check API keys for authenticated servers
- Review logs for detailed error messages
Tool Not Found
If an MCP tool is not available:- Ensure MCP provider is connected:
mcp.is_connected() - Check tool name (may be prefixed with server name)
- Verify MCP server provides the expected tools
- Use
await mcp.discover_tools()to list available tools
Import Errors
If you see import errors:- Install required dependencies:
pip install aiohttp - For stdio transport, ensure Node.js/npx is available
- Check that MCP server packages are installed
Advanced Usage
Custom Tool Prefixing
Control how tool names are prefixed:Connection State Checking
Check if MCP provider is connected:Manual Tool Registration
Register MCP tools manually into a ToolRegistry:Finding MCP Servers
Check out the MCP Servers repository for a collection of available MCP servers:- Filesystem - File and directory operations
- Git - Git repository operations
- PostgreSQL - Database queries
- Brave Search - Web search
- And many more…
Next Steps
- Tool Configuration - Create custom tools
- Agent Configuration - Configure agents
- MCP Examples - See more MCP examples
- Filesystem Agent Example - Complete filesystem agent