types.rs

  1use collections::HashMap;
  2use serde::{Deserialize, Serialize};
  3use url::Url;
  4
  5#[derive(Debug, Serialize)]
  6#[serde(rename_all = "camelCase")]
  7pub enum RequestType {
  8    Initialize,
  9    CallTool,
 10    ResourcesUnsubscribe,
 11    ResourcesSubscribe,
 12    ResourcesRead,
 13    ResourcesList,
 14    LoggingSetLevel,
 15    PromptsGet,
 16    PromptsList,
 17}
 18
 19impl RequestType {
 20    pub fn as_str(&self) -> &'static str {
 21        match self {
 22            RequestType::Initialize => "initialize",
 23            RequestType::CallTool => "tools/call",
 24            RequestType::ResourcesUnsubscribe => "resources/unsubscribe",
 25            RequestType::ResourcesSubscribe => "resources/subscribe",
 26            RequestType::ResourcesRead => "resources/read",
 27            RequestType::ResourcesList => "resources/list",
 28            RequestType::LoggingSetLevel => "logging/setLevel",
 29            RequestType::PromptsGet => "prompts/get",
 30            RequestType::PromptsList => "prompts/list",
 31        }
 32    }
 33}
 34
 35#[derive(Debug, Serialize)]
 36#[serde(rename_all = "camelCase")]
 37pub struct InitializeParams {
 38    pub protocol_version: u32,
 39    pub capabilities: ClientCapabilities,
 40    pub client_info: EntityInfo,
 41}
 42
 43#[derive(Debug, Serialize)]
 44#[serde(rename_all = "camelCase")]
 45pub struct CallToolParams {
 46    pub name: String,
 47    pub arguments: Option<serde_json::Value>,
 48}
 49
 50#[derive(Debug, Serialize)]
 51#[serde(rename_all = "camelCase")]
 52pub struct ResourcesUnsubscribeParams {
 53    pub uri: Url,
 54}
 55
 56#[derive(Debug, Serialize)]
 57#[serde(rename_all = "camelCase")]
 58pub struct ResourcesSubscribeParams {
 59    pub uri: Url,
 60}
 61
 62#[derive(Debug, Serialize)]
 63#[serde(rename_all = "camelCase")]
 64pub struct ResourcesReadParams {
 65    pub uri: Url,
 66}
 67
 68#[derive(Debug, Serialize)]
 69#[serde(rename_all = "camelCase")]
 70pub struct LoggingSetLevelParams {
 71    pub level: LoggingLevel,
 72}
 73
 74#[derive(Debug, Serialize)]
 75#[serde(rename_all = "camelCase")]
 76pub struct PromptsGetParams {
 77    pub name: String,
 78    pub arguments: Option<HashMap<String, String>>,
 79}
 80
 81#[derive(Debug, Deserialize)]
 82#[serde(rename_all = "camelCase")]
 83pub struct InitializeResponse {
 84    pub protocol_version: u32,
 85    pub capabilities: ServerCapabilities,
 86    pub server_info: EntityInfo,
 87}
 88
 89#[derive(Debug, Deserialize)]
 90#[serde(rename_all = "camelCase")]
 91pub struct ResourcesReadResponse {
 92    pub contents: Vec<ResourceContent>,
 93}
 94
 95#[derive(Debug, Deserialize)]
 96#[serde(rename_all = "camelCase")]
 97pub struct ResourcesListResponse {
 98    pub resource_templates: Option<Vec<ResourceTemplate>>,
 99    pub resources: Vec<Resource>,
100}
101
102#[derive(Debug, Deserialize)]
103#[serde(rename_all = "camelCase")]
104pub struct PromptsGetResponse {
105    pub description: Option<String>,
106    pub prompt: String,
107}
108
109#[derive(Debug, Deserialize)]
110#[serde(rename_all = "camelCase")]
111pub struct PromptsListResponse {
112    pub prompts: Vec<PromptInfo>,
113}
114
115#[derive(Debug, Deserialize, Clone)]
116#[serde(rename_all = "camelCase")]
117pub struct PromptInfo {
118    pub name: String,
119    pub arguments: Option<Vec<PromptArgument>>,
120}
121
122#[derive(Debug, Deserialize, Clone)]
123#[serde(rename_all = "camelCase")]
124pub struct PromptArgument {
125    pub name: String,
126    pub description: Option<String>,
127    pub required: Option<bool>,
128}
129
130// Shared Types
131
132#[derive(Debug, Serialize, Deserialize)]
133#[serde(rename_all = "camelCase")]
134pub struct ClientCapabilities {
135    pub experimental: Option<HashMap<String, serde_json::Value>>,
136    pub sampling: Option<HashMap<String, serde_json::Value>>,
137}
138
139#[derive(Debug, Serialize, Deserialize)]
140#[serde(rename_all = "camelCase")]
141pub struct ServerCapabilities {
142    pub experimental: Option<HashMap<String, serde_json::Value>>,
143    pub logging: Option<HashMap<String, serde_json::Value>>,
144    pub prompts: Option<HashMap<String, serde_json::Value>>,
145    pub resources: Option<ResourcesCapabilities>,
146    pub tools: Option<HashMap<String, serde_json::Value>>,
147}
148
149#[derive(Debug, Serialize, Deserialize)]
150#[serde(rename_all = "camelCase")]
151pub struct ResourcesCapabilities {
152    pub subscribe: Option<bool>,
153}
154
155#[derive(Debug, Serialize, Deserialize)]
156#[serde(rename_all = "camelCase")]
157pub struct Tool {
158    pub name: String,
159    pub description: Option<String>,
160    pub input_schema: serde_json::Value,
161}
162
163#[derive(Debug, Serialize, Deserialize)]
164#[serde(rename_all = "camelCase")]
165pub struct EntityInfo {
166    pub name: String,
167    pub version: String,
168}
169
170#[derive(Debug, Serialize, Deserialize)]
171#[serde(rename_all = "camelCase")]
172pub struct Resource {
173    pub uri: Url,
174    pub mime_type: Option<String>,
175}
176
177#[derive(Debug, Serialize, Deserialize)]
178#[serde(rename_all = "camelCase")]
179pub struct ResourceContent {
180    pub uri: Url,
181    pub mime_type: Option<String>,
182    pub content_type: String,
183    pub text: Option<String>,
184    pub data: Option<String>,
185}
186
187#[derive(Debug, Serialize, Deserialize)]
188#[serde(rename_all = "camelCase")]
189pub struct ResourceTemplate {
190    pub uri_template: String,
191    pub name: Option<String>,
192    pub description: Option<String>,
193}
194
195#[derive(Debug, Serialize, Deserialize)]
196#[serde(rename_all = "lowercase")]
197pub enum LoggingLevel {
198    Debug,
199    Info,
200    Warning,
201    Error,
202}
203
204// Client Notifications
205
206#[derive(Debug, Serialize)]
207#[serde(rename_all = "camelCase")]
208pub enum NotificationType {
209    Initialized,
210    Progress,
211}
212
213impl NotificationType {
214    pub fn as_str(&self) -> &'static str {
215        match self {
216            NotificationType::Initialized => "notifications/initialized",
217            NotificationType::Progress => "notifications/progress",
218        }
219    }
220}
221
222#[derive(Debug, Serialize)]
223#[serde(untagged)]
224pub enum ClientNotification {
225    Initialized,
226    Progress(ProgressParams),
227}
228
229#[derive(Debug, Serialize)]
230#[serde(rename_all = "camelCase")]
231pub struct ProgressParams {
232    pub progress_token: String,
233    pub progress: f64,
234    pub total: Option<f64>,
235}