MCP Integration
The traitclaw-mcp crate implements the Model Context Protocol client, enabling your agent to discover and use tools from MCP servers.
Quick Start
Section titled “Quick Start”use traitclaw_mcp::{McpServer, McpToolRegistry};
// Connect to an MCP server via stdiolet server = McpServer::stdio("npx", &["-y", "@mcp/server-filesystem", "."]).await?;
// Convert MCP tools to TraitClaw toolslet registry = McpToolRegistry::from_server(server).await?;
let agent = Agent::builder() .provider(provider) .tool_registry(registry) .build()?;
// The agent can now use all tools from the MCP server!Multi-Server
Section titled “Multi-Server”use traitclaw_mcp::MultiServerMcpRegistry;
let registry = MultiServerMcpRegistry::new() .add_server("fs", McpServer::stdio("npx", &["-y", "@mcp/server-filesystem", "."]).await?) .add_server("db", McpServer::stdio("npx", &["-y", "@mcp/server-postgres", db_url]).await?) .build() .await?;