Skip to main content

poem_mcpserver/protocol/
tool.rs

1//! Tool protocol.
2
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5
6use crate::protocol::content::Content;
7
8/// A request to list tools.
9#[derive(Debug, Deserialize, Default)]
10#[serde(rename_all = "camelCase")]
11pub struct ToolsListRequest {
12    /// The cursor to continue listing tools.
13    pub cursor: Option<String>,
14}
15
16/// Tool information.
17#[derive(Debug, Serialize)]
18#[serde(rename_all = "camelCase")]
19pub struct Tool {
20    /// The name of the tool.
21    pub name: &'static str,
22    /// The description of the tool.
23    pub description: &'static str,
24    /// The input schema of the tool.
25    pub input_schema: Value,
26    /// The output schema of the tool, if any.
27    #[serde(skip_serializing_if = "Option::is_none")]
28    pub output_schema: Option<Value>,
29}
30
31/// A response to a tools/list request.
32#[derive(Debug, Serialize)]
33#[serde(rename_all = "camelCase")]
34pub struct ToolsListResponse {
35    /// Tools list.
36    pub tools: Vec<Tool>,
37}
38
39/// A request to call a tool.
40#[derive(Debug, Deserialize)]
41#[serde(rename_all = "camelCase")]
42pub struct ToolsCallRequest {
43    /// The name of the tool.
44    pub name: String,
45    #[serde(default)]
46    /// The arguments passed to the tool.
47    pub arguments: Value,
48}
49
50/// A response to a tools/call request.
51#[derive(Debug, Serialize)]
52#[serde(rename_all = "camelCase")]
53pub struct ToolsCallResponse {
54    /// Response content.
55    pub content: Vec<Content>,
56    /// Structured content (if any).
57    #[serde(skip_serializing_if = "Option::is_none")]
58    pub structured_content: Option<Value>,
59    /// Whether the response is an error.
60    pub is_error: bool,
61}