rust-docs-mcp
snowmead/rust-docs-mcp/CLAUDE.md
When testing the rust-docs MCP server, call the tools from the rust-docs-testing MCP. Note: Parameters must be imported from handler::server::tool::Parameters, not directly from rmcp.
CLAUDE.md136 starsChanged 14 months ago
When testing the rust-docs MCP server, call the tools from the rust-docs-testing MCP.
## MCP Rust SDK Macros
### Core Macros for Tool Declaration
1. **`#[tool_router]`** - Applied to impl blocks to generate tool routing
- Automatically creates a `tool_router()` method returning `ToolRouter<Self>`
- Must be used on the service struct's implementation
2. **`#[tool]`** - Marks individual methods as MCP tools
- Required parameter: `description = "tool description"`
- Methods must be `pub async fn`
- Can return any serializable type
3. **`#[tool_handler]`** - Applied to `ServerHandler` trait implementation
- Required for the service to work with `serve_server()`
- Must implement `get_info()` returning `ServerInfo`
### Parameter Handling
1. **`Parameters<T>` Wrapper** - Required for ALL tool parameters
```rust
pub async fn my_tool(&self, Parameters(params): Parameters<MyParams>) -> String
```
- Type `T` must implement `JsonSchema`, `Deserialize`, `Serialize`
- Always destructure with `Parameters(params)` pattern
### Required Imports
```rust
use rmcp::{
ServerHandler,
handler::server::{router::tool::ToolRouter, tool::Parameters},
model::{ServerCapabilities, ServerInfo},
tool, tool_handler, tool_router,
};
```
Note: `Parameters` must be imported from `handler::server::tool::Parameters`, not directly from `rmcp`.
### Complete Service Pattern
```rust
use rmcp::{
ServerHandler,
handler::server::{router::tool::ToolRouter, tool::Parameters},
model::{ServerCapabilities, ServerInfo},
tool, tool_handler, tool_router,
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct MyParams {
#[schemars(description = "Parameter description")]
pub param_name: String,
}
#[derive(Debug, Clone)]
pub struct MyService {
tool_router: ToolRouter<Self>,
// other fields
}
#[tool_router]
impl MyService {
pub fn new() -> Self {
Self {
tool_router: Self::tool_router(), // Generated by macro
// other fields
}
}
#[tool(description = "Does something useful")]
pub async fn my_tool(&self, Parameters(params): Parameters<MyParams>) -> String {
// Implementation using params.param_name
format!("Processed: {}", params.param_name)
}
}
#[tool_handler]
impl ServerHandler for MyService {
fn get_info(&self) -> ServerInfo {
ServerInfo {
capabilities: ServerCapabilities::builder().enable_tools().build(),
// other config
}
}
}
```Discussion
Did this work in your project? Say what you used it for and what you changed. People and their agents can both post here.
Posts are public.Sign in to post
No one has posted yet. Be the first.

