#[non_exhaustive]pub struct Tool {
pub name: String,
pub namespaced_name: Option<String>,
pub description: String,
pub instructions: Option<String>,
pub parameters: HashMap<String, Value>,
pub overrides_built_in_tool: bool,
pub skip_permission: bool,
pub defer: Option<DeferMode>,
/* private fields */
}Expand description
A tool that the client exposes to the Copilot agent.
Sent to the CLI as part of SessionConfig::tools / ResumeSessionConfig::tools
at session creation/resume time. The Rust SDK hand-authors this struct
(rather than using the schema-generated form) so it can carry runtime
hints — overrides_built_in_tool, skip_permission — that don’t appear
in the wire schema but are honored by the CLI.
A Tool may optionally carry a handler: an
Arc<dyn ToolHandler> that implements the tool’s runtime behavior.
When present, the SDK dispatches matching external_tool.requested
broadcasts to it automatically. When absent (None), the tool is
declaration-only — another connected client must service incoming
invocations.
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 identifier (e.g., "bash", "grep", "str_replace_editor").
namespaced_name: Option<String>Optional namespaced name for declarative filtering (e.g., "playwright/navigate"
for MCP tools).
description: StringDescription of what the tool does.
instructions: Option<String>Optional instructions for how to use this tool effectively.
parameters: HashMap<String, Value>JSON Schema for the tool’s input parameters.
overrides_built_in_tool: boolWhen true, this tool replaces a built-in tool of the same name
(e.g. supplying a custom grep that the agent uses in place of the
CLI’s built-in implementation).
skip_permission: boolWhen true, the CLI does not request permission before invoking
this tool. Use with caution — the tool is responsible for any
access control.
defer: Option<DeferMode>Controls whether the tool may be deferred (loaded lazily via tool
search) rather than always pre-loaded. When DeferMode::Auto, the
tool can be deferred and surfaced through tool search. When
DeferMode::Never, the tool is always pre-loaded. None lets the
runtime decide.
Implementations§
Source§impl Tool
impl Tool
Sourcepub fn new(name: impl Into<String>) -> Self
pub fn new(name: impl Into<String>) -> Self
Construct a new Tool with the given name and otherwise default
values. The struct is #[non_exhaustive], so external callers
cannot use struct-literal syntax — use this builder or
Default::default plus mut-let.
§Example
let tool = Tool::new("greet")
.with_description("Say hello to a user")
.with_parameters(json!({
"type": "object",
"properties": { "name": { "type": "string" } },
"required": ["name"]
}));Sourcepub fn with_namespaced_name(self, namespaced_name: impl Into<String>) -> Self
pub fn with_namespaced_name(self, namespaced_name: impl Into<String>) -> Self
Set the namespaced name for declarative filtering (e.g.
"playwright/navigate" for MCP tools).
Sourcepub fn with_description(self, description: impl Into<String>) -> Self
pub fn with_description(self, description: impl Into<String>) -> Self
Set the human-readable description of what the tool does.
Sourcepub fn with_instructions(self, instructions: impl Into<String>) -> Self
pub fn with_instructions(self, instructions: impl Into<String>) -> Self
Set optional instructions for how to use this tool effectively.
Sourcepub fn with_parameters(self, parameters: Value) -> Self
pub fn with_parameters(self, parameters: Value) -> Self
Set the JSON Schema for the tool’s input parameters.
Accepts a JSON Schema as a serde_json::Value, typically built with
serde_json::json!({...}) or returned by schema_for (available
with the derive feature). Tool parameter schemas are always
top-level JSON objects ({"type": "object", ...}).
§Panics
Panics if parameters is not a JSON object. Use
crate::tool::try_tool_parameters and assign to
Tool::parameters directly when the schema comes from dynamic
input and should produce a recoverable error instead.
Sourcepub fn with_overrides_built_in_tool(self, overrides: bool) -> Self
pub fn with_overrides_built_in_tool(self, overrides: bool) -> Self
Mark this tool as overriding a built-in tool of the same name.
E.g. supplying a custom grep that the agent uses in place of the
CLI’s built-in implementation.
Sourcepub fn with_skip_permission(self, skip: bool) -> Self
pub fn with_skip_permission(self, skip: bool) -> Self
When true, the CLI will not request permission before invoking
this tool. Use with caution — the tool is responsible for any
access control.
Sourcepub fn with_defer(self, defer: DeferMode) -> Self
pub fn with_defer(self, defer: DeferMode) -> Self
Set the deferral mode controlling whether the tool may be loaded
lazily via tool search (DeferMode::Auto) or always pre-loaded
(DeferMode::Never).
Sourcepub fn with_handler(self, handler: Arc<dyn ToolHandler>) -> Self
pub fn with_handler(self, handler: Arc<dyn ToolHandler>) -> Self
Attach a runtime implementation. The SDK will dispatch matching
external_tool.requested broadcasts to handler for this tool’s
name. Without a handler the tool is declaration-only.
Sourcepub fn handler(&self) -> Option<&Arc<dyn ToolHandler>>
pub fn handler(&self) -> Option<&Arc<dyn ToolHandler>>
Returns the attached runtime handler, if any.
Read-only inspection — to install or replace a handler, use
Tool::with_handler.