feat(meta): add _meta field to prompts, resources and paginated result (#558)

This commit is contained in:
Pavel Bezglasny 2025-12-04 02:38:47 +01:00 • committed by GitHub
commit 81411fc12d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 195 additions and 8 deletions

View file

@ -102,7 +102,7 @@ where
let tools = self.tool_router.list_all();
Ok(ServerResult::ListToolsResult(ListToolsResult {
tools,
next_cursor: None,
..Default::default()
}))
}
ClientRequest::GetPromptRequest(request) => {
@ -125,7 +125,7 @@ where
let prompts = self.prompt_router.list_all();
Ok(ServerResult::ListPromptsResult(ListPromptsResult {
prompts,
next_cursor: None,
..Default::default()
}))
}
rest => self.service.handle_request(rest, context).await,

View file

@ -828,6 +828,8 @@ macro_rules! paginated_result {
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct $t {
#[serde(rename = "_meta", skip_serializing_if = "Option::is_none")]
pub meta: Option<Meta>,
#[serde(skip_serializing_if = "Option::is_none")]
pub next_cursor: Option<Cursor>,
pub $i_item: $t_item,
@ -838,6 +840,7 @@ macro_rules! paginated_result {
items: $t_item,
) -> Self {
Self {
meta: None,
next_cursor: None,
$i_item: items,
}

View file

@ -258,6 +258,7 @@ mod tests {
mime_type: Some("text/plain".to_string()),
size: Some(100),
icons: None,
meta: None,
});
let json = serde_json::to_string(&resource_link).unwrap();

View file

@ -2,7 +2,7 @@ use base64::engine::{Engine, general_purpose::STANDARD as BASE64_STANDARD};
use serde::{Deserialize, Serialize};
use super::{
AnnotateAble, Annotations, Icon, RawEmbeddedResource, RawImageContent,
AnnotateAble, Annotations, Icon, Meta, RawEmbeddedResource, RawImageContent,
content::{EmbeddedResource, ImageContent},
resource::ResourceContents,
};
@ -25,6 +25,9 @@ pub struct Prompt {
/// Optional list of icons for the prompt
#[serde(skip_serializing_if = "Option::is_none")]
pub icons: Option<Vec<Icon>>,
/// Optional additional metadata for this prompt
#[serde(rename = "_meta", skip_serializing_if = "Option::is_none")]
pub meta: Option<Meta>,
}
impl Prompt {
@ -44,6 +47,7 @@ impl Prompt {
description: description.map(Into::into),
arguments,
icons: None,
meta: None,
}
}
}

View file

@ -29,6 +29,9 @@ pub struct RawResource {
/// Optional list of icons for the resource
#[serde(skip_serializing_if = "Option::is_none")]
pub icons: Option<Vec<Icon>>,
/// Optional additional metadata for this resource
#[serde(rename = "_meta", skip_serializing_if = "Option::is_none")]
pub meta: Option<Meta>,
}
pub type Resource = Annotated<RawResource>;
@ -95,6 +98,7 @@ impl RawResource {
mime_type: None,
size: None,
icons: None,
meta: None,
}
}
}
@ -115,6 +119,7 @@ mod tests {
mime_type: Some("text/plain".to_string()),
size: Some(100),
icons: None,
meta: None,
};
let json = serde_json::to_string(&resource).unwrap();