rmcp/model/
tool.rs

1use std::{borrow::Cow, sync::Arc};
2
3/// Tools represent a routine that a server can execute
4/// Tool calls represent requests from the client to execute one
5use serde::{Deserialize, Serialize};
6use serde_json::Value;
7
8use super::JsonObject;
9
10/// A tool that can be used by a model.
11#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12#[serde(rename_all = "camelCase")]
13pub struct Tool {
14    /// The name of the tool
15    pub name: Cow<'static, str>,
16    /// A description of what the tool does
17    pub description: Cow<'static, str>,
18    /// A JSON Schema object defining the expected parameters for the tool
19    pub input_schema: Arc<JsonObject>,
20}
21
22impl Tool {
23    /// Create a new tool with the given name and description
24    pub fn new<N, D, S>(name: N, description: D, input_schema: S) -> Self
25    where
26        N: Into<Cow<'static, str>>,
27        D: Into<Cow<'static, str>>,
28        S: Into<Arc<JsonObject>>,
29    {
30        Tool {
31            name: name.into(),
32            description: description.into(),
33            input_schema: input_schema.into(),
34        }
35    }
36
37    /// Get the schema as json value
38    pub fn schema_as_json_value(&self) -> Value {
39        Value::Object(self.input_schema.as_ref().clone())
40    }
41}