Attribute Macro tool_router

Source
#[tool_router]
Expand description

Collects all tool methods from an impl block and generates a router.

This macro scans an impl block for methods marked with #[tool] and automatically generates registration code for them.

§Examples

#[tool_router]
impl MyServer {
    #[tool(description = "Get current time")]
    async fn get_time(&self) -> Result<String, Error> {
        Ok(chrono::Utc::now().to_string())
    }
     
    #[tool(description = "Echo message")]
    async fn echo(&self, message: String) -> Result<String, Error> {
        Ok(message)
    }
}

The macro generates:

  • A tools() method returning all tool definitions
  • A handle_tool() method for routing tool calls
  • Automatic schema generation for parameters