Skip to main content

Crate model_context_protocol_macros

Crate model_context_protocol_macros 

Source
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
  • #[mcp_tool] - Mark a method as an MCP tool

§Example

use mcp_macros::{mcp_server, mcp_tool};

#[mcp_server(name = "memory", version = "1.0.0")]
pub struct MemoryServer {
    store: MemoryStore,
}

#[mcp_server]
impl MemoryServer {
    #[mcp_tool(description = "Store a value in memory")]
    pub fn memory_write(&self, scope: String, key: String, value: Value) -> ToolResult<String> {
        self.store.write(&scope, &key, value)
    }
}

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.