-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtool.rs
More file actions
34 lines (32 loc) · 1.05 KB
/
Copy pathtool.rs
File metadata and controls
34 lines (32 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use crate::{
context::SshContext,
types::{ToolCall, ToolDef, ToolResult},
};
/// A tool that can be registered with the MCP registry and called by the LLM.
///
/// # Example
/// ```rust
/// struct EchoTool;
///
/// impl Tool for EchoTool {
/// fn def(&self) -> ToolDef {
/// ToolDef {
/// name: "echo".into(),
/// description: "Return the input unchanged.".into(),
/// params: vec![ToolParam { name: "text".into(), ... }],
/// }
/// }
///
/// fn call(&self, call: &ToolCall, _ctx: &dyn SshContext) -> anyhow::Result<ToolResult> {
/// let text = call.arg_str("text").unwrap_or("");
/// Ok(ToolResult::ok(&call.id, text))
/// }
/// }
/// ```
pub trait Tool: Send + Sync {
/// Static metadata: name, description, parameter schema.
fn def(&self) -> ToolDef;
/// Invoke the tool. Receives the full call (including id and raw arguments)
/// and a reference to the active SSH session.
fn call(&self, call: &ToolCall, ctx: &dyn SshContext) -> anyhow::Result<ToolResult>;
}