Repository navigation
Open
Labels
Description
Summary
Implement client-side support for Model Context Protocol, the open standard for LLM-tool integration.
Why MCP
MCP has emerged as the industry standard with adoption from OpenAI, Microsoft, Google, AWS, and Bloomberg. It was donated by Anthropic to the Agentic AI Foundation (Linux Foundation).
Benefits:
- Interoperability with entire MCP ecosystem
- Users can leverage any MCP server (databases, APIs, filesystems)
- 97M+ monthly SDK downloads
Relationship with ToolRegistry (#84)
MCP tools should integrate with the ToolRegistry from #84:
// MCP client wraps ToolRegistry
let mcp_client = McpClient::builder()
.add_server("filesystem", "npx @modelcontextprotocol/server-filesystem")
.build()
.await?;
// MCP tools get wrapped to implement our Tool trait
let mcp_tools: Vec<Box<dyn Tool>> = mcp_client.discover_tools().await?;
// Register MCP tools alongside native tools
let registry = ToolRegistry::new()
.register(Calculator::new()) // Native tool
.register_all(mcp_tools); // MCP tools
// Agents use both seamlessly via ToolSet
let agent = ReactAgent::new(ReactConfig {
tools: ToolSet::All, // Uses both native and MCP tools
..Default::default()
})?;MCP Tool Wrapper
/// Wraps an MCP tool to implement our Tool trait
struct McpToolWrapper {
server: Arc<McpServer>,
name: String,
description: String,
schema: serde_json::Value,
}
impl Tool for McpToolWrapper {
fn name(&self) -> &str { &self.name }
fn description(&self) -> &str { &self.description }
fn parameters_schema(&self) -> serde_json::Value { self.schema.clone() }
async fn execute(&self, input: serde_json::Value) -> Result<ToolOutput, ToolError> {
self.server.call_tool(&self.name, input).await
}
}Proposed API
// Connect to MCP servers
let mcp_client = McpClient::builder()
.add_server("filesystem", McpServerConfig::stdio("npx", &["@modelcontextprotocol/server-filesystem"]))
.add_server("github", McpServerConfig::stdio("mcp-server-github", &[]))
.build()
.await?;
// Discover available tools (returns Vec<Box<dyn Tool>>)
let tools = mcp_client.discover_tools().await?;
// Or integrate directly with registry
let registry = ToolRegistry::new()
.with_mcp_client(&mcp_client)
.await?;Transport Support
Phase 1: stdio (Priority)
Most common transport for local MCP servers:
pub enum McpTransport {
Stdio {
command: String,
args: Vec<String>,
env: HashMap<String, String>,
},
}Phase 2: HTTP/SSE (Future)
For remote MCP servers:
pub enum McpTransport {
Stdio { /* ... */ },
Http {
url: String,
headers: HashMap<String, String>,
},
Sse {
url: String,
headers: HashMap<String, String>,
},
}Extensibility
Use trait-based transport for future extensibility:
#[async_trait]
pub trait McpTransport: Send + Sync {
async fn connect(&mut self) -> Result<(), McpError>;
async fn send(&self, request: JsonRpcRequest) -> Result<JsonRpcResponse, McpError>;
async fn close(&mut self) -> Result<(), McpError>;
}
// Built-in implementations
pub struct StdioTransport { /* ... */ }
pub struct HttpTransport { /* ... */ } // Future
pub struct SseTransport { /* ... */ } // Future
// Users can implement custom transports
impl McpTransport for MyCustomTransport { /* ... */ }Technical Requirements
- JSON-RPC 2.0 client implementation
- stdio transport (spawn subprocess, communicate via stdin/stdout)
- Tool discovery via
tools/listmethod - Tool execution via
tools/callmethod - Graceful server lifecycle management (start/stop)
- Async operation handling (per 2025-11-25 spec)
Implementation Notes
- This is client-side MCP where gemicro connects to external MCP servers
- Different from rust-genai feat: Create gemicro-eval evaluation framework #64 which is Gemini's server-side remote MCP feature
- Depends on Built-in Tool Ecosystem: Tool trait, ToolRegistry, and core tools #84 (Tool trait and ToolRegistry) being implemented first
Priority
Low - Implement native tools (#84) first. MCP provides ecosystem access but native tools cover core use cases.
References
Related Issues
- Built-in Tool Ecosystem: Tool trait, ToolRegistry, and core tools #84 Built-in Tool Ecosystem (prerequisite - MCP wraps ToolRegistry)
- rust-genai feat: Create gemicro-eval evaluation framework #64 - Gemini's server-side remote MCP (different feature)
Activity
evansenter commentedon Dec 26, 2025
Implementation Notes (from codebase audit)
Integration approach with existing architecture:
MCP tools as Agent tools - MCP servers provide tools that can be used by ReAct (Implement ReAct agent with configurable tools #40) and other tool-using agents:
LlmClient already supports structured output - can use for tool call parsing in
gemicro-core/src/llm.rsSuggested crate structure:
Add to workspace dependencies:
Rust MCP resources:
Dependencies consideration:
evansenter commentedon Dec 26, 2025
Note: MCP integration would be especially valuable for the ReAct agent, which already has a tool-use architecture. MCP tools could be registered alongside built-in tools (calculator) to dramatically expand the agent's capabilities.
m13v commentedon Mar 18, 2026
MCP client support is a great addition. we built both an MCP server and client for our macOS agent and the main pain point was handling the different transport layers (stdio vs SSE) cleanly. having a pluggable transport interface from the start saves a lot of refactoring later. also worth implementing tool discovery caching so you don't re-fetch the tool list on every request.
m13v commentedon Mar 18, 2026
here's our MCP server implementation that handles tool discovery and transport: https://github.com/mediar-ai/terminator/blob/main/crates/terminator-mcp-agent/src/server.rs
and the client-side provider that manages connections to multiple MCP backends: https://github.com/m13v/fazm/blob/main/Desktop/Sources/Providers/ChatProvider.swift