turbomcp_protocol/types/
prompts.rs

1//! Prompt template types
2//!
3//! This module contains types for the MCP prompt template system,
4//! including prompt definitions, arguments, and prompt requests/responses.
5
6use serde::{Deserialize, Serialize};
7use std::collections::HashMap;
8
9use super::{
10    content::Content,
11    core::{Cursor, Role},
12};
13
14/// Prompt definition per MCP 2025-06-18 specification
15#[derive(Debug, Clone, Serialize, Deserialize)]
16pub struct Prompt {
17    /// Prompt name (programmatic identifier)
18    pub name: String,
19
20    /// Display title for UI contexts (optional, falls back to name if not provided)
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub title: Option<String>,
23
24    /// An optional description of what this prompt provides
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub description: Option<String>,
27
28    /// A list of arguments to use for templating the prompt
29    #[serde(skip_serializing_if = "Option::is_none")]
30    pub arguments: Option<Vec<PromptArgument>>,
31
32    /// General metadata field for extensions and custom data
33    #[serde(rename = "_meta", skip_serializing_if = "Option::is_none")]
34    pub meta: Option<HashMap<String, serde_json::Value>>,
35}
36
37/// Prompt argument definition per MCP 2025-06-18 specification
38#[derive(Debug, Clone, Serialize, Deserialize)]
39pub struct PromptArgument {
40    /// Argument name (programmatic identifier)
41    pub name: String,
42
43    /// Display title for UI contexts (optional, falls back to name if not provided)
44    #[serde(skip_serializing_if = "Option::is_none")]
45    pub title: Option<String>,
46
47    /// A human-readable description of the argument
48    #[serde(skip_serializing_if = "Option::is_none")]
49    pub description: Option<String>,
50
51    /// Whether this argument must be provided
52    #[serde(skip_serializing_if = "Option::is_none")]
53    pub required: Option<bool>,
54}
55
56/// Prompt input parameters
57pub type PromptInput = HashMap<String, serde_json::Value>;
58
59/// List prompts request with optional pagination
60#[derive(Debug, Clone, Serialize, Deserialize, Default)]
61pub struct ListPromptsRequest {
62    /// Optional cursor for pagination
63    /// An opaque token representing the current pagination position.
64    /// If provided, the server should return results starting after this cursor.
65    #[serde(skip_serializing_if = "Option::is_none")]
66    pub cursor: Option<Cursor>,
67    /// Optional metadata per MCP 2025-06-18 specification
68    #[serde(rename = "_meta", skip_serializing_if = "Option::is_none")]
69    pub _meta: Option<serde_json::Value>,
70}
71
72/// List prompts result
73#[derive(Debug, Clone, Serialize, Deserialize)]
74pub struct ListPromptsResult {
75    /// Available prompts
76    pub prompts: Vec<Prompt>,
77    /// Optional continuation token
78    #[serde(rename = "nextCursor", skip_serializing_if = "Option::is_none")]
79    pub next_cursor: Option<Cursor>,
80    /// Optional metadata per MCP 2025-06-18 specification
81    #[serde(skip_serializing_if = "Option::is_none")]
82    pub _meta: Option<serde_json::Value>,
83}
84
85/// Get prompt request
86#[derive(Debug, Clone, Serialize, Deserialize)]
87pub struct GetPromptRequest {
88    /// Prompt name
89    pub name: String,
90    /// Prompt arguments
91    #[serde(skip_serializing_if = "Option::is_none")]
92    pub arguments: Option<PromptInput>,
93    /// Optional metadata per MCP 2025-06-18 specification
94    #[serde(skip_serializing_if = "Option::is_none")]
95    pub _meta: Option<serde_json::Value>,
96}
97
98/// Get prompt result
99#[derive(Debug, Clone, Serialize, Deserialize)]
100pub struct GetPromptResult {
101    /// Prompt description
102    #[serde(skip_serializing_if = "Option::is_none")]
103    pub description: Option<String>,
104    /// Prompt messages
105    pub messages: Vec<PromptMessage>,
106    /// Optional metadata per MCP 2025-06-18 specification
107    #[serde(skip_serializing_if = "Option::is_none")]
108    pub _meta: Option<serde_json::Value>,
109}
110
111/// Prompt message
112#[derive(Debug, Clone, Serialize, Deserialize)]
113pub struct PromptMessage {
114    /// Message role
115    pub role: Role,
116    /// Message content
117    pub content: Content,
118}