Expand description
Procedural macros for MCP server and tool definitions.
This crate provides macros to reduce boilerplate when defining MCP servers:
#[mcp_server]- Define server metadata and collect tools from impl blocks#[mcp_tool]- Mark a method as an MCP tool (used within#[mcp_server]impl blocks)#[param(...)]- Mark a parameter with description for the tool schema
§Example
ⓘ
use mcp::macros::mcp_server;
#[mcp_server(name = "calculator", version = "1.0.0")]
pub struct Calculator;
#[mcp_server]
impl Calculator {
#[mcp_tool("Add two numbers together")]
pub fn add(
&self,
#[param("The first number")] a: f64,
#[param("The second number")] b: f64,
) -> f64 {
a + b
}
}Note: #[mcp_tool] and #[param] are inert marker attributes processed by #[mcp_server].
They should only be used within impl blocks marked with #[mcp_server].
Attribute Macros§
- mcp_
server - Marks a struct as an MCP server or an impl block as containing MCP tools.
- mcp_
tool - Marks a method as an MCP tool.