Skip to main content

mcp_server

Attribute Macro mcp_server 

Source
#[mcp_server]
Available on crate feature macros only.
Expand description

Marks a struct as an MCP server or an impl block as containing MCP tools.

When applied to a struct, it adds server name and version metadata. When applied to an impl block, it processes methods marked with #[mcp_tool] and generates the MacroServer trait implementation.

§On Structs

#[mcp_server(name = "my-server", version = "1.0.0")]
pub struct MyServer { ... }

§On Impl Blocks

#[mcp_server]
impl MyServer {
    #[mcp_tool(description = "Tool description")]
    pub fn my_tool(
        &self,
        #[param("Parameter description")] param: String,
    ) -> Result<String, String> { ... }
}

§Parameter Attributes

Within #[mcp_tool] methods, use #[param(...)] on parameters:

Shorthand (recommended):

  • #[param("description")] - Just the description

Full form:

  • #[param(description = "...", name = "...", required = true)]

Options:

  • description - Description shown to the LLM
  • name - Custom parameter name override (optional)
  • required - Override required/optional inference (optional)

All non-self parameters must have #[param(...)] - unmarked parameters cause compile errors.