tool_param!() { /* proc-macro */ }
Expand description
Defines a parameter for a tool function with additional metadata.
This macro allows specifying parameter attributes such as:
hidden
- Excludes the parameter from the generated schemadescription
- Adds a description to the parameter in the schema
ยงExample
use mcp_core_macros::{tool, tool_param};
use mcp_core::types::ToolResponseContent;
use mcp_core::tool_text_content;
use anyhow::Result;
#[tool(name = "my_tool", description = "A tool with documented parameters")]
async fn my_tool(
// A required parameter with description
required_param: tool_param!(String, description = "A required parameter"),
// An optional parameter
optional_param: tool_param!(Option<String>, description = "An optional parameter"),
// A hidden parameter that won't appear in the schema
internal_param: tool_param!(String, hidden)
) -> Result<ToolResponseContent> {
// Implementation
Ok(tool_text_content!("Tool executed".to_string()))
}