feat!: align model types with MCP 2025-11-25 spec (#927)
* feat!: align model types with MCP 2025-11-25 spec * fix: complete 2025-11-25 model spec conformance
This commit is contained in:
parent
42a1069833
commit
77932141e3
1 changed files with 4321 additions and 3886 deletions
|
|
@ -1,26 +1,23 @@
|
|||
use rmcp::model::{AnnotateAble, Content, Meta, RawContent, ResourceContents};
|
||||
use rmcp::model::{ContentBlock, EmbeddedResource, Meta, ResourceContents};
|
||||
use serde_json::json;
|
||||
|
||||
#[test]
|
||||
fn serialize_embedded_text_resource_with_meta() {
|
||||
// Inner contents meta
|
||||
let mut resource_content_meta = Meta::new();
|
||||
resource_content_meta.insert("inner".to_string(), json!(2));
|
||||
|
||||
// Top-level embedded resource meta
|
||||
let mut resource_meta = Meta::new();
|
||||
resource_meta.insert("top".to_string(), json!(1));
|
||||
|
||||
let content: Content = RawContent::Resource(rmcp::model::RawEmbeddedResource {
|
||||
meta: Some(resource_meta),
|
||||
resource: ResourceContents::TextResourceContents {
|
||||
let content = ContentBlock::Resource(
|
||||
EmbeddedResource::new(ResourceContents::TextResourceContents {
|
||||
uri: "str://example".to_string(),
|
||||
mime_type: Some("text/plain".to_string()),
|
||||
text: "hello".to_string(),
|
||||
meta: Some(resource_content_meta),
|
||||
},
|
||||
})
|
||||
.no_annotation();
|
||||
})
|
||||
.with_meta(resource_meta),
|
||||
);
|
||||
|
||||
let v = serde_json::to_value(&content).unwrap();
|
||||
|
||||
|
|
@ -40,16 +37,14 @@ fn serialize_embedded_text_resource_with_meta() {
|
|||
|
||||
#[test]
|
||||
fn serialize_embedded_text_resource_without_meta_omits_fields() {
|
||||
let content: Content = RawContent::Resource(rmcp::model::RawEmbeddedResource {
|
||||
meta: None,
|
||||
resource: ResourceContents::TextResourceContents {
|
||||
let content = ContentBlock::Resource(EmbeddedResource::new(
|
||||
ResourceContents::TextResourceContents {
|
||||
uri: "str://no-meta".to_string(),
|
||||
mime_type: Some("text/plain".to_string()),
|
||||
text: "hi".to_string(),
|
||||
meta: None,
|
||||
},
|
||||
})
|
||||
.no_annotation();
|
||||
));
|
||||
|
||||
let v = serde_json::to_value(&content).unwrap();
|
||||
|
||||
|
|
@ -70,19 +65,17 @@ fn deserialize_embedded_text_resource_with_meta() {
|
|||
}
|
||||
});
|
||||
|
||||
let content: Content = serde_json::from_value(raw).unwrap();
|
||||
let content: ContentBlock = serde_json::from_value(raw).unwrap();
|
||||
|
||||
let raw = match &content.raw {
|
||||
RawContent::Resource(er) => er,
|
||||
let er = match &content {
|
||||
ContentBlock::Resource(er) => er,
|
||||
_ => panic!("expected resource"),
|
||||
};
|
||||
|
||||
// top-level _meta
|
||||
let top = raw.meta.as_ref().expect("top-level meta missing");
|
||||
let top = er.meta.as_ref().expect("top-level meta missing");
|
||||
assert_eq!(top.get("x").unwrap(), &json!(true));
|
||||
|
||||
// inner contents _meta
|
||||
match &raw.resource {
|
||||
match &er.resource {
|
||||
ResourceContents::TextResourceContents {
|
||||
meta, uri, text, ..
|
||||
} => {
|
||||
|
|
@ -103,16 +96,15 @@ fn serialize_embedded_blob_resource_with_meta() {
|
|||
let mut resource_meta = Meta::new();
|
||||
resource_meta.insert("blob_top".to_string(), json!("t"));
|
||||
|
||||
let content: Content = RawContent::Resource(rmcp::model::RawEmbeddedResource {
|
||||
meta: Some(resource_meta),
|
||||
resource: ResourceContents::BlobResourceContents {
|
||||
let content = ContentBlock::Resource(
|
||||
EmbeddedResource::new(ResourceContents::BlobResourceContents {
|
||||
uri: "str://blob".to_string(),
|
||||
mime_type: Some("application/octet-stream".to_string()),
|
||||
blob: "Zm9v".to_string(),
|
||||
meta: Some(resource_content_meta),
|
||||
},
|
||||
})
|
||||
.no_annotation();
|
||||
})
|
||||
.with_meta(resource_meta),
|
||||
);
|
||||
|
||||
let v = serde_json::to_value(&content).unwrap();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue