Skip to main content

fn_tool

Macro fn_tool 

Source
macro_rules! fn_tool {
    ($name:expr, $desc:expr, $schema:tt, $handler:expr) => { ... };
}
Expand description

Helper macro for creating tools from async functions.

§Example

use mcp::fn_tool;

let add_tool = fn_tool!(
    "add",
    "Add two numbers",
    {
        "type": "object",
        "properties": {
            "a": { "type": "number" },
            "b": { "type": "number" }
        }
    },
    |args| async move {
        let a = args["a"].as_f64().unwrap_or(0.0);
        let b = args["b"].as_f64().unwrap_or(0.0);
        Ok(vec![ToolContent::text(format!("{}", a + b))])
    }
);