mcpkit-macros 0.2.0

Procedural macros for mcpkit
Documentation

Procedural macros for the MCP SDK.

This crate provides the unified #[mcp_server] macro that simplifies MCP server development.

Overview

The macro system provides:

  • #[mcp_server] - Transform an impl block into a full MCP server
  • #[tool] - Mark a method as an MCP tool
  • #[resource] - Mark a method as an MCP resource handler
  • #[prompt] - Mark a method as an MCP prompt handler

Example

use mcp::prelude::*;

struct Calculator;

#[mcp_server(name = "calculator", version = "1.0.0")]
impl Calculator {
    /// Add two numbers together
    #[tool(description = "Add two numbers")]
    async fn add(&self, a: f64, b: f64) -> ToolOutput {
        ToolOutput::text((a + b).to_string())
    }

    /// Multiply two numbers
    #[tool(description = "Multiply two numbers")]
    async fn multiply(&self, a: f64, b: f64) -> ToolOutput {
        ToolOutput::text((a * b).to_string())
    }
}

#[tokio::main]
async fn main() -> Result<(), McpError> {
    Calculator.serve_stdio().await
}

Code Reduction

This single macro replaces 4 separate macros:

  • #[derive(Clone)] with manual router field
  • #[tool_router]
  • #[tool_handler]
  • Manual new() constructor

Result: Reduced boilerplate code.