Skip to main content

Module macros

Module macros 

Source
Available on crate feature macros only.
Expand description

Procedural macros for defining MCP servers and tools.

This module re-exports the macros from model-context-protocol-macros.

Use #[mcp(...)] on function parameters to add descriptions:

#[mcp_server]
impl MyServer {
    #[mcp_tool(description = "Add two numbers")]
    pub fn add(
        &self,
        #[param("First number")] a: f64,
        #[param("Second number")] b: f64,
    ) -> f64 { a + b }
}

For standalone function tools:

use mcp::macros::mcp_tool;

#[mcp_tool(description = "Add two numbers")]
fn add(#[param("First number")] a: f64, #[param("Second number")] b: f64) -> f64 {
    a + b
}

Note: #[mcp_tool] and #[param] are inert attributes processed by #[mcp_server] when used on impl blocks. For standalone functions, #[mcp_tool] generates a tool struct.

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.