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
@@ -386,6 +387,114 @@ Creating an MCP client using the `rust-mcp-sdk` with the SSE transport is almost
386
387
👉 see [examples/simple-mcp-client-sse](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/examples/simple-mcp-client-sse) for a complete working example.
387
388
388
389
390
+
## Macros
391
+
[rust-mcp-sdk](https://github.com/rust-mcp-stack/rust-mcp-sdk) includes several helpful macros that simplify common tasks when building MCP servers and clients. For example, they can automatically generate tool specifications and tool schemas right from your structs, or assist with elicitation requests and responses making them completely type safe.
392
+
393
+
> To use these macros, ensure the `macros` feature is enabled in your Cargo.toml.
394
+
395
+
### mcp_tool
396
+
`mcp_tool` is a procedural macro attribute that helps generating rust_mcp_schema::Tool from a struct.
397
+
398
+
Usage example:
399
+
```rust
400
+
#[mcp_tool(
401
+
name ="move_file",
402
+
title="Move File",
403
+
description = concat!("Move or rename files and directories. Can move files between directories ",
404
+
"and rename them in a single operation. If the destination exists, the ",
405
+
"operation will fail. Works across different directories and can be used ",
406
+
"for simple renaming within the same directory. ",
407
+
"Both source and destination must be within allowed directories."),
💻 For a real-world example, check out any of the tools available at: https://github.com/rust-mcp-stack/rust-mcp-filesystem/tree/main/src/tools
427
+
428
+
429
+
### tool_box
430
+
`tool_box` generates an enum from a provided list of tools, making it easier to organize and manage them, especially when your application includes a large number of tools.
431
+
432
+
It accepts an array of tools and generates an enum where each tool becomes a variant of the enum.
433
+
434
+
Generated enum has a `tools()` function that returns a `Vec<Tool>` , and a `TryFrom<CallToolRequestParams>` trait implementation that could be used to convert a ToolRequest into a Tool instance.
435
+
436
+
Usage example:
437
+
```rust
438
+
// Accepts an array of tools and generates an enum named `FileSystemTools`,
- using `tools()` in list tools request : [https://github.com/rust-mcp-stack/rust-mcp-filesystem/blob/main/src/handler.rs](https://github.com/rust-mcp-stack/rust-mcp-filesystem/blob/main/src/handler.rs#L67)
449
+
- using `try_from` in call tool_request: [https://github.com/rust-mcp-stack/rust-mcp-filesystem/blob/main/src/handler.rs](https://github.com/rust-mcp-stack/rust-mcp-filesystem/blob/main/src/handler.rs#L100)
450
+
451
+
452
+
453
+
### mcp_elicit
454
+
The `mcp_elicit` macro generates implementations for the annotated struct to facilitate data elicitation. It enables struct to generate `ElicitRequestedSchema` and also parsing a map of field names to `ElicitResultContentValue` values back into the struct, supporting both required and optional fields. The generated implementation includes:
455
+
456
+
- A `message()` method returning the elicitation message as a string.
457
+
- A `requested_schema()` method returning an `ElicitRequestedSchema` based on the struct’s JSON schema.
458
+
- A `from_content_map()` method to convert a map of `ElicitResultContentValue` values into a struct instance.
459
+
460
+
### Attributes
461
+
462
+
-`message` - An optional string (or `concat!(...)` expression) to prompt the user or system for input. Defaults to an empty string if not provided.
463
+
464
+
Usage example:
465
+
```rust
466
+
// A struct that could be used to send elicit request and get the input from the user
If you are looking for a step-by-step tutorial on how to get started with `rust-mcp-sdk` , please see : [Getting Started MCP Server](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/doc/getting-started-mcp-server.md)
@@ -509,6 +618,7 @@ The `rust-mcp-sdk` crate provides several features that can be enabled or disabl
509
618
-`stdio`: Enables support for the `standard input/output (stdio)` transport.
510
619
-`tls-no-provider`: Enables TLS without a crypto provider. This is useful if you are already using a different crypto provider than the aws-lc default.
511
620
621
+
512
622
#### MCP Protocol Versions with Corresponding Features
513
623
514
624
-`2025_06_18` : Activates MCP Protocol version 2025-06-18 (enabled by default)
@@ -621,6 +731,10 @@ Below is a list of projects that utilize the `rust-mcp-sdk`, showcasing their na
621
731
622
732
623
733
734
+
735
+
736
+
737
+
624
738
## Contributing
625
739
626
740
We welcome everyone who wishes to contribute! Please refer to the [contributing](CONTRIBUTING.md) guidelines for more details.
Copy file name to clipboardExpand all lines: crates/rust-mcp-macros/README.md
+106-4Lines changed: 106 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,8 @@
1
1
# rust-mcp-macros.
2
2
3
+
4
+
## mcp_tool Macro
5
+
3
6
A procedural macro, part of the [rust-mcp-sdk](https://github.com/rust-mcp-stack/rust-mcp-sdk) ecosystem, to generate `rust_mcp_schema::Tool` instance from a struct.
4
7
5
8
The `mcp_tool` macro generates an implementation for the annotated struct that includes:
@@ -80,11 +83,7 @@ fn main() {
80
83
81
84
```
82
85
83
-
---
84
86
85
-
<imgalign="top"src="assets/rust-mcp-stack-icon.png"width="24"style="border-radius:0.2rem;"> Check out [rust-mcp-sdk](https://github.com/rust-mcp-stack/rust-mcp-sdk) , a high-performance, asynchronous toolkit for building MCP servers and clients. Focus on your app's logic while [rust-mcp-sdk](https://github.com/rust-mcp-stack/rust-mcp-sdk) takes care of the rest!
86
-
87
-
---
88
87
89
88
90
89
**Note**: The following attributes are available only in version `2025_03_26` and later of the MCP Schema, and their values will be used in the [annotations](https://github.com/rust-mcp-stack/rust-mcp-schema/blob/main/src/generated_schema/2025_03_26/mcp_schema.rs#L5557) attribute of the *[Tool struct](https://github.com/rust-mcp-stack/rust-mcp-schema/blob/main/src/generated_schema/2025_03_26/mcp_schema.rs#L5554-L5566).
@@ -93,3 +92,106 @@ fn main() {
93
92
-`idempotent_hint`
94
93
-`open_world_hint`
95
94
-`read_only_hint`
95
+
96
+
97
+
98
+
99
+
100
+
## mcp_elicit Macro
101
+
102
+
The `mcp_elicit` macro generates implementations for the annotated struct to facilitate data elicitation. It enables struct to generate `ElicitRequestedSchema` and also parsing a map of field names to `ElicitResultContentValue` values back into the struct, supporting both required and optional fields. The generated implementation includes:
103
+
104
+
- A `message()` method returning the elicitation message as a string.
105
+
- A `requested_schema()` method returning an `ElicitRequestedSchema` based on the struct’s JSON schema.
106
+
- A `from_content_map()` method to convert a map of `ElicitResultContentValue` values into a struct instance.
107
+
108
+
### Attributes
109
+
110
+
-`message` - An optional string (or `concat!(...)` expression) to prompt the user or system for input. Defaults to an empty string if not provided.
111
+
112
+
### Supported Field Types
113
+
114
+
-`String`: Maps to `ElicitResultContentValue::String`.
115
+
-`bool`: Maps to `ElicitResultContentValue::Boolean`.
116
+
-`i32`: Maps to `ElicitResultContentValue::Integer` (with bounds checking).
117
+
-`i64`: Maps to `ElicitResultContentValue::Integer`.
118
+
-`enum` Only simple enums are supported. The enum must implement the FromStr trait.
119
+
-`Option<T>`: Supported for any of the above types, mapping to `None` if the field is missing.
<imgalign="top"src="assets/rust-mcp-stack-icon.png"width="24"style="border-radius:0.2rem;"> Check out [rust-mcp-sdk](https://github.com/rust-mcp-stack/rust-mcp-sdk), a high-performance, asynchronous toolkit for building MCP servers and clients. Focus on your app's logic while [rust-mcp-sdk](https://github.com/rust-mcp-stack/rust-mcp-sdk) takes care of the rest!
0 commit comments