docs/MCP/transports.md
mistral.rs supports three transport types for connecting to MCP servers, each optimized for different use cases.
Best for public APIs, RESTful services, and servers behind load balancers.
{
"source": {
"type": "Http",
"url": "https://api.example.com/mcp",
"timeout_secs": 30,
"headers": {
"X-API-Version": "v1",
"User-Agent": "mistral-rs/0.6.0"
}
},
"bearer_token": "your-api-token"
}
Authorization: Bearer <token>)McpServerSource::Http {
url: "https://hf.co/mcp".to_string(),
timeout_secs: Some(30),
headers: None,
}
Best for real-time applications, bidirectional communication, and low-latency requirements.
{
"source": {
"type": "WebSocket",
"url": "wss://realtime.example.com/mcp",
"timeout_secs": 60,
"headers": {
"Origin": "https://mistral.rs",
"Sec-WebSocket-Protocol": "mcp"
}
},
"bearer_token": "your-websocket-token"
}
McpServerSource::WebSocket {
url: "wss://data.example.com/mcp".to_string(),
timeout_secs: Some(60),
headers: Some(headers),
}
Best for local tools, development servers, and sandboxed environments.
{
"source": {
"type": "Process",
"command": "mcp-server-filesystem",
"args": ["--root", "/tmp", "--readonly"],
"work_dir": "/home/user/workspace",
"env": {
"MCP_LOG_LEVEL": "info",
"MCP_TIMEOUT": "30"
}
}
}
McpServerSource::Process {
command: "mcp-server-filesystem".to_string(),
args: vec!["--root".to_string(), "/tmp".to_string()],
work_dir: None,
env: None,
}
| Use Case | Recommended Transport | Why |
|---|---|---|
| Public APIs | HTTP | Standard auth, caching, load balancing |
| Local tools | Process | No network, process isolation |
| Real-time data | WebSocket | Low latency, server push |
| Corporate proxies | HTTP | Proxy support, standard ports |
| Development | Process | Easy debugging, no network setup |
| Interactive apps | WebSocket | Bidirectional, persistent connection |
All transports implement automatic retry with exponential backoff:
Custom retry behavior can be configured per server.