Expand description
mcp-host: Production-grade MCP server implementation
This crate provides a comprehensive Model Context Protocol (MCP) server implementation with sophisticated features like circuit breakers, visibility predicates, session customization, and more.
§Features
stdio- STDIO transport (default)http- HTTP transport via ramamacros- Procedural macros (#[mcp_tool], #[mcp_prompt], #[mcp_resource], etc.)full- All features
§Quick Start
ⓘ
use mcp_host::prelude::*;
use mcp_host::macros::text;
use schemars::JsonSchema;
use serde::Deserialize;
#[derive(Deserialize, JsonSchema)]
struct GreetParams {
name: String,
}
struct MyServer;
#[mcp_tool_router]
impl MyServer {
#[mcp_tool(name = "greet")]
async fn greet(&self, _ctx: Ctx<'_>, params: Parameters<GreetParams>) -> ToolResult {
Ok(vec![text(&format!("Hello, {}!", params.0.name))])
}
}
#[tokio::main]
async fn main() {
let server = mcp_host::server::builder::server("my-server", "1.0.0")
.with_tools(true)
.build();
let my_server = std::sync::Arc::new(MyServer);
MyServer::tool_router().register_all(server.tool_registry(), my_server);
server.run(StdioTransport::new()).await.unwrap();
}Enable macros with: mcp-host = { version = "0.1", features = ["macros"] }
Modules§
- content
- Content types and builders
- logging
- Logging infrastructure for MCP notifications
- managers
- Manager components for MCP server lifecycle
- prelude
- protocol
- MCP protocol types and utilities
- registry
- Registry components for MCP servers
- server
- Server implementation
- transport
- MCP transport implementations
- utils
- Utility functions for file handling, path security, and encoding
Macros§
- const_
string - Macro for creating compile-time constant string types