Commit d83b156
authored
fix(rmcp): flatten Resource variant of PromptMessageContent (modelcontextprotocol#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.1 parent 321ab14 commit d83b156
3 files changed
Lines changed: 99 additions & 67 deletions
File tree
- crates/rmcp
- src/model
- tests/test_message_schema
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
161 | | - | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
162 | 165 | | |
163 | 166 | | |
164 | 167 | | |
| |||
321 | 324 | | |
322 | 325 | | |
323 | 326 | | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
324 | 378 | | |
325 | 379 | | |
326 | 380 | | |
| |||
Lines changed: 22 additions & 33 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | 143 | | |
173 | 144 | | |
174 | 145 | | |
| |||
244 | 215 | | |
245 | 216 | | |
246 | 217 | | |
247 | | - | |
| 218 | + | |
248 | 219 | | |
249 | 220 | | |
250 | 221 | | |
| |||
1481 | 1452 | | |
1482 | 1453 | | |
1483 | 1454 | | |
1484 | | - | |
| 1455 | + | |
1485 | 1456 | | |
1486 | 1457 | | |
1487 | 1458 | | |
| |||
1508 | 1479 | | |
1509 | 1480 | | |
1510 | 1481 | | |
1511 | | - | |
| 1482 | + | |
1512 | 1483 | | |
1513 | 1484 | | |
1514 | 1485 | | |
| |||
2148 | 2119 | | |
2149 | 2120 | | |
2150 | 2121 | | |
| 2122 | + | |
| 2123 | + | |
| 2124 | + | |
| 2125 | + | |
| 2126 | + | |
| 2127 | + | |
| 2128 | + | |
| 2129 | + | |
| 2130 | + | |
| 2131 | + | |
| 2132 | + | |
| 2133 | + | |
| 2134 | + | |
| 2135 | + | |
| 2136 | + | |
| 2137 | + | |
| 2138 | + | |
| 2139 | + | |
2151 | 2140 | | |
2152 | | - | |
| 2141 | + | |
2153 | 2142 | | |
2154 | 2143 | | |
2155 | 2144 | | |
| |||
Lines changed: 22 additions & 33 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | 143 | | |
173 | 144 | | |
174 | 145 | | |
| |||
244 | 215 | | |
245 | 216 | | |
246 | 217 | | |
247 | | - | |
| 218 | + | |
248 | 219 | | |
249 | 220 | | |
250 | 221 | | |
| |||
1481 | 1452 | | |
1482 | 1453 | | |
1483 | 1454 | | |
1484 | | - | |
| 1455 | + | |
1485 | 1456 | | |
1486 | 1457 | | |
1487 | 1458 | | |
| |||
1508 | 1479 | | |
1509 | 1480 | | |
1510 | 1481 | | |
1511 | | - | |
| 1482 | + | |
1512 | 1483 | | |
1513 | 1484 | | |
1514 | 1485 | | |
| |||
2148 | 2119 | | |
2149 | 2120 | | |
2150 | 2121 | | |
| 2122 | + | |
| 2123 | + | |
| 2124 | + | |
| 2125 | + | |
| 2126 | + | |
| 2127 | + | |
| 2128 | + | |
| 2129 | + | |
| 2130 | + | |
| 2131 | + | |
| 2132 | + | |
| 2133 | + | |
| 2134 | + | |
| 2135 | + | |
| 2136 | + | |
| 2137 | + | |
| 2138 | + | |
| 2139 | + | |
2151 | 2140 | | |
2152 | | - | |
| 2141 | + | |
2153 | 2142 | | |
2154 | 2143 | | |
2155 | 2144 | | |
| |||
0 commit comments