You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: crates/rmcp-macros/README.md
+20-1Lines changed: 20 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ For **getting started** and **full MCP feature documentation**, see the [main RE
20
20
| Macro | Description |
21
21
|-------|-------------|
22
22
|[`#[tool]`][tool]| Mark a function as an MCP tool handler |
23
-
|[`#[tool_router]`][tool_router]| Generate a tool router from an impl block |
23
+
|[`#[tool_router]`][tool_router]| Generate a tool router from an impl block (optional `server_handler` flag elides a separate `#[tool_handler]` block for tools-only servers) |
24
24
|[`#[tool_handler]`][tool_handler]| Generate `call_tool` and `list_tools` handler methods |
25
25
|[`#[prompt]`][prompt]| Mark a function as an MCP prompt handler |
26
26
|[`#[prompt_router]`][prompt_router]| Generate a prompt router from an impl block |
@@ -37,6 +37,25 @@ For **getting started** and **full MCP feature documentation**, see the [main RE
37
37
38
38
## Quick Example
39
39
40
+
Tools-only server with a single `impl` block (`server_handler` expands `#[tool_handler]` in a second macro pass):
41
+
42
+
```rust,ignore
43
+
use rmcp::{tool, tool_router};
44
+
45
+
#[derive(Clone)]
46
+
struct MyServer;
47
+
48
+
#[tool_router(server_handler)]
49
+
impl MyServer {
50
+
#[tool(description = "Say hello")]
51
+
async fn hello(&self) -> String {
52
+
"Hello, world!".into()
53
+
}
54
+
}
55
+
```
56
+
57
+
If you need custom `#[tool_handler(...)]` arguments (e.g. `instructions`, `name`, or stacked `#[prompt_handler]` on the same `impl ServerHandler`), use two blocks instead:
58
+
40
59
```rust,ignore
41
60
use rmcp::{tool, tool_router, tool_handler, ServerHandler};
/// | `router` | `Ident` | The name of the router function to be generated. Defaults to `tool_router`. |
58
-
/// | `vis` | `Visibility` | The visibility of the generated router function. Defaults to empty. |
55
+
/// | field | type | usage |
56
+
/// | :- | :- | :- |
57
+
/// | `router` | `Ident` | The name of the router function to be generated. Defaults to `tool_router`. |
58
+
/// | `vis` | `Visibility` | The visibility of the generated router function. Defaults to empty. |
59
+
/// | `server_handler` | `flag` | When set, also emits `#[::rmcp::tool_handler]` on `impl ServerHandler for Self` so you can omit a separate `#[tool_handler]` block. |
0 commit comments