agent_client_protocol/
mcp_types.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
5#[serde(tag = "type", rename_all = "snake_case")]
6pub enum ContentBlock {
7    Text(TextContent),
8    Image(ImageContent),
9    Audio(AudioContent),
10    ResourceLink(ResourceLink),
11    Resource(EmbeddedResource),
12}
13
14/// Text provided to or from an LLM.
15#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
16pub struct TextContent {
17    #[serde(default, skip_serializing_if = "Option::is_none")]
18    pub annotations: Option<Annotations>,
19    pub text: String,
20}
21
22impl<T: Into<String>> From<T> for ContentBlock {
23    fn from(value: T) -> Self {
24        Self::Text(TextContent {
25            annotations: None,
26            text: value.into(),
27        })
28    }
29}
30
31/// An image provided to or from an LLM.
32#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
33pub struct ImageContent {
34    #[serde(default, skip_serializing_if = "Option::is_none")]
35    pub annotations: Option<Annotations>,
36    pub data: String,
37    #[serde(rename = "mimeType")]
38    pub mime_type: String,
39}
40
41/// Audio provided to or from an LLM.
42#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
43pub struct AudioContent {
44    #[serde(default, skip_serializing_if = "Option::is_none")]
45    pub annotations: Option<Annotations>,
46    pub data: String,
47    #[serde(rename = "mimeType")]
48    pub mime_type: String,
49}
50
51/// The contents of a resource, embedded into a prompt or tool call result.
52///
53/// It is up to the client how best to render embedded resources for the benefit
54/// of the LLM and/or the user.
55#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
56pub struct EmbeddedResource {
57    #[serde(default, skip_serializing_if = "Option::is_none")]
58    pub annotations: Option<Annotations>,
59    pub resource: EmbeddedResourceResource,
60}
61
62#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
63#[serde(untagged)]
64pub enum EmbeddedResourceResource {
65    TextResourceContents(TextResourceContents),
66    BlobResourceContents(BlobResourceContents),
67}
68
69#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
70pub struct TextResourceContents {
71    #[serde(rename = "mimeType", default, skip_serializing_if = "Option::is_none")]
72    pub mime_type: Option<String>,
73    pub text: String,
74    pub uri: String,
75}
76
77#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
78pub struct BlobResourceContents {
79    pub blob: String,
80    #[serde(rename = "mimeType", default, skip_serializing_if = "Option::is_none")]
81    pub mime_type: Option<String>,
82    pub uri: String,
83}
84
85/// A resource that the server is capable of reading, included in a prompt or tool call result.
86///
87/// Note: resource links returned by tools are not guaranteed to appear in the results of `resources/list` requests.
88#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
89pub struct ResourceLink {
90    #[serde(default, skip_serializing_if = "Option::is_none")]
91    pub annotations: Option<Annotations>,
92    #[serde(default, skip_serializing_if = "Option::is_none")]
93    pub description: Option<String>,
94    #[serde(rename = "mimeType", default, skip_serializing_if = "Option::is_none")]
95    pub mime_type: Option<String>,
96    pub name: String,
97    #[serde(default, skip_serializing_if = "Option::is_none")]
98    pub size: Option<i64>,
99    #[serde(default, skip_serializing_if = "Option::is_none")]
100    pub title: Option<String>,
101    pub uri: String,
102}
103
104/// Optional annotations for the client. The client can use annotations to inform how objects are used or displayed
105#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
106pub struct Annotations {
107    #[serde(default, skip_serializing_if = "Option::is_none")]
108    pub audience: Option<Vec<Role>>,
109    #[serde(
110        rename = "lastModified",
111        default,
112        skip_serializing_if = "Option::is_none"
113    )]
114    pub last_modified: Option<String>,
115    #[serde(default, skip_serializing_if = "Option::is_none")]
116    pub priority: Option<f64>,
117}
118
119/// The sender or recipient of messages and data in a conversation.
120#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
121pub enum Role {
122    #[serde(rename = "assistant")]
123    Assistant,
124    #[serde(rename = "user")]
125    User,
126}