Skip to content

Commit e73038a

Browse files
committed
fix(docs): use correct Parameters<T> syntax in tool examples
The README examples used `#[tool(param)]` on function parameters, which is not a supported syntax and fails to compile. Replace with the `Parameters<T>` wrapper pattern that the macros actually expect. Closes #812
1 parent 020a38b commit e73038a

2 files changed

Lines changed: 32 additions & 8 deletions

File tree

README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,21 @@ Tools let servers expose callable functions to clients. Each tool has a name, de
141141
The `#[tool]`, `#[tool_router]`, and `#[tool_handler]` macros handle all the wiring. For a tools-only server you can use `#[tool_router(server_handler)]` to skip the separate `ServerHandler` impl:
142142

143143
```rust,ignore
144-
use rmcp::{tool, tool_router, ServiceExt, transport::stdio};
144+
use rmcp::{handler::server::wrapper::Parameters, schemars, tool, tool_router, ServiceExt, transport::stdio};
145+
146+
#[derive(Debug, serde::Deserialize, schemars::JsonSchema)]
147+
struct AddParams {
148+
a: i32,
149+
b: i32,
150+
}
145151
146152
#[derive(Clone)]
147153
struct Calculator;
148154
149155
#[tool_router(server_handler)]
150156
impl Calculator {
151157
#[tool(description = "Add two numbers")]
152-
fn add(&self, #[tool(param)] a: i32, #[tool(param)] b: i32) -> String {
158+
fn add(&self, Parameters(AddParams { a, b }): Parameters<AddParams>) -> String {
153159
(a + b).to_string()
154160
}
155161
}
@@ -165,15 +171,21 @@ async fn main() -> anyhow::Result<()> {
165171
When you need custom server metadata or multiple capabilities (tools + prompts), use explicit `#[tool_handler]`:
166172

167173
```rust,ignore
168-
use rmcp::{tool, tool_router, tool_handler, ServerHandler, ServiceExt};
174+
use rmcp::{handler::server::wrapper::Parameters, schemars, tool, tool_router, tool_handler, ServerHandler, ServiceExt};
175+
176+
#[derive(Debug, serde::Deserialize, schemars::JsonSchema)]
177+
struct AddParams {
178+
a: i32,
179+
b: i32,
180+
}
169181
170182
#[derive(Clone)]
171183
struct Calculator;
172184
173185
#[tool_router]
174186
impl Calculator {
175187
#[tool(description = "Add two numbers")]
176-
fn add(&self, #[tool(param)] a: i32, #[tool(param)] b: i32) -> String {
188+
fn add(&self, Parameters(AddParams { a, b }): Parameters<AddParams>) -> String {
177189
(a + b).to_string()
178190
}
179191
}

docs/readme/README.zh-cn.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,21 @@ let quit_reason = server.cancel().await?;
141141
`#[tool]``#[tool_router]``#[tool_handler]` 宏负责所有连接工作。对于纯工具服务端,可以使用 `#[tool_router(server_handler)]` 来省略单独的 `ServerHandler` 实现:
142142

143143
```rust,ignore
144-
use rmcp::{tool, tool_router, ServiceExt, transport::stdio};
144+
use rmcp::{handler::server::wrapper::Parameters, schemars, tool, tool_router, ServiceExt, transport::stdio};
145+
146+
#[derive(Debug, serde::Deserialize, schemars::JsonSchema)]
147+
struct AddParams {
148+
a: i32,
149+
b: i32,
150+
}
145151
146152
#[derive(Clone)]
147153
struct Calculator;
148154
149155
#[tool_router(server_handler)]
150156
impl Calculator {
151157
#[tool(description = "Add two numbers")]
152-
fn add(&self, #[tool(param)] a: i32, #[tool(param)] b: i32) -> String {
158+
fn add(&self, Parameters(AddParams { a, b }): Parameters<AddParams>) -> String {
153159
(a + b).to_string()
154160
}
155161
}
@@ -165,15 +171,21 @@ async fn main() -> anyhow::Result<()> {
165171
当需要自定义服务端元数据或多种能力(工具 + 提示词)时,使用显式的 `#[tool_handler]`
166172

167173
```rust,ignore
168-
use rmcp::{tool, tool_router, tool_handler, ServerHandler, ServiceExt};
174+
use rmcp::{handler::server::wrapper::Parameters, schemars, tool, tool_router, tool_handler, ServerHandler, ServiceExt};
175+
176+
#[derive(Debug, serde::Deserialize, schemars::JsonSchema)]
177+
struct AddParams {
178+
a: i32,
179+
b: i32,
180+
}
169181
170182
#[derive(Clone)]
171183
struct Calculator;
172184
173185
#[tool_router]
174186
impl Calculator {
175187
#[tool(description = "Add two numbers")]
176-
fn add(&self, #[tool(param)] a: i32, #[tool(param)] b: i32) -> String {
188+
fn add(&self, Parameters(AddParams { a, b }): Parameters<AddParams>) -> String {
177189
(a + b).to_string()
178190
}
179191
}

0 commit comments

Comments
 (0)