mcp_types/
lib.rs

1// @generated
2// DO NOT EDIT THIS FILE DIRECTLY.
3// Run the following in the crate root to regenerate this file:
4//
5// ```shell
6// ./generate_mcp_types.py
7// ```
8use serde::Deserialize;
9use serde::Serialize;
10use serde::de::DeserializeOwned;
11use std::convert::TryFrom;
12
13use schemars::JsonSchema;
14use ts_rs::TS;
15
16pub const MCP_SCHEMA_VERSION: &str = "2025-06-18";
17pub const JSONRPC_VERSION: &str = "2.0";
18
19/// Paired request/response types for the Model Context Protocol (MCP).
20pub trait ModelContextProtocolRequest {
21    const METHOD: &'static str;
22    type Params: DeserializeOwned + Serialize + Send + Sync + 'static;
23    type Result: DeserializeOwned + Serialize + Send + Sync + 'static;
24}
25
26/// One-way message in the Model Context Protocol (MCP).
27pub trait ModelContextProtocolNotification {
28    const METHOD: &'static str;
29    type Params: DeserializeOwned + Serialize + Send + Sync + 'static;
30}
31
32fn default_jsonrpc() -> String {
33    JSONRPC_VERSION.to_owned()
34}
35
36/// Optional annotations for the client. The client can use annotations to inform how objects are used or displayed
37#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
38pub struct Annotations {
39    #[serde(default, skip_serializing_if = "Option::is_none")]
40    #[ts(optional)]
41    pub audience: Option<Vec<Role>>,
42    #[serde(
43        rename = "lastModified",
44        default,
45        skip_serializing_if = "Option::is_none"
46    )]
47    #[ts(optional)]
48    pub last_modified: Option<String>,
49    #[serde(default, skip_serializing_if = "Option::is_none")]
50    #[ts(optional)]
51    pub priority: Option<f64>,
52}
53
54/// Audio provided to or from an LLM.
55#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
56pub struct AudioContent {
57    #[serde(default, skip_serializing_if = "Option::is_none")]
58    #[ts(optional)]
59    pub annotations: Option<Annotations>,
60    pub data: String,
61    #[serde(rename = "mimeType")]
62    pub mime_type: String,
63    pub r#type: String, // &'static str = "audio"
64}
65
66/// Base interface for metadata with name (identifier) and title (display name) properties.
67#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
68pub struct BaseMetadata {
69    pub name: String,
70    #[serde(default, skip_serializing_if = "Option::is_none")]
71    #[ts(optional)]
72    pub title: Option<String>,
73}
74
75#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
76pub struct BlobResourceContents {
77    pub blob: String,
78    #[serde(rename = "mimeType", default, skip_serializing_if = "Option::is_none")]
79    #[ts(optional)]
80    pub mime_type: Option<String>,
81    pub uri: String,
82}
83
84#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
85pub struct BooleanSchema {
86    #[serde(default, skip_serializing_if = "Option::is_none")]
87    #[ts(optional)]
88    pub default: Option<bool>,
89    #[serde(default, skip_serializing_if = "Option::is_none")]
90    #[ts(optional)]
91    pub description: Option<String>,
92    #[serde(default, skip_serializing_if = "Option::is_none")]
93    #[ts(optional)]
94    pub title: Option<String>,
95    pub r#type: String, // &'static str = "boolean"
96}
97
98#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
99pub enum CallToolRequest {}
100
101impl ModelContextProtocolRequest for CallToolRequest {
102    const METHOD: &'static str = "tools/call";
103    type Params = CallToolRequestParams;
104    type Result = CallToolResult;
105}
106
107#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
108pub struct CallToolRequestParams {
109    #[serde(default, skip_serializing_if = "Option::is_none")]
110    #[ts(optional)]
111    pub arguments: Option<serde_json::Value>,
112    pub name: String,
113}
114
115/// The server's response to a tool call.
116#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
117pub struct CallToolResult {
118    pub content: Vec<ContentBlock>,
119    #[serde(rename = "isError", default, skip_serializing_if = "Option::is_none")]
120    #[ts(optional)]
121    pub is_error: Option<bool>,
122    #[serde(
123        rename = "structuredContent",
124        default,
125        skip_serializing_if = "Option::is_none"
126    )]
127    #[ts(optional)]
128    pub structured_content: Option<serde_json::Value>,
129}
130
131impl From<CallToolResult> for serde_json::Value {
132    fn from(value: CallToolResult) -> Self {
133        // Leave this as it should never fail
134        #[expect(clippy::unwrap_used)]
135        serde_json::to_value(value).unwrap()
136    }
137}
138
139#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
140pub enum CancelledNotification {}
141
142impl ModelContextProtocolNotification for CancelledNotification {
143    const METHOD: &'static str = "notifications/cancelled";
144    type Params = CancelledNotificationParams;
145}
146
147#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
148pub struct CancelledNotificationParams {
149    #[serde(default, skip_serializing_if = "Option::is_none")]
150    #[ts(optional)]
151    pub reason: Option<String>,
152    #[serde(rename = "requestId")]
153    pub request_id: RequestId,
154}
155
156/// Capabilities a client may support. Known capabilities are defined here, in this schema, but this is not a closed set: any client can define its own, additional capabilities.
157#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
158pub struct ClientCapabilities {
159    #[serde(default, skip_serializing_if = "Option::is_none")]
160    #[ts(optional)]
161    pub elicitation: Option<serde_json::Value>,
162    #[serde(default, skip_serializing_if = "Option::is_none")]
163    #[ts(optional)]
164    pub experimental: Option<serde_json::Value>,
165    #[serde(default, skip_serializing_if = "Option::is_none")]
166    #[ts(optional)]
167    pub roots: Option<ClientCapabilitiesRoots>,
168    #[serde(default, skip_serializing_if = "Option::is_none")]
169    #[ts(optional)]
170    pub sampling: Option<serde_json::Value>,
171}
172
173/// Present if the client supports listing roots.
174#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
175pub struct ClientCapabilitiesRoots {
176    #[serde(
177        rename = "listChanged",
178        default,
179        skip_serializing_if = "Option::is_none"
180    )]
181    #[ts(optional)]
182    pub list_changed: Option<bool>,
183}
184
185#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
186#[serde(untagged)]
187pub enum ClientNotification {
188    CancelledNotification(CancelledNotification),
189    InitializedNotification(InitializedNotification),
190    ProgressNotification(ProgressNotification),
191    RootsListChangedNotification(RootsListChangedNotification),
192}
193
194#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
195#[serde(tag = "method", content = "params")]
196pub enum ClientRequest {
197    #[serde(rename = "initialize")]
198    InitializeRequest(<InitializeRequest as ModelContextProtocolRequest>::Params),
199    #[serde(rename = "ping")]
200    PingRequest(<PingRequest as ModelContextProtocolRequest>::Params),
201    #[serde(rename = "resources/list")]
202    ListResourcesRequest(<ListResourcesRequest as ModelContextProtocolRequest>::Params),
203    #[serde(rename = "resources/templates/list")]
204    ListResourceTemplatesRequest(
205        <ListResourceTemplatesRequest as ModelContextProtocolRequest>::Params,
206    ),
207    #[serde(rename = "resources/read")]
208    ReadResourceRequest(<ReadResourceRequest as ModelContextProtocolRequest>::Params),
209    #[serde(rename = "resources/subscribe")]
210    SubscribeRequest(<SubscribeRequest as ModelContextProtocolRequest>::Params),
211    #[serde(rename = "resources/unsubscribe")]
212    UnsubscribeRequest(<UnsubscribeRequest as ModelContextProtocolRequest>::Params),
213    #[serde(rename = "prompts/list")]
214    ListPromptsRequest(<ListPromptsRequest as ModelContextProtocolRequest>::Params),
215    #[serde(rename = "prompts/get")]
216    GetPromptRequest(<GetPromptRequest as ModelContextProtocolRequest>::Params),
217    #[serde(rename = "tools/list")]
218    ListToolsRequest(<ListToolsRequest as ModelContextProtocolRequest>::Params),
219    #[serde(rename = "tools/call")]
220    CallToolRequest(<CallToolRequest as ModelContextProtocolRequest>::Params),
221    #[serde(rename = "logging/setLevel")]
222    SetLevelRequest(<SetLevelRequest as ModelContextProtocolRequest>::Params),
223    #[serde(rename = "completion/complete")]
224    CompleteRequest(<CompleteRequest as ModelContextProtocolRequest>::Params),
225}
226
227#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
228#[serde(untagged)]
229pub enum ClientResult {
230    Result(Result),
231    CreateMessageResult(CreateMessageResult),
232    ListRootsResult(ListRootsResult),
233    ElicitResult(ElicitResult),
234}
235
236#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
237pub enum CompleteRequest {}
238
239impl ModelContextProtocolRequest for CompleteRequest {
240    const METHOD: &'static str = "completion/complete";
241    type Params = CompleteRequestParams;
242    type Result = CompleteResult;
243}
244
245#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
246pub struct CompleteRequestParams {
247    pub argument: CompleteRequestParamsArgument,
248    #[serde(default, skip_serializing_if = "Option::is_none")]
249    #[ts(optional)]
250    pub context: Option<CompleteRequestParamsContext>,
251    pub r#ref: CompleteRequestParamsRef,
252}
253
254/// Additional, optional context for completions
255#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
256pub struct CompleteRequestParamsContext {
257    #[serde(default, skip_serializing_if = "Option::is_none")]
258    #[ts(optional)]
259    pub arguments: Option<serde_json::Value>,
260}
261
262/// The argument's information
263#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
264pub struct CompleteRequestParamsArgument {
265    pub name: String,
266    pub value: String,
267}
268
269#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
270#[serde(untagged)]
271pub enum CompleteRequestParamsRef {
272    PromptReference(PromptReference),
273    ResourceTemplateReference(ResourceTemplateReference),
274}
275
276/// The server's response to a completion/complete request
277#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
278pub struct CompleteResult {
279    pub completion: CompleteResultCompletion,
280}
281
282#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
283pub struct CompleteResultCompletion {
284    #[serde(rename = "hasMore", default, skip_serializing_if = "Option::is_none")]
285    #[ts(optional)]
286    pub has_more: Option<bool>,
287    #[serde(default, skip_serializing_if = "Option::is_none")]
288    #[ts(optional)]
289    pub total: Option<i64>,
290    pub values: Vec<String>,
291}
292
293impl From<CompleteResult> for serde_json::Value {
294    fn from(value: CompleteResult) -> Self {
295        // Leave this as it should never fail
296        #[expect(clippy::unwrap_used)]
297        serde_json::to_value(value).unwrap()
298    }
299}
300
301#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
302#[serde(untagged)]
303pub enum ContentBlock {
304    TextContent(TextContent),
305    ImageContent(ImageContent),
306    AudioContent(AudioContent),
307    ResourceLink(ResourceLink),
308    EmbeddedResource(EmbeddedResource),
309}
310
311#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
312pub enum CreateMessageRequest {}
313
314impl ModelContextProtocolRequest for CreateMessageRequest {
315    const METHOD: &'static str = "sampling/createMessage";
316    type Params = CreateMessageRequestParams;
317    type Result = CreateMessageResult;
318}
319
320#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
321pub struct CreateMessageRequestParams {
322    #[serde(
323        rename = "includeContext",
324        default,
325        skip_serializing_if = "Option::is_none"
326    )]
327    #[ts(optional)]
328    pub include_context: Option<String>,
329    #[serde(rename = "maxTokens")]
330    pub max_tokens: i64,
331    pub messages: Vec<SamplingMessage>,
332    #[serde(default, skip_serializing_if = "Option::is_none")]
333    #[ts(optional)]
334    pub metadata: Option<serde_json::Value>,
335    #[serde(
336        rename = "modelPreferences",
337        default,
338        skip_serializing_if = "Option::is_none"
339    )]
340    #[ts(optional)]
341    pub model_preferences: Option<ModelPreferences>,
342    #[serde(
343        rename = "stopSequences",
344        default,
345        skip_serializing_if = "Option::is_none"
346    )]
347    #[ts(optional)]
348    pub stop_sequences: Option<Vec<String>>,
349    #[serde(
350        rename = "systemPrompt",
351        default,
352        skip_serializing_if = "Option::is_none"
353    )]
354    #[ts(optional)]
355    pub system_prompt: Option<String>,
356    #[serde(default, skip_serializing_if = "Option::is_none")]
357    #[ts(optional)]
358    pub temperature: Option<f64>,
359}
360
361/// The client's response to a sampling/create_message request from the server. The client should inform the user before returning the sampled message, to allow them to inspect the response (human in the loop) and decide whether to allow the server to see it.
362#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
363pub struct CreateMessageResult {
364    pub content: CreateMessageResultContent,
365    pub model: String,
366    pub role: Role,
367    #[serde(
368        rename = "stopReason",
369        default,
370        skip_serializing_if = "Option::is_none"
371    )]
372    #[ts(optional)]
373    pub stop_reason: Option<String>,
374}
375
376#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
377#[serde(untagged)]
378pub enum CreateMessageResultContent {
379    TextContent(TextContent),
380    ImageContent(ImageContent),
381    AudioContent(AudioContent),
382}
383
384impl From<CreateMessageResult> for serde_json::Value {
385    fn from(value: CreateMessageResult) -> Self {
386        // Leave this as it should never fail
387        #[expect(clippy::unwrap_used)]
388        serde_json::to_value(value).unwrap()
389    }
390}
391
392#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
393pub struct Cursor(String);
394
395#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
396pub enum ElicitRequest {}
397
398impl ModelContextProtocolRequest for ElicitRequest {
399    const METHOD: &'static str = "elicitation/create";
400    type Params = ElicitRequestParams;
401    type Result = ElicitResult;
402}
403
404#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
405pub struct ElicitRequestParams {
406    pub message: String,
407    #[serde(rename = "requestedSchema")]
408    pub requested_schema: ElicitRequestParamsRequestedSchema,
409}
410
411/// A restricted subset of JSON Schema.
412/// Only top-level properties are allowed, without nesting.
413#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
414pub struct ElicitRequestParamsRequestedSchema {
415    pub properties: serde_json::Value,
416    #[serde(default, skip_serializing_if = "Option::is_none")]
417    #[ts(optional)]
418    pub required: Option<Vec<String>>,
419    pub r#type: String, // &'static str = "object"
420}
421
422/// The client's response to an elicitation request.
423#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
424pub struct ElicitResult {
425    pub action: String,
426    #[serde(default, skip_serializing_if = "Option::is_none")]
427    #[ts(optional)]
428    pub content: Option<serde_json::Value>,
429}
430
431impl From<ElicitResult> for serde_json::Value {
432    fn from(value: ElicitResult) -> Self {
433        // Leave this as it should never fail
434        #[expect(clippy::unwrap_used)]
435        serde_json::to_value(value).unwrap()
436    }
437}
438
439/// The contents of a resource, embedded into a prompt or tool call result.
440///
441/// It is up to the client how best to render embedded resources for the benefit
442/// of the LLM and/or the user.
443#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
444pub struct EmbeddedResource {
445    #[serde(default, skip_serializing_if = "Option::is_none")]
446    #[ts(optional)]
447    pub annotations: Option<Annotations>,
448    pub resource: EmbeddedResourceResource,
449    pub r#type: String, // &'static str = "resource"
450}
451
452#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
453#[serde(untagged)]
454pub enum EmbeddedResourceResource {
455    TextResourceContents(TextResourceContents),
456    BlobResourceContents(BlobResourceContents),
457}
458
459pub type EmptyResult = Result;
460
461#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
462pub struct EnumSchema {
463    #[serde(default, skip_serializing_if = "Option::is_none")]
464    #[ts(optional)]
465    pub description: Option<String>,
466    pub r#enum: Vec<String>,
467    #[serde(rename = "enumNames", default, skip_serializing_if = "Option::is_none")]
468    #[ts(optional)]
469    pub enum_names: Option<Vec<String>>,
470    #[serde(default, skip_serializing_if = "Option::is_none")]
471    #[ts(optional)]
472    pub title: Option<String>,
473    pub r#type: String, // &'static str = "string"
474}
475
476#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
477pub enum GetPromptRequest {}
478
479impl ModelContextProtocolRequest for GetPromptRequest {
480    const METHOD: &'static str = "prompts/get";
481    type Params = GetPromptRequestParams;
482    type Result = GetPromptResult;
483}
484
485#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
486pub struct GetPromptRequestParams {
487    #[serde(default, skip_serializing_if = "Option::is_none")]
488    #[ts(optional)]
489    pub arguments: Option<serde_json::Value>,
490    pub name: String,
491}
492
493/// The server's response to a prompts/get request from the client.
494#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
495pub struct GetPromptResult {
496    #[serde(default, skip_serializing_if = "Option::is_none")]
497    #[ts(optional)]
498    pub description: Option<String>,
499    pub messages: Vec<PromptMessage>,
500}
501
502impl From<GetPromptResult> for serde_json::Value {
503    fn from(value: GetPromptResult) -> Self {
504        // Leave this as it should never fail
505        #[expect(clippy::unwrap_used)]
506        serde_json::to_value(value).unwrap()
507    }
508}
509
510/// An image provided to or from an LLM.
511#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
512pub struct ImageContent {
513    #[serde(default, skip_serializing_if = "Option::is_none")]
514    #[ts(optional)]
515    pub annotations: Option<Annotations>,
516    pub data: String,
517    #[serde(rename = "mimeType")]
518    pub mime_type: String,
519    pub r#type: String, // &'static str = "image"
520}
521
522/// Describes the name and version of an MCP implementation, with an optional title for UI representation.
523#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
524pub struct Implementation {
525    pub name: String,
526    #[serde(default, skip_serializing_if = "Option::is_none")]
527    #[ts(optional)]
528    pub title: Option<String>,
529    pub version: String,
530    // This is an extra field that the Codex MCP server sends as part of InitializeResult.
531    #[serde(default, skip_serializing_if = "Option::is_none")]
532    #[ts(optional)]
533    pub user_agent: Option<String>,
534}
535
536#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
537pub enum InitializeRequest {}
538
539impl ModelContextProtocolRequest for InitializeRequest {
540    const METHOD: &'static str = "initialize";
541    type Params = InitializeRequestParams;
542    type Result = InitializeResult;
543}
544
545#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
546pub struct InitializeRequestParams {
547    pub capabilities: ClientCapabilities,
548    #[serde(rename = "clientInfo")]
549    pub client_info: Implementation,
550    #[serde(rename = "protocolVersion")]
551    pub protocol_version: String,
552}
553
554/// After receiving an initialize request from the client, the server sends this response.
555#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
556pub struct InitializeResult {
557    pub capabilities: ServerCapabilities,
558    #[serde(default, skip_serializing_if = "Option::is_none")]
559    #[ts(optional)]
560    pub instructions: Option<String>,
561    #[serde(rename = "protocolVersion")]
562    pub protocol_version: String,
563    #[serde(rename = "serverInfo")]
564    pub server_info: Implementation,
565}
566
567impl From<InitializeResult> for serde_json::Value {
568    fn from(value: InitializeResult) -> Self {
569        // Leave this as it should never fail
570        #[expect(clippy::unwrap_used)]
571        serde_json::to_value(value).unwrap()
572    }
573}
574
575#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
576pub enum InitializedNotification {}
577
578impl ModelContextProtocolNotification for InitializedNotification {
579    const METHOD: &'static str = "notifications/initialized";
580    type Params = Option<serde_json::Value>;
581}
582
583/// A response to a request that indicates an error occurred.
584#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
585pub struct JSONRPCError {
586    pub error: JSONRPCErrorError,
587    pub id: RequestId,
588    #[serde(rename = "jsonrpc", default = "default_jsonrpc")]
589    pub jsonrpc: String,
590}
591
592#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
593pub struct JSONRPCErrorError {
594    pub code: i64,
595    #[serde(default, skip_serializing_if = "Option::is_none")]
596    #[ts(optional)]
597    pub data: Option<serde_json::Value>,
598    pub message: String,
599}
600
601/// Refers to any valid JSON-RPC object that can be decoded off the wire, or encoded to be sent.
602#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
603#[serde(untagged)]
604pub enum JSONRPCMessage {
605    Request(JSONRPCRequest),
606    Notification(JSONRPCNotification),
607    Response(JSONRPCResponse),
608    Error(JSONRPCError),
609}
610
611/// A notification which does not expect a response.
612#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
613pub struct JSONRPCNotification {
614    #[serde(rename = "jsonrpc", default = "default_jsonrpc")]
615    pub jsonrpc: String,
616    pub method: String,
617    #[serde(default, skip_serializing_if = "Option::is_none")]
618    #[ts(optional)]
619    pub params: Option<serde_json::Value>,
620}
621
622/// A request that expects a response.
623#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
624pub struct JSONRPCRequest {
625    pub id: RequestId,
626    #[serde(rename = "jsonrpc", default = "default_jsonrpc")]
627    pub jsonrpc: String,
628    pub method: String,
629    #[serde(default, skip_serializing_if = "Option::is_none")]
630    #[ts(optional)]
631    pub params: Option<serde_json::Value>,
632}
633
634/// A successful (non-error) response to a request.
635#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
636pub struct JSONRPCResponse {
637    pub id: RequestId,
638    #[serde(rename = "jsonrpc", default = "default_jsonrpc")]
639    pub jsonrpc: String,
640    pub result: Result,
641}
642
643#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
644pub enum ListPromptsRequest {}
645
646impl ModelContextProtocolRequest for ListPromptsRequest {
647    const METHOD: &'static str = "prompts/list";
648    type Params = Option<ListPromptsRequestParams>;
649    type Result = ListPromptsResult;
650}
651
652#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
653pub struct ListPromptsRequestParams {
654    #[serde(default, skip_serializing_if = "Option::is_none")]
655    #[ts(optional)]
656    pub cursor: Option<String>,
657}
658
659/// The server's response to a prompts/list request from the client.
660#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
661pub struct ListPromptsResult {
662    #[serde(
663        rename = "nextCursor",
664        default,
665        skip_serializing_if = "Option::is_none"
666    )]
667    #[ts(optional)]
668    pub next_cursor: Option<String>,
669    pub prompts: Vec<Prompt>,
670}
671
672impl From<ListPromptsResult> for serde_json::Value {
673    fn from(value: ListPromptsResult) -> Self {
674        // Leave this as it should never fail
675        #[expect(clippy::unwrap_used)]
676        serde_json::to_value(value).unwrap()
677    }
678}
679
680#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
681pub enum ListResourceTemplatesRequest {}
682
683impl ModelContextProtocolRequest for ListResourceTemplatesRequest {
684    const METHOD: &'static str = "resources/templates/list";
685    type Params = Option<ListResourceTemplatesRequestParams>;
686    type Result = ListResourceTemplatesResult;
687}
688
689#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
690pub struct ListResourceTemplatesRequestParams {
691    #[serde(default, skip_serializing_if = "Option::is_none")]
692    #[ts(optional)]
693    pub cursor: Option<String>,
694}
695
696/// The server's response to a resources/templates/list request from the client.
697#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
698pub struct ListResourceTemplatesResult {
699    #[serde(
700        rename = "nextCursor",
701        default,
702        skip_serializing_if = "Option::is_none"
703    )]
704    #[ts(optional)]
705    pub next_cursor: Option<String>,
706    #[serde(rename = "resourceTemplates")]
707    pub resource_templates: Vec<ResourceTemplate>,
708}
709
710impl From<ListResourceTemplatesResult> for serde_json::Value {
711    fn from(value: ListResourceTemplatesResult) -> Self {
712        // Leave this as it should never fail
713        #[expect(clippy::unwrap_used)]
714        serde_json::to_value(value).unwrap()
715    }
716}
717
718#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
719pub enum ListResourcesRequest {}
720
721impl ModelContextProtocolRequest for ListResourcesRequest {
722    const METHOD: &'static str = "resources/list";
723    type Params = Option<ListResourcesRequestParams>;
724    type Result = ListResourcesResult;
725}
726
727#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
728pub struct ListResourcesRequestParams {
729    #[serde(default, skip_serializing_if = "Option::is_none")]
730    #[ts(optional)]
731    pub cursor: Option<String>,
732}
733
734/// The server's response to a resources/list request from the client.
735#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
736pub struct ListResourcesResult {
737    #[serde(
738        rename = "nextCursor",
739        default,
740        skip_serializing_if = "Option::is_none"
741    )]
742    #[ts(optional)]
743    pub next_cursor: Option<String>,
744    pub resources: Vec<Resource>,
745}
746
747impl From<ListResourcesResult> for serde_json::Value {
748    fn from(value: ListResourcesResult) -> Self {
749        // Leave this as it should never fail
750        #[expect(clippy::unwrap_used)]
751        serde_json::to_value(value).unwrap()
752    }
753}
754
755#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
756pub enum ListRootsRequest {}
757
758impl ModelContextProtocolRequest for ListRootsRequest {
759    const METHOD: &'static str = "roots/list";
760    type Params = Option<serde_json::Value>;
761    type Result = ListRootsResult;
762}
763
764/// The client's response to a roots/list request from the server.
765/// This result contains an array of Root objects, each representing a root directory
766/// or file that the server can operate on.
767#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
768pub struct ListRootsResult {
769    pub roots: Vec<Root>,
770}
771
772impl From<ListRootsResult> for serde_json::Value {
773    fn from(value: ListRootsResult) -> Self {
774        // Leave this as it should never fail
775        #[expect(clippy::unwrap_used)]
776        serde_json::to_value(value).unwrap()
777    }
778}
779
780#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
781pub enum ListToolsRequest {}
782
783impl ModelContextProtocolRequest for ListToolsRequest {
784    const METHOD: &'static str = "tools/list";
785    type Params = Option<ListToolsRequestParams>;
786    type Result = ListToolsResult;
787}
788
789#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
790pub struct ListToolsRequestParams {
791    #[serde(default, skip_serializing_if = "Option::is_none")]
792    #[ts(optional)]
793    pub cursor: Option<String>,
794}
795
796/// The server's response to a tools/list request from the client.
797#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
798pub struct ListToolsResult {
799    #[serde(
800        rename = "nextCursor",
801        default,
802        skip_serializing_if = "Option::is_none"
803    )]
804    #[ts(optional)]
805    pub next_cursor: Option<String>,
806    pub tools: Vec<Tool>,
807}
808
809impl From<ListToolsResult> for serde_json::Value {
810    fn from(value: ListToolsResult) -> Self {
811        // Leave this as it should never fail
812        #[expect(clippy::unwrap_used)]
813        serde_json::to_value(value).unwrap()
814    }
815}
816
817/// The severity of a log message.
818///
819/// These map to syslog message severities, as specified in RFC-5424:
820/// https://datatracker.ietf.org/doc/html/rfc5424#section-6.2.1
821#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
822pub enum LoggingLevel {
823    #[serde(rename = "alert")]
824    Alert,
825    #[serde(rename = "critical")]
826    Critical,
827    #[serde(rename = "debug")]
828    Debug,
829    #[serde(rename = "emergency")]
830    Emergency,
831    #[serde(rename = "error")]
832    Error,
833    #[serde(rename = "info")]
834    Info,
835    #[serde(rename = "notice")]
836    Notice,
837    #[serde(rename = "warning")]
838    Warning,
839}
840
841#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
842pub enum LoggingMessageNotification {}
843
844impl ModelContextProtocolNotification for LoggingMessageNotification {
845    const METHOD: &'static str = "notifications/message";
846    type Params = LoggingMessageNotificationParams;
847}
848
849#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
850pub struct LoggingMessageNotificationParams {
851    pub data: serde_json::Value,
852    pub level: LoggingLevel,
853    #[serde(default, skip_serializing_if = "Option::is_none")]
854    #[ts(optional)]
855    pub logger: Option<String>,
856}
857
858/// Hints to use for model selection.
859///
860/// Keys not declared here are currently left unspecified by the spec and are up
861/// to the client to interpret.
862#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
863pub struct ModelHint {
864    #[serde(default, skip_serializing_if = "Option::is_none")]
865    #[ts(optional)]
866    pub name: Option<String>,
867}
868
869/// The server's preferences for model selection, requested of the client during sampling.
870///
871/// Because LLMs can vary along multiple dimensions, choosing the "best" model is
872/// rarely straightforward.  Different models excel in different areas—some are
873/// faster but less capable, others are more capable but more expensive, and so
874/// on. This interface allows servers to express their priorities across multiple
875/// dimensions to help clients make an appropriate selection for their use case.
876///
877/// These preferences are always advisory. The client MAY ignore them. It is also
878/// up to the client to decide how to interpret these preferences and how to
879/// balance them against other considerations.
880#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
881pub struct ModelPreferences {
882    #[serde(
883        rename = "costPriority",
884        default,
885        skip_serializing_if = "Option::is_none"
886    )]
887    #[ts(optional)]
888    pub cost_priority: Option<f64>,
889    #[serde(default, skip_serializing_if = "Option::is_none")]
890    #[ts(optional)]
891    pub hints: Option<Vec<ModelHint>>,
892    #[serde(
893        rename = "intelligencePriority",
894        default,
895        skip_serializing_if = "Option::is_none"
896    )]
897    #[ts(optional)]
898    pub intelligence_priority: Option<f64>,
899    #[serde(
900        rename = "speedPriority",
901        default,
902        skip_serializing_if = "Option::is_none"
903    )]
904    #[ts(optional)]
905    pub speed_priority: Option<f64>,
906}
907
908#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
909pub struct Notification {
910    pub method: String,
911    #[serde(default, skip_serializing_if = "Option::is_none")]
912    #[ts(optional)]
913    pub params: Option<serde_json::Value>,
914}
915
916#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
917pub struct NumberSchema {
918    #[serde(default, skip_serializing_if = "Option::is_none")]
919    #[ts(optional)]
920    pub description: Option<String>,
921    #[serde(default, skip_serializing_if = "Option::is_none")]
922    #[ts(optional)]
923    pub maximum: Option<i64>,
924    #[serde(default, skip_serializing_if = "Option::is_none")]
925    #[ts(optional)]
926    pub minimum: Option<i64>,
927    #[serde(default, skip_serializing_if = "Option::is_none")]
928    #[ts(optional)]
929    pub title: Option<String>,
930    pub r#type: String,
931}
932
933#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
934pub struct PaginatedRequest {
935    pub method: String,
936    #[serde(default, skip_serializing_if = "Option::is_none")]
937    #[ts(optional)]
938    pub params: Option<PaginatedRequestParams>,
939}
940
941#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
942pub struct PaginatedRequestParams {
943    #[serde(default, skip_serializing_if = "Option::is_none")]
944    #[ts(optional)]
945    pub cursor: Option<String>,
946}
947
948#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
949pub struct PaginatedResult {
950    #[serde(
951        rename = "nextCursor",
952        default,
953        skip_serializing_if = "Option::is_none"
954    )]
955    #[ts(optional)]
956    pub next_cursor: Option<String>,
957}
958
959impl From<PaginatedResult> for serde_json::Value {
960    fn from(value: PaginatedResult) -> Self {
961        // Leave this as it should never fail
962        #[expect(clippy::unwrap_used)]
963        serde_json::to_value(value).unwrap()
964    }
965}
966
967#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
968pub enum PingRequest {}
969
970impl ModelContextProtocolRequest for PingRequest {
971    const METHOD: &'static str = "ping";
972    type Params = Option<serde_json::Value>;
973    type Result = Result;
974}
975
976/// Restricted schema definitions that only allow primitive types
977/// without nested objects or arrays.
978#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
979#[serde(untagged)]
980pub enum PrimitiveSchemaDefinition {
981    StringSchema(StringSchema),
982    NumberSchema(NumberSchema),
983    BooleanSchema(BooleanSchema),
984    EnumSchema(EnumSchema),
985}
986
987#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
988pub enum ProgressNotification {}
989
990impl ModelContextProtocolNotification for ProgressNotification {
991    const METHOD: &'static str = "notifications/progress";
992    type Params = ProgressNotificationParams;
993}
994
995#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
996pub struct ProgressNotificationParams {
997    #[serde(default, skip_serializing_if = "Option::is_none")]
998    #[ts(optional)]
999    pub message: Option<String>,
1000    pub progress: f64,
1001    #[serde(rename = "progressToken")]
1002    pub progress_token: ProgressToken,
1003    #[serde(default, skip_serializing_if = "Option::is_none")]
1004    #[ts(optional)]
1005    pub total: Option<f64>,
1006}
1007
1008#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Hash, Eq, JsonSchema, TS)]
1009#[serde(untagged)]
1010pub enum ProgressToken {
1011    String(String),
1012    Integer(i64),
1013}
1014
1015/// A prompt or prompt template that the server offers.
1016#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1017pub struct Prompt {
1018    #[serde(default, skip_serializing_if = "Option::is_none")]
1019    #[ts(optional)]
1020    pub arguments: Option<Vec<PromptArgument>>,
1021    #[serde(default, skip_serializing_if = "Option::is_none")]
1022    #[ts(optional)]
1023    pub description: Option<String>,
1024    pub name: String,
1025    #[serde(default, skip_serializing_if = "Option::is_none")]
1026    #[ts(optional)]
1027    pub title: Option<String>,
1028}
1029
1030/// Describes an argument that a prompt can accept.
1031#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1032pub struct PromptArgument {
1033    #[serde(default, skip_serializing_if = "Option::is_none")]
1034    #[ts(optional)]
1035    pub description: Option<String>,
1036    pub name: String,
1037    #[serde(default, skip_serializing_if = "Option::is_none")]
1038    #[ts(optional)]
1039    pub required: Option<bool>,
1040    #[serde(default, skip_serializing_if = "Option::is_none")]
1041    #[ts(optional)]
1042    pub title: Option<String>,
1043}
1044
1045#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1046pub enum PromptListChangedNotification {}
1047
1048impl ModelContextProtocolNotification for PromptListChangedNotification {
1049    const METHOD: &'static str = "notifications/prompts/list_changed";
1050    type Params = Option<serde_json::Value>;
1051}
1052
1053/// Describes a message returned as part of a prompt.
1054///
1055/// This is similar to `SamplingMessage`, but also supports the embedding of
1056/// resources from the MCP server.
1057#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1058pub struct PromptMessage {
1059    pub content: ContentBlock,
1060    pub role: Role,
1061}
1062
1063/// Identifies a prompt.
1064#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1065pub struct PromptReference {
1066    pub name: String,
1067    #[serde(default, skip_serializing_if = "Option::is_none")]
1068    #[ts(optional)]
1069    pub title: Option<String>,
1070    pub r#type: String, // &'static str = "ref/prompt"
1071}
1072
1073#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1074pub enum ReadResourceRequest {}
1075
1076impl ModelContextProtocolRequest for ReadResourceRequest {
1077    const METHOD: &'static str = "resources/read";
1078    type Params = ReadResourceRequestParams;
1079    type Result = ReadResourceResult;
1080}
1081
1082#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1083pub struct ReadResourceRequestParams {
1084    pub uri: String,
1085}
1086
1087/// The server's response to a resources/read request from the client.
1088#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1089pub struct ReadResourceResult {
1090    pub contents: Vec<ReadResourceResultContents>,
1091}
1092
1093#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1094#[serde(untagged)]
1095pub enum ReadResourceResultContents {
1096    TextResourceContents(TextResourceContents),
1097    BlobResourceContents(BlobResourceContents),
1098}
1099
1100impl From<ReadResourceResult> for serde_json::Value {
1101    fn from(value: ReadResourceResult) -> Self {
1102        // Leave this as it should never fail
1103        #[expect(clippy::unwrap_used)]
1104        serde_json::to_value(value).unwrap()
1105    }
1106}
1107
1108#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1109pub struct Request {
1110    pub method: String,
1111    #[serde(default, skip_serializing_if = "Option::is_none")]
1112    #[ts(optional)]
1113    pub params: Option<serde_json::Value>,
1114}
1115
1116#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Hash, Eq, JsonSchema, TS)]
1117#[serde(untagged)]
1118pub enum RequestId {
1119    String(String),
1120    Integer(i64),
1121}
1122
1123/// A known resource that the server is capable of reading.
1124#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1125pub struct Resource {
1126    #[serde(default, skip_serializing_if = "Option::is_none")]
1127    #[ts(optional)]
1128    pub annotations: Option<Annotations>,
1129    #[serde(default, skip_serializing_if = "Option::is_none")]
1130    #[ts(optional)]
1131    pub description: Option<String>,
1132    #[serde(rename = "mimeType", default, skip_serializing_if = "Option::is_none")]
1133    #[ts(optional)]
1134    pub mime_type: Option<String>,
1135    pub name: String,
1136    #[serde(default, skip_serializing_if = "Option::is_none")]
1137    #[ts(optional)]
1138    pub size: Option<i64>,
1139    #[serde(default, skip_serializing_if = "Option::is_none")]
1140    #[ts(optional)]
1141    pub title: Option<String>,
1142    pub uri: String,
1143}
1144
1145/// The contents of a specific resource or sub-resource.
1146#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1147pub struct ResourceContents {
1148    #[serde(rename = "mimeType", default, skip_serializing_if = "Option::is_none")]
1149    #[ts(optional)]
1150    pub mime_type: Option<String>,
1151    pub uri: String,
1152}
1153
1154/// A resource that the server is capable of reading, included in a prompt or tool call result.
1155///
1156/// Note: resource links returned by tools are not guaranteed to appear in the results of `resources/list` requests.
1157#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1158pub struct ResourceLink {
1159    #[serde(default, skip_serializing_if = "Option::is_none")]
1160    #[ts(optional)]
1161    pub annotations: Option<Annotations>,
1162    #[serde(default, skip_serializing_if = "Option::is_none")]
1163    #[ts(optional)]
1164    pub description: Option<String>,
1165    #[serde(rename = "mimeType", default, skip_serializing_if = "Option::is_none")]
1166    #[ts(optional)]
1167    pub mime_type: Option<String>,
1168    pub name: String,
1169    #[serde(default, skip_serializing_if = "Option::is_none")]
1170    #[ts(optional)]
1171    pub size: Option<i64>,
1172    #[serde(default, skip_serializing_if = "Option::is_none")]
1173    #[ts(optional)]
1174    pub title: Option<String>,
1175    pub r#type: String, // &'static str = "resource_link"
1176    pub uri: String,
1177}
1178
1179#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1180pub enum ResourceListChangedNotification {}
1181
1182impl ModelContextProtocolNotification for ResourceListChangedNotification {
1183    const METHOD: &'static str = "notifications/resources/list_changed";
1184    type Params = Option<serde_json::Value>;
1185}
1186
1187/// A template description for resources available on the server.
1188#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1189pub struct ResourceTemplate {
1190    #[serde(default, skip_serializing_if = "Option::is_none")]
1191    #[ts(optional)]
1192    pub annotations: Option<Annotations>,
1193    #[serde(default, skip_serializing_if = "Option::is_none")]
1194    #[ts(optional)]
1195    pub description: Option<String>,
1196    #[serde(rename = "mimeType", default, skip_serializing_if = "Option::is_none")]
1197    #[ts(optional)]
1198    pub mime_type: Option<String>,
1199    pub name: String,
1200    #[serde(default, skip_serializing_if = "Option::is_none")]
1201    #[ts(optional)]
1202    pub title: Option<String>,
1203    #[serde(rename = "uriTemplate")]
1204    pub uri_template: String,
1205}
1206
1207/// A reference to a resource or resource template definition.
1208#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1209pub struct ResourceTemplateReference {
1210    pub r#type: String, // &'static str = "ref/resource"
1211    pub uri: String,
1212}
1213
1214#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1215pub enum ResourceUpdatedNotification {}
1216
1217impl ModelContextProtocolNotification for ResourceUpdatedNotification {
1218    const METHOD: &'static str = "notifications/resources/updated";
1219    type Params = ResourceUpdatedNotificationParams;
1220}
1221
1222#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1223pub struct ResourceUpdatedNotificationParams {
1224    pub uri: String,
1225}
1226
1227pub type Result = serde_json::Value;
1228
1229/// The sender or recipient of messages and data in a conversation.
1230#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1231pub enum Role {
1232    #[serde(rename = "assistant")]
1233    Assistant,
1234    #[serde(rename = "user")]
1235    User,
1236}
1237
1238/// Represents a root directory or file that the server can operate on.
1239#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1240pub struct Root {
1241    #[serde(default, skip_serializing_if = "Option::is_none")]
1242    #[ts(optional)]
1243    pub name: Option<String>,
1244    pub uri: String,
1245}
1246
1247#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1248pub enum RootsListChangedNotification {}
1249
1250impl ModelContextProtocolNotification for RootsListChangedNotification {
1251    const METHOD: &'static str = "notifications/roots/list_changed";
1252    type Params = Option<serde_json::Value>;
1253}
1254
1255/// Describes a message issued to or received from an LLM API.
1256#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1257pub struct SamplingMessage {
1258    pub content: SamplingMessageContent,
1259    pub role: Role,
1260}
1261
1262#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1263#[serde(untagged)]
1264pub enum SamplingMessageContent {
1265    TextContent(TextContent),
1266    ImageContent(ImageContent),
1267    AudioContent(AudioContent),
1268}
1269
1270/// Capabilities that a server may support. Known capabilities are defined here, in this schema, but this is not a closed set: any server can define its own, additional capabilities.
1271#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1272pub struct ServerCapabilities {
1273    #[serde(default, skip_serializing_if = "Option::is_none")]
1274    #[ts(optional)]
1275    pub completions: Option<serde_json::Value>,
1276    #[serde(default, skip_serializing_if = "Option::is_none")]
1277    #[ts(optional)]
1278    pub experimental: Option<serde_json::Value>,
1279    #[serde(default, skip_serializing_if = "Option::is_none")]
1280    #[ts(optional)]
1281    pub logging: Option<serde_json::Value>,
1282    #[serde(default, skip_serializing_if = "Option::is_none")]
1283    #[ts(optional)]
1284    pub prompts: Option<ServerCapabilitiesPrompts>,
1285    #[serde(default, skip_serializing_if = "Option::is_none")]
1286    #[ts(optional)]
1287    pub resources: Option<ServerCapabilitiesResources>,
1288    #[serde(default, skip_serializing_if = "Option::is_none")]
1289    #[ts(optional)]
1290    pub tools: Option<ServerCapabilitiesTools>,
1291}
1292
1293/// Present if the server offers any tools to call.
1294#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1295pub struct ServerCapabilitiesTools {
1296    #[serde(
1297        rename = "listChanged",
1298        default,
1299        skip_serializing_if = "Option::is_none"
1300    )]
1301    #[ts(optional)]
1302    pub list_changed: Option<bool>,
1303}
1304
1305/// Present if the server offers any resources to read.
1306#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1307pub struct ServerCapabilitiesResources {
1308    #[serde(
1309        rename = "listChanged",
1310        default,
1311        skip_serializing_if = "Option::is_none"
1312    )]
1313    #[ts(optional)]
1314    pub list_changed: Option<bool>,
1315    #[serde(default, skip_serializing_if = "Option::is_none")]
1316    #[ts(optional)]
1317    pub subscribe: Option<bool>,
1318}
1319
1320/// Present if the server offers any prompt templates.
1321#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1322pub struct ServerCapabilitiesPrompts {
1323    #[serde(
1324        rename = "listChanged",
1325        default,
1326        skip_serializing_if = "Option::is_none"
1327    )]
1328    #[ts(optional)]
1329    pub list_changed: Option<bool>,
1330}
1331
1332#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1333#[serde(tag = "method", content = "params")]
1334pub enum ServerNotification {
1335    #[serde(rename = "notifications/cancelled")]
1336    CancelledNotification(<CancelledNotification as ModelContextProtocolNotification>::Params),
1337    #[serde(rename = "notifications/progress")]
1338    ProgressNotification(<ProgressNotification as ModelContextProtocolNotification>::Params),
1339    #[serde(rename = "notifications/resources/list_changed")]
1340    ResourceListChangedNotification(
1341        <ResourceListChangedNotification as ModelContextProtocolNotification>::Params,
1342    ),
1343    #[serde(rename = "notifications/resources/updated")]
1344    ResourceUpdatedNotification(
1345        <ResourceUpdatedNotification as ModelContextProtocolNotification>::Params,
1346    ),
1347    #[serde(rename = "notifications/prompts/list_changed")]
1348    PromptListChangedNotification(
1349        <PromptListChangedNotification as ModelContextProtocolNotification>::Params,
1350    ),
1351    #[serde(rename = "notifications/tools/list_changed")]
1352    ToolListChangedNotification(
1353        <ToolListChangedNotification as ModelContextProtocolNotification>::Params,
1354    ),
1355    #[serde(rename = "notifications/message")]
1356    LoggingMessageNotification(
1357        <LoggingMessageNotification as ModelContextProtocolNotification>::Params,
1358    ),
1359}
1360
1361#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1362#[serde(untagged)]
1363pub enum ServerRequest {
1364    PingRequest(PingRequest),
1365    CreateMessageRequest(CreateMessageRequest),
1366    ListRootsRequest(ListRootsRequest),
1367    ElicitRequest(ElicitRequest),
1368}
1369
1370#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1371#[serde(untagged)]
1372#[allow(clippy::large_enum_variant)]
1373pub enum ServerResult {
1374    Result(Result),
1375    InitializeResult(InitializeResult),
1376    ListResourcesResult(ListResourcesResult),
1377    ListResourceTemplatesResult(ListResourceTemplatesResult),
1378    ReadResourceResult(ReadResourceResult),
1379    ListPromptsResult(ListPromptsResult),
1380    GetPromptResult(GetPromptResult),
1381    ListToolsResult(ListToolsResult),
1382    CallToolResult(CallToolResult),
1383    CompleteResult(CompleteResult),
1384}
1385
1386#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1387pub enum SetLevelRequest {}
1388
1389impl ModelContextProtocolRequest for SetLevelRequest {
1390    const METHOD: &'static str = "logging/setLevel";
1391    type Params = SetLevelRequestParams;
1392    type Result = Result;
1393}
1394
1395#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1396pub struct SetLevelRequestParams {
1397    pub level: LoggingLevel,
1398}
1399
1400#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1401pub struct StringSchema {
1402    #[serde(default, skip_serializing_if = "Option::is_none")]
1403    #[ts(optional)]
1404    pub description: Option<String>,
1405    #[serde(default, skip_serializing_if = "Option::is_none")]
1406    #[ts(optional)]
1407    pub format: Option<String>,
1408    #[serde(rename = "maxLength", default, skip_serializing_if = "Option::is_none")]
1409    #[ts(optional)]
1410    pub max_length: Option<i64>,
1411    #[serde(rename = "minLength", default, skip_serializing_if = "Option::is_none")]
1412    #[ts(optional)]
1413    pub min_length: Option<i64>,
1414    #[serde(default, skip_serializing_if = "Option::is_none")]
1415    #[ts(optional)]
1416    pub title: Option<String>,
1417    pub r#type: String, // &'static str = "string"
1418}
1419
1420#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1421pub enum SubscribeRequest {}
1422
1423impl ModelContextProtocolRequest for SubscribeRequest {
1424    const METHOD: &'static str = "resources/subscribe";
1425    type Params = SubscribeRequestParams;
1426    type Result = Result;
1427}
1428
1429#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1430pub struct SubscribeRequestParams {
1431    pub uri: String,
1432}
1433
1434/// Text provided to or from an LLM.
1435#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1436pub struct TextContent {
1437    #[serde(default, skip_serializing_if = "Option::is_none")]
1438    #[ts(optional)]
1439    pub annotations: Option<Annotations>,
1440    pub text: String,
1441    pub r#type: String, // &'static str = "text"
1442}
1443
1444#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1445pub struct TextResourceContents {
1446    #[serde(rename = "mimeType", default, skip_serializing_if = "Option::is_none")]
1447    #[ts(optional)]
1448    pub mime_type: Option<String>,
1449    pub text: String,
1450    pub uri: String,
1451}
1452
1453/// Definition for a tool the client can call.
1454#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1455pub struct Tool {
1456    #[serde(default, skip_serializing_if = "Option::is_none")]
1457    #[ts(optional)]
1458    pub annotations: Option<ToolAnnotations>,
1459    #[serde(default, skip_serializing_if = "Option::is_none")]
1460    #[ts(optional)]
1461    pub description: Option<String>,
1462    #[serde(rename = "inputSchema")]
1463    pub input_schema: ToolInputSchema,
1464    pub name: String,
1465    #[serde(
1466        rename = "outputSchema",
1467        default,
1468        skip_serializing_if = "Option::is_none"
1469    )]
1470    #[ts(optional)]
1471    pub output_schema: Option<ToolOutputSchema>,
1472    #[serde(default, skip_serializing_if = "Option::is_none")]
1473    #[ts(optional)]
1474    pub title: Option<String>,
1475}
1476
1477/// An optional JSON Schema object defining the structure of the tool's output returned in
1478/// the structuredContent field of a CallToolResult.
1479#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1480pub struct ToolOutputSchema {
1481    #[serde(default, skip_serializing_if = "Option::is_none")]
1482    #[ts(optional)]
1483    pub properties: Option<serde_json::Value>,
1484    #[serde(default, skip_serializing_if = "Option::is_none")]
1485    #[ts(optional)]
1486    pub required: Option<Vec<String>>,
1487    pub r#type: String, // &'static str = "object"
1488}
1489
1490/// A JSON Schema object defining the expected parameters for the tool.
1491#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1492pub struct ToolInputSchema {
1493    #[serde(default, skip_serializing_if = "Option::is_none")]
1494    #[ts(optional)]
1495    pub properties: Option<serde_json::Value>,
1496    #[serde(default, skip_serializing_if = "Option::is_none")]
1497    #[ts(optional)]
1498    pub required: Option<Vec<String>>,
1499    pub r#type: String, // &'static str = "object"
1500}
1501
1502/// Additional properties describing a Tool to clients.
1503///
1504/// NOTE: all properties in ToolAnnotations are **hints**.
1505/// They are not guaranteed to provide a faithful description of
1506/// tool behavior (including descriptive properties like `title`).
1507///
1508/// Clients should never make tool use decisions based on ToolAnnotations
1509/// received from untrusted servers.
1510#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1511pub struct ToolAnnotations {
1512    #[serde(
1513        rename = "destructiveHint",
1514        default,
1515        skip_serializing_if = "Option::is_none"
1516    )]
1517    #[ts(optional)]
1518    pub destructive_hint: Option<bool>,
1519    #[serde(
1520        rename = "idempotentHint",
1521        default,
1522        skip_serializing_if = "Option::is_none"
1523    )]
1524    #[ts(optional)]
1525    pub idempotent_hint: Option<bool>,
1526    #[serde(
1527        rename = "openWorldHint",
1528        default,
1529        skip_serializing_if = "Option::is_none"
1530    )]
1531    #[ts(optional)]
1532    pub open_world_hint: Option<bool>,
1533    #[serde(
1534        rename = "readOnlyHint",
1535        default,
1536        skip_serializing_if = "Option::is_none"
1537    )]
1538    #[ts(optional)]
1539    pub read_only_hint: Option<bool>,
1540    #[serde(default, skip_serializing_if = "Option::is_none")]
1541    #[ts(optional)]
1542    pub title: Option<String>,
1543}
1544
1545#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1546pub enum ToolListChangedNotification {}
1547
1548impl ModelContextProtocolNotification for ToolListChangedNotification {
1549    const METHOD: &'static str = "notifications/tools/list_changed";
1550    type Params = Option<serde_json::Value>;
1551}
1552
1553#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1554pub enum UnsubscribeRequest {}
1555
1556impl ModelContextProtocolRequest for UnsubscribeRequest {
1557    const METHOD: &'static str = "resources/unsubscribe";
1558    type Params = UnsubscribeRequestParams;
1559    type Result = Result;
1560}
1561
1562#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
1563pub struct UnsubscribeRequestParams {
1564    pub uri: String,
1565}
1566
1567impl TryFrom<JSONRPCRequest> for ClientRequest {
1568    type Error = serde_json::Error;
1569    fn try_from(req: JSONRPCRequest) -> std::result::Result<Self, Self::Error> {
1570        match req.method.as_str() {
1571            "initialize" => {
1572                let params_json = req.params.unwrap_or(serde_json::Value::Null);
1573                let params: <InitializeRequest as ModelContextProtocolRequest>::Params =
1574                    serde_json::from_value(params_json)?;
1575                Ok(ClientRequest::InitializeRequest(params))
1576            }
1577            "ping" => {
1578                let params_json = req.params.unwrap_or(serde_json::Value::Null);
1579                let params: <PingRequest as ModelContextProtocolRequest>::Params =
1580                    serde_json::from_value(params_json)?;
1581                Ok(ClientRequest::PingRequest(params))
1582            }
1583            "resources/list" => {
1584                let params_json = req.params.unwrap_or(serde_json::Value::Null);
1585                let params: <ListResourcesRequest as ModelContextProtocolRequest>::Params =
1586                    serde_json::from_value(params_json)?;
1587                Ok(ClientRequest::ListResourcesRequest(params))
1588            }
1589            "resources/templates/list" => {
1590                let params_json = req.params.unwrap_or(serde_json::Value::Null);
1591                let params: <ListResourceTemplatesRequest as ModelContextProtocolRequest>::Params =
1592                    serde_json::from_value(params_json)?;
1593                Ok(ClientRequest::ListResourceTemplatesRequest(params))
1594            }
1595            "resources/read" => {
1596                let params_json = req.params.unwrap_or(serde_json::Value::Null);
1597                let params: <ReadResourceRequest as ModelContextProtocolRequest>::Params =
1598                    serde_json::from_value(params_json)?;
1599                Ok(ClientRequest::ReadResourceRequest(params))
1600            }
1601            "resources/subscribe" => {
1602                let params_json = req.params.unwrap_or(serde_json::Value::Null);
1603                let params: <SubscribeRequest as ModelContextProtocolRequest>::Params =
1604                    serde_json::from_value(params_json)?;
1605                Ok(ClientRequest::SubscribeRequest(params))
1606            }
1607            "resources/unsubscribe" => {
1608                let params_json = req.params.unwrap_or(serde_json::Value::Null);
1609                let params: <UnsubscribeRequest as ModelContextProtocolRequest>::Params =
1610                    serde_json::from_value(params_json)?;
1611                Ok(ClientRequest::UnsubscribeRequest(params))
1612            }
1613            "prompts/list" => {
1614                let params_json = req.params.unwrap_or(serde_json::Value::Null);
1615                let params: <ListPromptsRequest as ModelContextProtocolRequest>::Params =
1616                    serde_json::from_value(params_json)?;
1617                Ok(ClientRequest::ListPromptsRequest(params))
1618            }
1619            "prompts/get" => {
1620                let params_json = req.params.unwrap_or(serde_json::Value::Null);
1621                let params: <GetPromptRequest as ModelContextProtocolRequest>::Params =
1622                    serde_json::from_value(params_json)?;
1623                Ok(ClientRequest::GetPromptRequest(params))
1624            }
1625            "tools/list" => {
1626                let params_json = req.params.unwrap_or(serde_json::Value::Null);
1627                let params: <ListToolsRequest as ModelContextProtocolRequest>::Params =
1628                    serde_json::from_value(params_json)?;
1629                Ok(ClientRequest::ListToolsRequest(params))
1630            }
1631            "tools/call" => {
1632                let params_json = req.params.unwrap_or(serde_json::Value::Null);
1633                let params: <CallToolRequest as ModelContextProtocolRequest>::Params =
1634                    serde_json::from_value(params_json)?;
1635                Ok(ClientRequest::CallToolRequest(params))
1636            }
1637            "logging/setLevel" => {
1638                let params_json = req.params.unwrap_or(serde_json::Value::Null);
1639                let params: <SetLevelRequest as ModelContextProtocolRequest>::Params =
1640                    serde_json::from_value(params_json)?;
1641                Ok(ClientRequest::SetLevelRequest(params))
1642            }
1643            "completion/complete" => {
1644                let params_json = req.params.unwrap_or(serde_json::Value::Null);
1645                let params: <CompleteRequest as ModelContextProtocolRequest>::Params =
1646                    serde_json::from_value(params_json)?;
1647                Ok(ClientRequest::CompleteRequest(params))
1648            }
1649            _ => Err(serde_json::Error::io(std::io::Error::new(
1650                std::io::ErrorKind::InvalidData,
1651                format!("Unknown method: {}", req.method),
1652            ))),
1653        }
1654    }
1655}
1656
1657impl TryFrom<JSONRPCNotification> for ServerNotification {
1658    type Error = serde_json::Error;
1659    fn try_from(n: JSONRPCNotification) -> std::result::Result<Self, Self::Error> {
1660        match n.method.as_str() {
1661            "notifications/cancelled" => {
1662                let params_json = n.params.unwrap_or(serde_json::Value::Null);
1663                let params: <CancelledNotification as ModelContextProtocolNotification>::Params =
1664                    serde_json::from_value(params_json)?;
1665                Ok(ServerNotification::CancelledNotification(params))
1666            }
1667            "notifications/progress" => {
1668                let params_json = n.params.unwrap_or(serde_json::Value::Null);
1669                let params: <ProgressNotification as ModelContextProtocolNotification>::Params =
1670                    serde_json::from_value(params_json)?;
1671                Ok(ServerNotification::ProgressNotification(params))
1672            }
1673            "notifications/resources/list_changed" => {
1674                let params_json = n.params.unwrap_or(serde_json::Value::Null);
1675                let params: <ResourceListChangedNotification as ModelContextProtocolNotification>::Params = serde_json::from_value(params_json)?;
1676                Ok(ServerNotification::ResourceListChangedNotification(params))
1677            }
1678            "notifications/resources/updated" => {
1679                let params_json = n.params.unwrap_or(serde_json::Value::Null);
1680                let params: <ResourceUpdatedNotification as ModelContextProtocolNotification>::Params = serde_json::from_value(params_json)?;
1681                Ok(ServerNotification::ResourceUpdatedNotification(params))
1682            }
1683            "notifications/prompts/list_changed" => {
1684                let params_json = n.params.unwrap_or(serde_json::Value::Null);
1685                let params: <PromptListChangedNotification as ModelContextProtocolNotification>::Params = serde_json::from_value(params_json)?;
1686                Ok(ServerNotification::PromptListChangedNotification(params))
1687            }
1688            "notifications/tools/list_changed" => {
1689                let params_json = n.params.unwrap_or(serde_json::Value::Null);
1690                let params: <ToolListChangedNotification as ModelContextProtocolNotification>::Params = serde_json::from_value(params_json)?;
1691                Ok(ServerNotification::ToolListChangedNotification(params))
1692            }
1693            "notifications/message" => {
1694                let params_json = n.params.unwrap_or(serde_json::Value::Null);
1695                let params: <LoggingMessageNotification as ModelContextProtocolNotification>::Params = serde_json::from_value(params_json)?;
1696                Ok(ServerNotification::LoggingMessageNotification(params))
1697            }
1698            _ => Err(serde_json::Error::io(std::io::Error::new(
1699                std::io::ErrorKind::InvalidData,
1700                format!("Unknown method: {}", n.method),
1701            ))),
1702        }
1703    }
1704}