mcp_protocol/types/
prompt.rs

1// mcp-protocol/src/types/prompt.rs
2use serde::{Deserialize, Serialize};
3use std::collections::HashMap;
4
5/// Prompt definition provided by the server
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct Prompt {
8    /// Unique identifier for the prompt
9    pub name: String,
10    
11    /// Optional human-readable description
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub description: Option<String>,
14    
15    /// Optional list of arguments for customization
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub arguments: Option<Vec<PromptArgument>>,
18    
19    /// Optional annotations for additional information
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub annotations: Option<HashMap<String, serde_json::Value>>,
22}
23
24/// Argument definition for a prompt
25#[derive(Debug, Clone, Serialize, Deserialize)]
26pub struct PromptArgument {
27    /// Argument name
28    pub name: String,
29    
30    /// Optional human-readable description
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub description: Option<String>,
33    
34    /// Whether the argument is required
35    #[serde(skip_serializing_if = "Option::is_none")]
36    pub required: Option<bool>,
37}
38
39/// Parameters for the prompts/list request
40#[derive(Debug, Clone, Serialize, Deserialize)]
41pub struct PromptsListParams {
42    /// Optional cursor for pagination
43    #[serde(skip_serializing_if = "Option::is_none")]
44    pub cursor: Option<String>,
45}
46
47/// Result of the prompts/list request
48#[derive(Debug, Clone, Serialize, Deserialize)]
49pub struct PromptsListResult {
50    /// List of available prompts
51    pub prompts: Vec<Prompt>,
52    
53    /// Cursor for the next page (empty if no more pages)
54    #[serde(rename = "nextCursor")]
55    pub next_cursor: String,
56}
57
58/// Parameters for the prompts/get request
59#[derive(Debug, Clone, Serialize, Deserialize)]
60pub struct PromptGetParams {
61    /// Name of the prompt to retrieve
62    pub name: String,
63    
64    /// Arguments to apply to the prompt
65    #[serde(skip_serializing_if = "Option::is_none")]
66    pub arguments: Option<HashMap<String, String>>,
67}
68
69/// Result of the prompts/get request
70#[derive(Debug, Clone, Serialize, Deserialize)]
71pub struct PromptGetResult {
72    /// Optional human-readable description
73    #[serde(skip_serializing_if = "Option::is_none")]
74    pub description: Option<String>,
75    
76    /// Messages in the prompt
77    pub messages: Vec<PromptMessage>,
78}
79
80/// Message in a prompt
81#[derive(Debug, Clone, Serialize, Deserialize)]
82pub struct PromptMessage {
83    /// Role of the message sender ("user" or "assistant")
84    pub role: String,
85    
86    /// Content of the message
87    pub content: PromptMessageContent,
88}
89
90/// Content of a prompt message
91#[derive(Debug, Clone, Serialize, Deserialize)]
92#[serde(tag = "type")]
93pub enum PromptMessageContent {
94    /// Text content
95    #[serde(rename = "text")]
96    Text { text: String },
97    
98    /// Image content
99    #[serde(rename = "image")]
100    Image { 
101        data: String, 
102        #[serde(rename = "mimeType")]
103        mime_type: String 
104    },
105    
106    /// Resource content
107    #[serde(rename = "resource")]
108    Resource { 
109        resource: EmbeddedResource 
110    },
111}
112
113/// Embedded resource in a prompt message
114#[derive(Debug, Clone, Serialize, Deserialize)]
115pub struct EmbeddedResource {
116    /// URI of the resource
117    pub uri: String,
118    
119    /// MIME type of the resource
120    #[serde(rename = "mimeType")]
121    pub mime_type: String,
122    
123    /// Text content (if text resource)
124    #[serde(skip_serializing_if = "Option::is_none")]
125    pub text: Option<String>,
126    
127    /// Binary data content (if binary resource)
128    #[serde(skip_serializing_if = "Option::is_none")]
129    pub data: Option<String>,
130}
131
132/// Reference to a prompt for completion
133#[derive(Debug, Clone, Serialize, Deserialize)]
134pub struct PromptReference {
135    /// Type of reference (always "ref/prompt")
136    #[serde(rename = "type")]
137    pub ref_type: String,
138    
139    /// Name of the prompt
140    pub name: String,
141}