| Crates.io | hanzo-mcp-client |
| lib.rs | hanzo-mcp-client |
| version | 0.6.0 |
| created_at | 2025-12-09 22:18:11.234929+00 |
| updated_at | 2026-01-25 20:33:38.412279+00 |
| description | Async MCP (Model Context Protocol) client for Hanzo AI agents |
| homepage | https://github.com/hanzoai/dev/tree/main/mcp-client |
| repository | https://github.com/hanzoai/dev |
| max_upload_size | |
| id | 1976841 |
| size | 43,965 |
Async MCP (Model Context Protocol) client for Rust.
This crate provides an async client for communicating with MCP servers. It handles the JSON-RPC transport layer, message framing, and provides a clean API for tool discovery and execution.
[dependencies]
hanzo-mcp-client = "0.6"
tokio = { version = "1", features = ["full"] }
use hanzo_mcp_client::McpClient;
use serde_json::json;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Spawn an MCP server and connect
let client = McpClient::spawn(
"npx",
&["-y", "@modelcontextprotocol/server-filesystem", "/workspace"],
).await?;
// List available tools
let tools = client.list_tools().await?;
println!("Available tools: {:?}", tools.iter().map(|t| &t.name).collect::<Vec<_>>());
// Call a tool
let result = client.call_tool("read_file", json!({
"path": "README.md"
})).await?;
println!("Result: {:?}", result);
Ok(())
}
hanzo-mcp-typesimpl McpClient {
/// Spawn an MCP server subprocess and connect
pub async fn spawn(command: &str, args: &[&str]) -> Result<Self>;
/// Connect to an existing MCP server via stdio
pub async fn connect(stdin: ChildStdin, stdout: ChildStdout) -> Result<Self>;
/// Initialize the MCP connection
pub async fn initialize(&self) -> Result<InitializeResult>;
/// List available tools
pub async fn list_tools(&self) -> Result<Vec<Tool>>;
/// Call a tool with arguments
pub async fn call_tool(&self, name: &str, arguments: Value) -> Result<CallToolResult>;
/// List available resources
pub async fn list_resources(&self) -> Result<Vec<Resource>>;
/// Read a resource
pub async fn read_resource(&self, uri: &str) -> Result<ReadResourceResult>;
/// List available prompts
pub async fn list_prompts(&self) -> Result<Vec<Prompt>>;
/// Get a prompt with arguments
pub async fn get_prompt(&self, name: &str, arguments: Value) -> Result<GetPromptResult>;
}
use hanzo_mcp_client::McpClient;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Connect to multiple MCP servers
let filesystem = McpClient::spawn(
"npx", &["-y", "@modelcontextprotocol/server-filesystem", "/workspace"]
).await?;
let github = McpClient::spawn(
"npx", &["-y", "@modelcontextprotocol/server-github"]
).await?;
// Use tools from different servers
let files = filesystem.call_tool("list_directory", json!({"path": "."})).await?;
let issues = github.call_tool("list_issues", json!({"repo": "hanzoai/dev"})).await?;
Ok(())
}
use hanzo_mcp_client::{McpClient, McpError};
match client.call_tool("unknown_tool", json!({})).await {
Ok(result) => println!("Success: {:?}", result),
Err(McpError::ToolNotFound(name)) => println!("Tool not found: {}", name),
Err(McpError::InvalidParams(msg)) => println!("Invalid params: {}", msg),
Err(McpError::Transport(e)) => println!("Transport error: {}", e),
Err(e) => println!("Other error: {}", e),
}
hanzo-mcp-types - MCP type definitionshanzo-protocol - Core protocol typeshanzo-zap - Zero-copy Agent Protocol (1000x faster)MIT License - Copyright 2025 Hanzo AI Inc.