mcprotocol_rs/server_features/
tools.rs

1use async_trait::async_trait;
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4
5use crate::Result;
6
7/// Represents a tool
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct Tool {
10    /// Unique identifier for the tool
11    pub id: String,
12    /// Human-readable name
13    pub name: String,
14    /// Description of what the tool does
15    pub description: String,
16    /// Tool parameters schema
17    pub parameters: Value,
18    /// Whether the tool requires user approval
19    pub requires_approval: bool,
20}
21
22/// Tool manager trait
23#[async_trait]
24pub trait ToolManager: Send + Sync {
25    /// Lists available tools
26    async fn list_tools(&self) -> Result<Vec<Tool>>;
27
28    /// Gets a specific tool by ID
29    async fn get_tool(&self, id: &str) -> Result<Tool>;
30
31    /// Executes a tool with given parameters
32    async fn execute_tool(&self, id: &str, params: Value) -> Result<Value>;
33
34    /// Cancels a running tool execution
35    async fn cancel_tool(&self, id: &str) -> Result<()>;
36}