mcp_tool

Attribute Macro mcp_tool 

Source
#[mcp_tool]
Expand description

Automatically generates MCP tool definitions from Rust functions.

This macro transforms regular Rust functions into MCP tools with automatic JSON schema generation, parameter validation, and error handling.

§Basic Usage

use pulseengine_mcp_macros::mcp_tool;

#[mcp_tool]
async fn say_hello(name: String) -> String {
    format!("Hello, {}!", name)
}

§With Custom Description

#[mcp_tool(description = "Say hello to someone or something")]
async fn say_hello(name: String, greeting: Option<String>) -> String {
    format!("{}, {}!", greeting.unwrap_or("Hello"), name)
}

§Parameters

  • description: Optional custom description (defaults to doc comments)
  • name: Optional custom tool name (defaults to function name)

§Features

  • Automatic Schema: JSON schemas generated from Rust parameter types
  • Doc Comments: Function documentation becomes tool description
  • Type Safety: Compile-time validation of parameters
  • Error Handling: Automatic conversion of Result types
  • Async Support: Both sync and async functions supported