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 prompt: String,
106}
107
108#[derive(Debug, Deserialize)]
109#[serde(rename_all = "camelCase")]
110pub struct PromptsListResponse {
111 pub prompts: Vec<PromptInfo>,
112}
113
114#[derive(Debug, Deserialize, Clone)]
115#[serde(rename_all = "camelCase")]
116pub struct PromptInfo {
117 pub name: String,
118 pub arguments: Option<Vec<PromptArgument>>,
119}
120
121#[derive(Debug, Deserialize, Clone)]
122#[serde(rename_all = "camelCase")]
123pub struct PromptArgument {
124 pub name: String,
125 pub description: Option<String>,
126 pub required: Option<bool>,
127}
128
129// Shared Types
130
131#[derive(Debug, Serialize, Deserialize)]
132#[serde(rename_all = "camelCase")]
133pub struct ClientCapabilities {
134 pub experimental: Option<HashMap<String, serde_json::Value>>,
135 pub sampling: Option<HashMap<String, serde_json::Value>>,
136}
137
138#[derive(Debug, Serialize, Deserialize)]
139#[serde(rename_all = "camelCase")]
140pub struct ServerCapabilities {
141 pub experimental: Option<HashMap<String, serde_json::Value>>,
142 pub logging: Option<HashMap<String, serde_json::Value>>,
143 pub prompts: Option<HashMap<String, serde_json::Value>>,
144 pub resources: Option<ResourcesCapabilities>,
145 pub tools: Option<HashMap<String, serde_json::Value>>,
146}
147
148#[derive(Debug, Serialize, Deserialize)]
149#[serde(rename_all = "camelCase")]
150pub struct ResourcesCapabilities {
151 pub subscribe: Option<bool>,
152}
153
154#[derive(Debug, Serialize, Deserialize)]
155#[serde(rename_all = "camelCase")]
156pub struct Tool {
157 pub name: String,
158 pub description: Option<String>,
159 pub input_schema: serde_json::Value,
160}
161
162#[derive(Debug, Serialize, Deserialize)]
163#[serde(rename_all = "camelCase")]
164pub struct EntityInfo {
165 pub name: String,
166 pub version: String,
167}
168
169#[derive(Debug, Serialize, Deserialize)]
170#[serde(rename_all = "camelCase")]
171pub struct Resource {
172 pub uri: Url,
173 pub mime_type: Option<String>,
174}
175
176#[derive(Debug, Serialize, Deserialize)]
177#[serde(rename_all = "camelCase")]
178pub struct ResourceContent {
179 pub uri: Url,
180 pub mime_type: Option<String>,
181 pub content_type: String,
182 pub text: Option<String>,
183 pub data: Option<String>,
184}
185
186#[derive(Debug, Serialize, Deserialize)]
187#[serde(rename_all = "camelCase")]
188pub struct ResourceTemplate {
189 pub uri_template: String,
190 pub name: Option<String>,
191 pub description: Option<String>,
192}
193
194#[derive(Debug, Serialize, Deserialize)]
195#[serde(rename_all = "lowercase")]
196pub enum LoggingLevel {
197 Debug,
198 Info,
199 Warning,
200 Error,
201}
202
203// Client Notifications
204
205#[derive(Debug, Serialize)]
206#[serde(rename_all = "camelCase")]
207pub enum NotificationType {
208 Initialized,
209 Progress,
210}
211
212impl NotificationType {
213 pub fn as_str(&self) -> &'static str {
214 match self {
215 NotificationType::Initialized => "notifications/initialized",
216 NotificationType::Progress => "notifications/progress",
217 }
218 }
219}
220
221#[derive(Debug, Serialize)]
222#[serde(untagged)]
223pub enum ClientNotification {
224 Initialized,
225 Progress(ProgressParams),
226}
227
228#[derive(Debug, Serialize)]
229#[serde(rename_all = "camelCase")]
230pub struct ProgressParams {
231 pub progress_token: String,
232 pub progress: f64,
233 pub total: Option<f64>,
234}