Quick Start
MCPClient Parameters
MCPClient is the main entry point for connecting to MCP servers. It provides flexible configuration for SSL, sandboxing, middleware, and server-initiated callbacks.
MCPClient Constructor Parameters
Path to a JSON configuration file or a configuration dictionary containing server definitions
Restrict which servers from the config to use. When set, only the specified servers will be available
SSL certificate verification for HTTP/HTTPS servers. Set to
False for self-signed certificates or internal serversRun MCP servers in an isolated E2B sandbox environment. See Sandbox for configuration
E2B sandbox configuration including
api_key and sandbox_template_id. Required when sandbox=True. See SandboxEnable Python code execution mode for interacting with MCP tools programmatically. See Code Mode
Custom middleware for intercepting and processing tool calls. See Middleware
Directories or files to advertise to servers. Roots inform servers about accessible filesystem locations. See Roots
Custom callback to handle
roots/list requests from servers. Overrides the static roots parameter with dynamic responsesHandle server-initiated sampling requests (LLM completions). Required for servers that use sampling. See Sampling
Handle server requests for user input or decisions. See Elicitation
Handle server notifications and messages. See Notifications
Server Configuration
MCP servers are configured in themcpServers object. Each server has a unique name and connection settings.
STDIO Servers (Local)
Servers that run as local processes:| Field | Required | Description |
|---|---|---|
command | Yes | Executable to run (npx, python, etc.) |
args | No | Arguments to pass to the command |
env | No | Environment variables for the process |
HTTP Servers (Remote)
Servers accessible via HTTP/HTTPS:| Field | Required | Description |
|---|---|---|
url | Yes | Server URL (supports SSE and Streamable HTTP) |
headers | No | HTTP headers for authentication |
timeout | No | Connection timeout in seconds (default: 5) |
sse_read_timeout | No | SSE read timeout in seconds (default: 300) |
auth | No | Authentication config (see Authentication) |
WebSocket Servers
Servers accessible via WebSocket:| Field | Required | Description |
|---|---|---|
ws_url | Yes | WebSocket URL |
headers | No | HTTP headers for the upgrade request |
auth | No | Bearer token string |
Multiple Servers
Configure multiple servers for different capabilities:Alternative Constructors
from_dict
from_config_file
MCPClient().
Common Issues
| Error | Cause | Solution |
|---|---|---|
Server 'x' not found | Server name not in config | Check spelling, verify config file |
SSL certificate error | Self-signed cert or internal server | Set verify=False |
Connection timeout | Server not running or unreachable | Check server URL/command, network |
Permission denied | Missing permissions for command | Check file permissions, PATH |