Expand description
Unified MCP Server
This module provides a concrete MCP server implementation that aggregates multiple tools and implements the ToolProtocol trait, routing tool calls to the appropriate underlying tool implementation.
The server acts as a dispatcher that can be deployed as an HTTP service, allowing multiple agents (local or remote) to access a unified set of tools through a single ToolProtocol interface.
§Architecture
Multiple Tools (Memory, Bash, etc.)
↓
UnifiedMcpServer (implements ToolProtocol)
↓
HTTP Endpoints (GET /tools, POST /execute)
↓
Agents/Clients (via McpClientProtocol)§Example
ⓘ
use async_trait::async_trait;
use mcp::{ToolMetadata, ToolProtocol, ToolResult};
use mcp::UnifiedMcpServer;
use std::sync::Arc;
struct MemoryProtocol;
#[async_trait]
impl ToolProtocol for MemoryProtocol {
async fn execute(
&self,
_tool_name: &str,
_parameters: serde_json::Value,
) -> Result<ToolResult, Box<dyn std::error::Error + Send + Sync>> {
Ok(ToolResult::success(serde_json::json!({"ok": true})))
}
async fn list_tools(
&self,
) -> Result<Vec<ToolMetadata>, Box<dyn std::error::Error + Send + Sync>> {
Ok(vec![])
}
}
let memory_protocol = Arc::new(MemoryProtocol);
let mut server = UnifiedMcpServer::new();
server.register_tool("memory", memory_protocol).await;
// Now the server implements ToolProtocol and can route calls
let tools = server.list_tools().await.unwrap();Structs§
- Unified
McpServer - A unified MCP server that aggregates multiple tools