#[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
| field | type | usage |
|---|---|---|
name | String | The name of the tool. If not provided, it defaults to the function name. |
description | String | A description of the tool. The document of this function will be used. |
input_schema | Expr | A 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> |
annotations | ToolAnnotationsAttribute | Additional 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
}