Expand description
mcp-host: Production-grade MCP server implementation
This crate provides a comprehensive Model Context Protocol (MCP) server implementation with sophisticated features like middleware chains, task management, progress tracking, and more.
§Quick Start
ⓘ
use mcp_host::prelude::*;
use async_trait::async_trait;
struct MyTool;
#[async_trait]
impl Tool for MyTool {
fn name(&self) -> &str { "my_tool" }
fn input_schema(&self) -> serde_json::Value {
serde_json::json!({
"type": "object",
"properties": {
"input": { "type": "string" }
}
})
}
async fn execute(&self, ctx: ExecutionContext<'_>) -> Result<Vec<Box<dyn Content>>, ToolError> {
Ok(vec![Box::new(TextContent::new("Hello!"))])
}
}§Derive Macros (Recommended)
When using the macros feature, you can use procedural derive macros for reduced boilerplate:
ⓘ
use mcp_host::prelude::*;
#[derive(McpTool)]
#[mcp(name = "my_tool", description = "Does something useful")]
struct MyTool {
#[mcp(skip)]
state: SomeInternalState, // Not included in schema
input: String, // Included in schema
}
// User must implement execute manually
impl MyTool {
async fn run(&self, ctx: ExecutionContext<'_>) -> Result<Vec<Box<dyn Content>>, ToolError> {
Ok(vec![Box::new(TextContent::new(&self.input))])
}
}Enable derive macros with: mcp-host = { version = "0.1", features = ["macros"] }
Modules§
- content
- Content types and builders
- logging
- Logging infrastructure for MCP notifications
- managers
- Manager components TODO: Phase 4
- prelude
- protocol
- MCP protocol types and utilities
- registry
- Registry components TODO: Phase 5
- 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