#[non_exhaustive]pub struct ToolInfo {
pub name: String,
pub title: Option<String>,
pub description: Option<String>,
pub input_schema: Value,
pub output_schema: Option<Value>,
pub annotations: Option<ToolAnnotations>,
pub icons: Option<Vec<IconInfo>>,
pub _meta: Option<Map<String, Value>>,
pub execution: Option<ToolExecution>,
}Expand description
Tool information.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.name: StringTool name (unique identifier)
title: Option<String>Optional human-readable title (MCP 2025-11-25)
description: Option<String>Human-readable description
input_schema: ValueJSON Schema for tool parameters
output_schema: Option<Value>JSON Schema for the tool’s output type (MCP spec 2025-06-18).
When present, clients can validate and type-check the tool’s structured
output. Code generators can create typed return structs instead of
falling back to serde_json::Value.
annotations: Option<ToolAnnotations>Tool annotations (hints and PMCP extensions)
icons: Option<Vec<IconInfo>>Optional icons (MCP 2025-11-25)
_meta: Option<Map<String, Value>>Optional metadata (e.g., for UI resource association in MCP Apps Extension)
execution: Option<ToolExecution>Execution metadata declaring task support level (MCP 2025-11-25).
Implementations§
Source§impl ToolInfo
impl ToolInfo
Sourcepub fn new(
name: impl Into<String>,
description: Option<String>,
input_schema: Value,
) -> Self
pub fn new( name: impl Into<String>, description: Option<String>, input_schema: Value, ) -> Self
Create a new ToolInfo without metadata or annotations.
Sourcepub fn with_annotations(
name: impl Into<String>,
description: Option<String>,
input_schema: Value,
annotations: ToolAnnotations,
) -> Self
pub fn with_annotations( name: impl Into<String>, description: Option<String>, input_schema: Value, annotations: ToolAnnotations, ) -> Self
Create a new ToolInfo with annotations.
Use this constructor when your tool has annotation hints. For output
schema, chain ToolInfo::with_output_schema on the result.
§Example
use pmcp::types::{ToolInfo, ToolAnnotations};
use serde_json::json;
let annotations = ToolAnnotations::new()
.with_read_only(true)
.with_output_type_name("MyResult");
let tool = ToolInfo::with_annotations(
"my_tool",
Some("My tool description".to_string()),
json!({"type": "object"}),
annotations,
).with_output_schema(json!({"type": "object", "properties": {"result": {"type": "string"}}}));Sourcepub fn with_ui(
name: impl Into<String>,
description: Option<String>,
input_schema: Value,
ui_resource_uri: impl Into<String>,
) -> Self
pub fn with_ui( name: impl Into<String>, description: Option<String>, input_schema: Value, ui_resource_uri: impl Into<String>, ) -> Self
Create a new ToolInfo with UI resource metadata.
Produces nested _meta format compatible with both MCP standard and ChatGPT:
_meta.ui.resourceUri- MCP standard nested format_meta["openai/outputTemplate"]-ChatGPTalias for the same URI
Sourcepub fn with_output_schema(self, schema: Value) -> Self
pub fn with_output_schema(self, schema: Value) -> Self
Set the output schema for this tool (MCP spec 2025-06-18).
The output schema declares the JSON Schema that the tool’s structured output conforms to, enabling clients to validate and type-check results.
§Example
use pmcp::types::ToolInfo;
use serde_json::json;
let tool = ToolInfo::new("my_tool", None, json!({"type": "object"}))
.with_output_schema(json!({
"type": "object",
"properties": { "count": { "type": "integer" } }
}));Sourcepub fn with_widget_meta(self, widget: WidgetMeta) -> Self
Available on crate feature mcp-apps only.
pub fn with_widget_meta(self, widget: WidgetMeta) -> Self
mcp-apps only.Add widget metadata, deep-merging into existing _meta.
This merges WidgetMeta::to_meta_map() into the tool’s _meta,
correctly combining nested ui objects so that ui.resourceUri
and widget fields like ui.prefersBorder coexist.
§Example
use pmcp::types::ToolInfo;
use pmcp::types::mcp_apps::WidgetMeta;
use serde_json::json;
let tool = ToolInfo::with_ui("my_tool", None, json!({"type": "object"}), "ui://w/app.html")
.with_widget_meta(WidgetMeta::new().prefers_border(true));
// _meta.ui = { "resourceUri": "ui://w/app.html", "prefersBorder": true }Sourcepub fn with_meta_entry(self, key: impl Into<String>, value: Value) -> Self
pub fn with_meta_entry(self, key: impl Into<String>, value: Value) -> Self
Add a single key-value pair to _meta, merging with existing entries.
If the key already exists and both values are objects, they are deep-merged. Otherwise the new value replaces the old (last-in wins).
This is the composable counterpart to ToolInfo::with_ui –
multiple calls can be chained without overwriting each other’s keys.
§Example
use pmcp::types::ToolInfo;
use serde_json::json;
let tool = ToolInfo::new("my_tool", None, json!({"type": "object"}))
.with_meta_entry("ui", json!({"resourceUri": "ui://x"}))
.with_meta_entry("execution", json!({"mode": "async"}));