rust-sdk/crates/rmcp-macros
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2025-05-19 13:15:49 +08:00
..
src feat(server): add annotation to tool macro (#184) 2025-05-18 16:04:58 +08:00
Cargo.toml feat(server): add annotation to tool macro (#184) 2025-05-18 16:04:58 +08:00
README.md doc: use hierarchical readme for publishing (#198) 2025-05-19 13:15:49 +08:00

rmcp-macros

rmcp-macros is a procedural macro library for the Rust Model Context Protocol (RMCP) SDK, providing macros that facilitate the development of RMCP applications.

Features

This library primarily provides the following macros:

  • #[tool]: Used to mark functions as RMCP tools, automatically generating necessary metadata and invocation mechanisms

Usage

Tool Macro

Mark a function as a tool:

#[tool]
fn calculator(&self, #[tool(param)] a: i32, #[tool(param)] b: i32) -> Result<CallToolResult, Error> {
    // Implement tool functionality
    Ok(CallToolResult::success(vec![Content::text((a + b).to_string())]))
}

Use on an impl block to automatically register multiple tools:

#[tool(tool_box)]
impl MyHandler {
    #[tool]
    fn tool1(&self) -> Result<CallToolResult, Error> {
        // Tool 1 implementation
    }
    
    #[tool]
    fn tool2(&self) -> Result<CallToolResult, Error> {
        // Tool 2 implementation
    }
}

Advanced Features

  • Support for parameter aggregation (#[tool(aggr)])
  • Support for custom tool names and descriptions
  • Automatic generation of tool descriptions from documentation comments
  • JSON Schema generation for tool parameters

License

Please refer to the LICENSE file in the project root directory.