mcp_core_fishcode2025/
tool.rs

1/// Tools represent a routine that a server can execute
2/// Tool calls represent requests from the client to execute one
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5
6/// A tool that can be used by a model.
7#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8#[serde(rename_all = "camelCase")]
9pub struct Tool {
10    /// The name of the tool
11    pub name: String,
12    /// A description of what the tool does
13    pub description: String,
14    /// A JSON Schema object defining the expected parameters for the tool
15    pub input_schema: Value,
16}
17
18impl Tool {
19    /// Create a new tool with the given name and description
20    pub fn new<N, D>(name: N, description: D, input_schema: Value) -> Self
21    where
22        N: Into<String>,
23        D: Into<String>,
24    {
25        Tool {
26            name: name.into(),
27            description: description.into(),
28            input_schema,
29        }
30    }
31}
32
33/// A tool call request that an extension can execute
34#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
35#[serde(rename_all = "camelCase")]
36pub struct ToolCall {
37    /// The name of the tool to execute
38    pub name: String,
39    /// The parameters for the execution
40    pub arguments: Value,
41}
42
43impl ToolCall {
44    /// Create a new ToolUse with the given name and parameters
45    pub fn new<S: Into<String>>(name: S, arguments: Value) -> Self {
46        Self {
47            name: name.into(),
48            arguments,
49        }
50    }
51}