pub trait McpTool: Send + Sync {
// Required methods
fn name(&self) -> &'static str;
fn tool_def(&self) -> Tool;
fn handle(
&self,
args: &Map<String, Value>,
ctx: &ToolContext,
) -> Result<ToolOutput, ErrorData>;
}Expand description
Trait for a self-contained MCP tool. Each tool provides its own schema definition and handler, eliminating the possibility of schema/handler drift.
This trait is the plugin interface for LcpTools: any implementation can be
registered at runtime via ToolRegistry::register(). Future plugin system
will load implementations from shared libraries or subprocess bridges.
Handlers are synchronous because all existing tool handlers are sync.
The async boundary (cache locks, session reads) is handled by the dispatch
layer before calling handle.
Required Methods§
Sourcefn tool_def(&self) -> Tool
fn tool_def(&self) -> Tool
MCP tool definition including JSON schema. This replaces the
corresponding entry in granular_tool_defs().
Sourcefn handle(
&self,
args: &Map<String, Value>,
ctx: &ToolContext,
) -> Result<ToolOutput, ErrorData>
fn handle( &self, args: &Map<String, Value>, ctx: &ToolContext, ) -> Result<ToolOutput, ErrorData>
Execute the tool. Args are the raw JSON-RPC arguments.
ctx provides access to resolved paths and project state.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".