turul-mcp-client
MCP client library with multi-transport support. Bilingual by default: it negotiates the spec per connection, speaking either the MCP 2026-07-28 stateless core or MCP 2025-11-25.
Overview
turul-mcp-client provides a complete client implementation for the Model Context Protocol (MCP), supporting multiple transport layers and offering both high-level and low-level APIs for interacting with MCP servers.
Features
- ✅ Multi-Transport Support - HTTP and SSE transports
- ✅ Bilingual Protocol - Default build negotiates per connection: MCP 2026-07-28 stateless core or 2025-11-25
- ✅ Session Management - Automatic session handling with recovery
- ✅ Streaming Support - Real-time event streaming and progress tracking
- ✅ Async/Await - Built on Tokio for high performance
- ✅ Error Recovery - Comprehensive error types and retry mechanisms
Quick Start
Add this to your Cargo.toml:
[]
= "0.4"
= { = "1.0", = ["full"] }
Basic HTTP Client
use ;
use HttpTransport;
async
Transport Types
HTTP Transport (Streamable HTTP)
For modern MCP servers (the client negotiates MCP 2026-07-28 or 2025-11-25 per connection):
use HttpTransport;
let transport = new?;
let client = new
.with_transport
.build;
SSE Transport (HTTP+SSE, deprecated — SEP-2596)
Deprecated upstream (SEP-2596, 2025-03-26): "new implementations SHOULD NOT adopt it; existing implementations SHOULD migrate to Streamable HTTP." Use
HttpTransportunless you must talk to an unmigrated ≤ 2024-11-05 server.
use SseTransport;
let transport = new?;
let client = new
.with_transport
.build;
Future Transport Support
Additional transport implementations (stdio) are planned for future releases.
Client Configuration
Using ClientConfig
use ;
use Duration;
let config = ClientConfig ,
};
let client = new
.with_config
.with_url?
.build;
Using URL Builder
let client = new
.with_url? // Automatically detects transport type
.build;
Session Management
Connection Status
use SessionState;
// Check connection and session status
let status = client.connection_status.await;
println!;
println!;
println!;
if let Some = status.session_id
Session Information
// Get detailed session information
let session_info = client.session_info.await;
println!;
println!;
println!;
Connection Management
// Check if client is ready
if !client.is_ready.await
// Disconnect and cleanup
client.disconnect.await?;
Error Handling
Error Types
use ;
async
Core Operations
Tools
// List available tools
let tools = client.list_tools.await?;
for tool in &tools
// Call a tool
let result = client.call_tool.await?;
println!;
Resources
// List available resources
let resources = client.list_resources.await?;
for resource in &resources
// Read a resource
let content = client.read_resource.await?;
println!;
Prompts
// List available prompts
let prompts = client.list_prompts.await?;
for prompt in &prompts
// Get a prompt with arguments
let prompt_result = client.get_prompt.await?;
println!;
Tasks (MCP 2025-11-25 opt-in)
// Call a tool with task augmentation (long-running)
let task = client.call_tool_with_task.await?;
println!;
// Poll task status
let task = client.get_task.await?;
println!;
// Wait for result (blocks until terminal)
let result = client.get_task_result.await?;
// List all tasks
let tasks = client.list_tasks.await?;
// Cancel a running task
let cancelled = client.cancel_task.await?;
Streaming and Events
Stream Handler
// Access the stream handler for server events
let stream_handler = client.stream_handler.await;
// The stream handler processes server-sent events automatically
// This is primarily for internal use and advanced scenarios
Protocol Headers
MCP Protocol Version
The client automatically sends the negotiated protocol version header. On a
2026-07-28 connection it is stateless (no session id); the mcp-session-id
below is the 2025-11-25 opt-in lane only:
// On a 2025-11-25 connection the client sends: MCP-Protocol-Version: 2025-11-25
// Server responds with: mcp-session-id: <session-uuid>
// (On a 2026-07-28 connection: MCP-Protocol-Version: 2026-07-28, no session id)
// Access session ID from connection status
let status = client.connection_status.await;
if let Some = status.session_id
Testing and Development
Health Check
// Ping the server to check connectivity
match client.ping.await
Transport Statistics
// Get transport layer statistics
let stats = client.transport_stats.await;
println!;
println!;
println!;
Transport Detection
Automatic Transport Selection
use ;
// Detect transport type from URL
let transport_type = detect_transport_type?;
println!;
// Create transport automatically
let transport = from_url?;
// List available transports
let available = available_transports;
println!;
Examples
Complete Application
use ;
use HttpTransport;
use ;
use Duration;
async
Transport Comparison
// SseTransport: HTTP+SSE is deprecated upstream (SEP-2596)
use ;
// Compare transport capabilities
Feature Flags
[]
= { = "0.4", = ["sse"] }
Available features:
default=["http", "sse"]- HTTP and SSE transporthttp- HTTP transport support (included by default)sse- Server-Sent Events transport (included by default)stdio- (Planned) Standard I/O transport for executable servers
Error Reference
McpClientError Types
use McpClientError;
match error
Performance Notes
- Connection Reuse: Transport connections are reused across requests
- Async/Await: All operations are non-blocking and async
- Memory Efficient: Streaming responses avoid large memory allocations
- Session Cleanup: Automatic session cleanup on client drop
Compatibility
MCP Protocol Versions
The client automatically adapts to server capabilities:
- 2024-11-05: Basic MCP without streamable HTTP
- 2025-03-26: Streamable HTTP with SSE support
- 2025-06-18: Full feature set with meta fields and enhanced capabilities
- 2025-11-25: Icons, tasks, sampling tools, URL elicitation (opt-in spec lane)
- 2026-07-28: Stateless core —
server/discover, per-request_meta, noMcp-Session-Id(default)
Transport Compatibility
- HTTP: Works with all MCP servers
- SSE: Requires server-sent events support
- Stdio: (Planned) Executable MCP server support
Related Crates
- turul-mcp-server: Complete MCP server framework
- turul-mcp-protocol: MCP protocol types and traits
- turul-http-mcp-server: HTTP transport layer for servers
License
Licensed under the MIT License. See LICENSE for details.