Skip to main content

tool

Attribute Macro tool 

Source
#[tool]
Available on crate features macros and server only.
Expand description

§tool

This macro is used to mark a function as a tool handler.

This will generate a function that return the attribute of this tool, with type rmcp::model::Tool.

§Usage

fieldtypeusage
nameStringThe name of the tool. If not provided, it defaults to the function name.
descriptionStringA description of the tool. The document of this function will be used.
input_schemaExprA JSON Schema object defining the expected parameters for the tool. If not provide, if will use the json schema of its argument with type Parameters<T>
annotationsToolAnnotationsAttributeAdditional tool information. Defaults to None.

§Example

#[tool(name = "my_tool", description = "This is my tool", annotations(title = "我的工具", read_only_hint = true))]
pub async fn my_tool(param: Parameters<MyToolParam>) {
    // handling tool request
}