fix(rmcp): flatten Resource variant of PromptMessageContent (#843)

The Resource variant of PromptMessageContent was missing #[serde(flatten)],
causing the embedded resource content block to serialize as a double-nested
shape `{ "type": "resource", "resource": { "resource": {...} } }` instead of
the spec-compliant flat shape `{ "type": "resource", "resource": {uri, mimeType, text} }`.

This caused Zod-based MCP clients (e.g. Claude Code) to reject prompts/get
responses containing embedded resource messages with InvalidUnion errors.

The Image and ResourceLink variants already use #[serde(flatten)] correctly;
only Resource was missing it.

Fix: add #[serde(flatten)] so EmbeddedResource (=Annotated<RawEmbeddedResource>)
fields _meta / annotations / resource are flattened to the content-block level,
matching the MCP spec for prompts embedded resources.

Regression test: test_prompt_message_resource_serialization_is_flat verifies
content.resource.uri is reachable and content.resource.resource is absent.

Schema snapshots regenerated via UPDATE_SCHEMA=1.
This commit is contained in:
Yutaka Nishimura 2026-05-13 03:46:12 +09:00 • committed by GitHub
commit d83b1566d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 99 additions and 67 deletions

View file

@ -140,35 +140,6 @@
]
},
"Annotated2": {
"type": "object",
"properties": {
"_meta": {
"description": "Optional protocol-level metadata for this content block",
"type": [
"object",
"null"
],
"additionalProperties": true
},
"annotations": {
"anyOf": [
{
"$ref": "#/definitions/Annotations"
},
{
"type": "null"
}
]
},
"resource": {
"$ref": "#/definitions/ResourceContents"
}
},
"required": [
"resource"
]
},
"Annotated3": {
"description": "Represents a resource in the extension with metadata",
"type": "object",
"properties": {
@ -244,7 +215,7 @@
"name"
]
},
"Annotated4": {
"Annotated3": {
"type": "object",
"properties": {
"annotations": {
@ -1481,7 +1452,7 @@
"resourceTemplates": {
"type": "array",
"items": {
"$ref": "#/definitions/Annotated4"
"$ref": "#/definitions/Annotated3"
}
}
},
@ -1508,7 +1479,7 @@
"resources": {
"type": "array",
"items": {
"$ref": "#/definitions/Annotated3"
"$ref": "#/definitions/Annotated2"
}
}
},
@ -2148,8 +2119,26 @@
"description": "Embedded server-side resource",
"type": "object",
"properties": {
"_meta": {
"description": "Optional protocol-level metadata for this content block",
"type": [
"object",
"null"
],
"additionalProperties": true
},
"annotations": {
"anyOf": [
{
"$ref": "#/definitions/Annotations"
},
{
"type": "null"
}
]
},
"resource": {
"$ref": "#/definitions/Annotated2"
"$ref": "#/definitions/ResourceContents"
},
"type": {
"type": "string",

View file

@ -140,35 +140,6 @@
]
},
"Annotated2": {
"type": "object",
"properties": {
"_meta": {
"description": "Optional protocol-level metadata for this content block",
"type": [
"object",
"null"
],
"additionalProperties": true
},
"annotations": {
"anyOf": [
{
"$ref": "#/definitions/Annotations"
},
{
"type": "null"
}
]
},
"resource": {
"$ref": "#/definitions/ResourceContents"
}
},
"required": [
"resource"
]
},
"Annotated3": {
"description": "Represents a resource in the extension with metadata",
"type": "object",
"properties": {
@ -244,7 +215,7 @@
"name"
]
},
"Annotated4": {
"Annotated3": {
"type": "object",
"properties": {
"annotations": {
@ -1481,7 +1452,7 @@
"resourceTemplates": {
"type": "array",
"items": {
"$ref": "#/definitions/Annotated4"
"$ref": "#/definitions/Annotated3"
}
}
},
@ -1508,7 +1479,7 @@
"resources": {
"type": "array",
"items": {
"$ref": "#/definitions/Annotated3"
"$ref": "#/definitions/Annotated2"
}
}
},
@ -2148,8 +2119,26 @@
"description": "Embedded server-side resource",
"type": "object",
"properties": {
"_meta": {
"description": "Optional protocol-level metadata for this content block",
"type": [
"object",
"null"
],
"additionalProperties": true
},
"annotations": {
"anyOf": [
{
"$ref": "#/definitions/Annotations"
},
{
"type": "null"
}
]
},
"resource": {
"$ref": "#/definitions/Annotated2"
"$ref": "#/definitions/ResourceContents"
},
"type": {
"type": "string",