Skip to content

Commit 9734e79

Browse files
committed
chore: update readme
1 parent 77603cf commit 9734e79

File tree

3 files changed

+235
-7
lines changed

3 files changed

+235
-7
lines changed

README.md

Lines changed: 116 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ This project supports following transports:
3838
- ✅ Batch Messages
3939
- ✅ Streaming & non-streaming JSON response
4040
- ✅ Streamable HTTP Support for MCP Clients
41-
- Resumability
42-
-Authentication / Oauth
41+
- Resumability
42+
- ⬜ Oauth Authentication
4343

4444
**⚠️** Project is currently under development and should be used at your own risk.
4545

@@ -50,6 +50,7 @@ This project supports following transports:
5050
- [MCP Client (stdio)](#mcp-client-stdio)
5151
- [MCP Client (Streamable HTTP)](#mcp-client_streamable-http))
5252
- [MCP Client (sse)](#mcp-client-sse)
53+
- [Macros](#macros)
5354
- [Getting Started](#getting-started)
5455
- [HyperServerOptions](#hyperserveroptions)
5556
- [Security Considerations](#security-considerations)
@@ -386,6 +387,114 @@ Creating an MCP client using the `rust-mcp-sdk` with the SSE transport is almost
386387
👉 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.
387388

388389

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."),
408+
destructive_hint = false,
409+
idempotent_hint = false,
410+
open_world_hint = false,
411+
read_only_hint = false
412+
)]
413+
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug, JsonSchema)]
414+
pub struct MoveFileTool {
415+
/// The source path of the file to move.
416+
pub source: String,
417+
/// The destination path to move the file to.
418+
pub destination: String,
419+
}
420+
421+
// Now we can call `tool()` method on it to get a Tool instance
422+
let rust_mcp_sdk::schema::Tool = MoveFileTool::tool();
423+
424+
```
425+
426+
💻 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`,
439+
// where each tool becomes a variant of the enum.
440+
tool_box!(FileSystemTools, [ReadFileTool, MoveFileTool, SearchFilesTool]);
441+
442+
// now in the app, we can use the FileSystemTools, like:
443+
let all_tools: Vec<Tool> = FileSystemTools::tools();
444+
```
445+
446+
💻 To see a real-world example of that please see :
447+
- `tool_box` macro usage: [https://github.com/rust-mcp-stack/rust-mcp-filesystem/blob/main/src/tools.rs](https://github.com/rust-mcp-stack/rust-mcp-filesystem/blob/main/src/tools.rs)
448+
- 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
467+
#[mcp_elicit(message = "Please enter your info")]
468+
#[derive(JsonSchema)]
469+
pub struct UserInfo {
470+
#[json_schema(
471+
title = "Name",
472+
description = "The user's full name",
473+
min_length = 5,
474+
max_length = 100
475+
)]
476+
pub name: String,
477+
/// Is user a student?
478+
#[json_schema(title = "Is student?", default = true)]
479+
pub is_student: Option<bool>,
480+
481+
/// User's favorite color
482+
pub favorate_color: Colors,
483+
}
484+
485+
// send a Elicit Request , ask for UserInfo data and convert the result back to a valid UserInfo instance
486+
let result: ElicitResult = server
487+
.elicit_input(UserInfo::message(), UserInfo::requested_schema())
488+
.await?;
489+
490+
// Create a UserInfo instance using data provided by the user on the client side
491+
let user_info = UserInfo::from_content_map(result.content)?;
492+
493+
```
494+
495+
💻 For mre info please see :
496+
- https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/crates/rust-mcp-macros
497+
389498
## Getting Started
390499

391500
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)
@@ -612,6 +721,7 @@ Below is a list of projects that utilize the `rust-mcp-sdk`, showcasing their na
612721
| <a href="https://rust-mcp-stack.github.io/mcp-discovery"><img src="https://raw.githubusercontent.com/rust-mcp-stack/mcp-discovery/refs/heads/main/docs/_media/mcp-discovery-logo.png" width="64"/></a> | [MCP Discovery](https://rust-mcp-stack.github.io/mcp-discovery) | A lightweight command-line tool for discovering and documenting MCP Server capabilities. | [GitHub](https://github.com/rust-mcp-stack/mcp-discovery) |
613722
| <a href="https://github.com/EricLBuehler/mistral.rs"><img src="https://avatars.githubusercontent.com/u/65165915?s=64" width="64"/></a> | [mistral.rs](https://github.com/EricLBuehler/mistral.rs) | Blazingly fast LLM inference. | [GitHub](https://github.com/EricLBuehler/mistral.rs) |
614723
| <a href="https://github.com/moonrepo/moon"><img src="https://avatars.githubusercontent.com/u/102833400?s=64" width="64"/></a> | [moon](https://github.com/moonrepo/moon) | moon is a repository management, organization, orchestration, and notification tool for the web ecosystem, written in Rust. | [GitHub](https://github.com/moonrepo/moon) |
724+
| <a href="https://github.com/LepistaBioinformatics/mycelium"><img src="https://avatars.githubusercontent.com/u/79392252?s=64" width="64"/></a> | [mycelium](https://github.com/LepistaBioinformatics/mycelium) | `mycelium` is a modern, open-source platform for secure, flexible, and scalable API management. | [GitHub](https://github.com/LepistaBioinformatics/mycelium) |
615725
| <a href="https://github.com/angreal/angreal"><img src="https://avatars.githubusercontent.com/u/45580675?s=64" width="64"/></a> | [angreal](https://github.com/angreal/angreal) | Angreal provides a way to template the structure of projects and a way of executing methods for interacting with that project in a consistent manner. | [GitHub](https://github.com/angreal/angreal) |
616726
| <a href="https://github.com/FalkorDB/text-to-cypher"><img src="https://avatars.githubusercontent.com/u/140048192?s=64" width="64"/></a> | [text-to-cypher](https://github.com/FalkorDB/text-to-cypher) | A high-performance Rust-based API service that translates natural language text to Cypher queries for graph databases. | [GitHub](https://github.com/FalkorDB/text-to-cypher) |
617727
| <a href="https://github.com/Tuurlijk/notify-mcp"><img src="https://avatars.githubusercontent.com/u/790979?s=64" width="64"/></a> | [notify-mcp](https://github.com/Tuurlijk/notify-mcp) | A Model Context Protocol (MCP) server that provides desktop notification functionality. | [GitHub](https://github.com/Tuurlijk/notify-mcp) |
@@ -622,6 +732,10 @@ Below is a list of projects that utilize the `rust-mcp-sdk`, showcasing their na
622732

623733

624734

735+
736+
737+
738+
625739
## Contributing
626740

627741
We welcome everyone who wishes to contribute! Please refer to the [contributing](CONTRIBUTING.md) guidelines for more details.

crates/rust-mcp-macros/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ fn main() {
9999

100100
## mcp_elicit Macro
101101

102-
The `mcp_elicit` macro generates an implementation for the annotated struct to facilitate data elicitation into a `rust_mcp_schema::Tool` instance. It enables parsing a map of field names to `ElicitResultContentValue` values into the struct, supporting both required and optional fields. The generated implementation includes:
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:
103103

104104
- A `message()` method returning the elicitation message as a string.
105-
- A `requested_schema()` method returning an `ElicitRequestParamsRequestedSchema` based on the struct’s JSON schema.
105+
- A `requested_schema()` method returning an `ElicitRequestedSchema` based on the struct’s JSON schema.
106106
- A `from_content_map()` method to convert a map of `ElicitResultContentValue` values into a struct instance.
107107

108108
### Attributes

0 commit comments

Comments
 (0)