pub struct Tool {
pub name: String,
pub title: Option<String>,
pub description: Option<String>,
pub input_schema: ToolInputSchema,
pub output_schema: Option<ToolOutputSchema>,
pub annotations: Option<ToolAnnotations>,
pub meta: Option<HashMap<String, Value>>,
}Expand description
Represents a tool that can be executed by an MCP server, as per the MCP 2025-06-18 specification.
A Tool definition includes its programmatic name, a human-readable description,
and JSON schemas for its inputs and outputs.
Fields§
§name: StringThe programmatic name of the tool, used to identify it in CallToolRequest.
title: Option<String>An optional, user-friendly title for the tool. Display name precedence is: title, annotations.title, then name.
description: Option<String>A human-readable description of what the tool does, which can be used by clients or LLMs.
input_schema: ToolInputSchemaThe JSON Schema object defining the parameters the tool accepts.
output_schema: Option<ToolOutputSchema>An optional JSON Schema object defining the structure of the tool’s successful output.
annotations: Option<ToolAnnotations>Optional, additional metadata providing hints about the tool’s behavior.
meta: Option<HashMap<String, Value>>A general-purpose metadata field for custom data.
Implementations§
Source§impl Tool
impl Tool
Sourcepub fn new(name: impl Into<String>) -> Self
pub fn new(name: impl Into<String>) -> Self
Creates a new Tool with a given name.
§Panics
Panics if the name is empty or contains only whitespace.
Sourcepub fn with_description(
name: impl Into<String>,
description: impl Into<String>,
) -> Self
pub fn with_description( name: impl Into<String>, description: impl Into<String>, ) -> Self
Creates a new Tool with a name and a description.
§Panics
Panics if the name is empty or contains only whitespace.
Sourcepub fn with_input_schema(self, schema: ToolInputSchema) -> Self
pub fn with_input_schema(self, schema: ToolInputSchema) -> Self
Sets the input schema for this tool.
§Example
let schema = ToolInputSchema::empty();
let tool = Tool::new("my_tool").with_input_schema(schema);Sourcepub fn with_output_schema(self, schema: ToolOutputSchema) -> Self
pub fn with_output_schema(self, schema: ToolOutputSchema) -> Self
Sets the output schema for this tool.
Sourcepub fn with_title(self, title: impl Into<String>) -> Self
pub fn with_title(self, title: impl Into<String>) -> Self
Sets the user-friendly title for this tool.
Sourcepub fn with_annotations(self, annotations: ToolAnnotations) -> Self
pub fn with_annotations(self, annotations: ToolAnnotations) -> Self
Sets the annotations for this tool.