Commit 47bf2ae
committed
feat!: guard required MCP spec fields against null
Records in McpSchema whose fields the MCP spec marks as required were
storing them as nullable Java types with no validation. A caller
constructing one of these records with null for a required field would
silently produce invalid wire JSON because @JsonInclude(NON_ABSENT) omits
null values without complaint.
Compact canonical constructors with Assert.notNull are added to seven
records:
- JSONRPCError (code, message),
- ProgressNotification (progressToken, progress),
- LoggingMessageNotification (level, data),
- CreateMessageRequest (messages, maxTokens),
- CallToolResult (content),
- SamplingMessage (role, content),
- ElicitRequest (message, requestedSchema).
Test code that constructed these records without required fields was
updated to supply valid values; those tests were testing capability-check
or error-path logic that fires after construction, so the missing fields
were incidental rather than intentional.
Signed-off-by: Dariusz Jędrzejczyk <2554306+chemicL@users.noreply.github.com>1 parent d1cad25 commit 47bf2ae
5 files changed
Lines changed: 63 additions & 2 deletions
File tree
- mcp-core/src
- main/java/io/modelcontextprotocol/spec
- test/java/io/modelcontextprotocol/server
- mcp-test/src
- main/java/io/modelcontextprotocol
- test/java/io/modelcontextprotocol/spec
Lines changed: 34 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
296 | 296 | | |
297 | 297 | | |
298 | 298 | | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
299 | 304 | | |
300 | 305 | | |
301 | 306 | | |
| |||
1573 | 1578 | | |
1574 | 1579 | | |
1575 | 1580 | | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
1576 | 1585 | | |
1577 | 1586 | | |
1578 | 1587 | | |
| |||
1797 | 1806 | | |
1798 | 1807 | | |
1799 | 1808 | | |
| 1809 | + | |
| 1810 | + | |
| 1811 | + | |
| 1812 | + | |
| 1813 | + | |
1800 | 1814 | | |
1801 | 1815 | | |
1802 | 1816 | | |
| |||
1834 | 1848 | | |
1835 | 1849 | | |
1836 | 1850 | | |
| 1851 | + | |
| 1852 | + | |
| 1853 | + | |
| 1854 | + | |
| 1855 | + | |
1837 | 1856 | | |
1838 | 1857 | | |
1839 | 1858 | | |
| |||
2063 | 2082 | | |
2064 | 2083 | | |
2065 | 2084 | | |
| 2085 | + | |
| 2086 | + | |
| 2087 | + | |
| 2088 | + | |
| 2089 | + | |
2066 | 2090 | | |
2067 | 2091 | | |
2068 | 2092 | | |
| |||
2239 | 2263 | | |
2240 | 2264 | | |
2241 | 2265 | | |
| 2266 | + | |
| 2267 | + | |
| 2268 | + | |
| 2269 | + | |
| 2270 | + | |
2242 | 2271 | | |
2243 | 2272 | | |
2244 | 2273 | | |
| |||
2281 | 2310 | | |
2282 | 2311 | | |
2283 | 2312 | | |
| 2313 | + | |
| 2314 | + | |
| 2315 | + | |
| 2316 | + | |
| 2317 | + | |
2284 | 2318 | | |
2285 | 2319 | | |
2286 | 2320 | | |
| |||
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
306 | 306 | | |
307 | 307 | | |
308 | 308 | | |
| 309 | + | |
309 | 310 | | |
310 | 311 | | |
311 | 312 | | |
| |||
330 | 331 | | |
331 | 332 | | |
332 | 333 | | |
| 334 | + | |
333 | 335 | | |
334 | 336 | | |
335 | 337 | | |
| |||
397 | 399 | | |
398 | 400 | | |
399 | 401 | | |
| 402 | + | |
400 | 403 | | |
401 | 404 | | |
402 | 405 | | |
| |||
424 | 427 | | |
425 | 428 | | |
426 | 429 | | |
| 430 | + | |
427 | 431 | | |
428 | 432 | | |
429 | 433 | | |
| |||
451 | 455 | | |
452 | 456 | | |
453 | 457 | | |
| 458 | + | |
454 | 459 | | |
455 | 460 | | |
456 | 461 | | |
| |||
474 | 479 | | |
475 | 480 | | |
476 | 481 | | |
| 482 | + | |
477 | 483 | | |
478 | 484 | | |
479 | 485 | | |
| |||
500 | 506 | | |
501 | 507 | | |
502 | 508 | | |
| 509 | + | |
503 | 510 | | |
504 | 511 | | |
505 | 512 | | |
| |||
525 | 532 | | |
526 | 533 | | |
527 | 534 | | |
| 535 | + | |
528 | 536 | | |
529 | 537 | | |
530 | 538 | | |
| |||
563 | 571 | | |
564 | 572 | | |
565 | 573 | | |
| 574 | + | |
566 | 575 | | |
567 | 576 | | |
568 | 577 | | |
| |||
596 | 605 | | |
597 | 606 | | |
598 | 607 | | |
| 608 | + | |
599 | 609 | | |
600 | 610 | | |
601 | 611 | | |
| |||
621 | 631 | | |
622 | 632 | | |
623 | 633 | | |
| 634 | + | |
624 | 635 | | |
625 | 636 | | |
626 | 637 | | |
| |||
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
303 | 303 | | |
304 | 304 | | |
305 | 305 | | |
| 306 | + | |
306 | 307 | | |
307 | 308 | | |
308 | 309 | | |
| |||
326 | 327 | | |
327 | 328 | | |
328 | 329 | | |
| 330 | + | |
329 | 331 | | |
330 | 332 | | |
331 | 333 | | |
| |||
394 | 396 | | |
395 | 397 | | |
396 | 398 | | |
| 399 | + | |
397 | 400 | | |
398 | 401 | | |
399 | 402 | | |
| |||
422 | 425 | | |
423 | 426 | | |
424 | 427 | | |
| 428 | + | |
425 | 429 | | |
426 | 430 | | |
427 | 431 | | |
| |||
450 | 454 | | |
451 | 455 | | |
452 | 456 | | |
| 457 | + | |
453 | 458 | | |
454 | 459 | | |
455 | 460 | | |
| |||
475 | 480 | | |
476 | 481 | | |
477 | 482 | | |
| 483 | + | |
478 | 484 | | |
479 | 485 | | |
480 | 486 | | |
| |||
500 | 506 | | |
501 | 507 | | |
502 | 508 | | |
| 509 | + | |
503 | 510 | | |
504 | 511 | | |
505 | 512 | | |
| |||
525 | 532 | | |
526 | 533 | | |
527 | 534 | | |
| 535 | + | |
528 | 536 | | |
529 | 537 | | |
530 | 538 | | |
| |||
564 | 572 | | |
565 | 573 | | |
566 | 574 | | |
| 575 | + | |
567 | 576 | | |
568 | 577 | | |
569 | 578 | | |
| |||
598 | 607 | | |
599 | 608 | | |
600 | 609 | | |
| 610 | + | |
601 | 611 | | |
602 | 612 | | |
603 | 613 | | |
| |||
624 | 634 | | |
625 | 635 | | |
626 | 636 | | |
| 637 | + | |
627 | 638 | | |
628 | 639 | | |
629 | 640 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
| 174 | + | |
174 | 175 | | |
175 | 176 | | |
176 | 177 | | |
| |||
250 | 251 | | |
251 | 252 | | |
252 | 253 | | |
| 254 | + | |
253 | 255 | | |
254 | 256 | | |
255 | 257 | | |
| |||
325 | 327 | | |
326 | 328 | | |
327 | 329 | | |
| 330 | + | |
328 | 331 | | |
329 | 332 | | |
330 | 333 | | |
| |||
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1427 | 1427 | | |
1428 | 1428 | | |
1429 | 1429 | | |
| 1430 | + | |
1430 | 1431 | | |
1431 | 1432 | | |
1432 | 1433 | | |
| |||
1436 | 1437 | | |
1437 | 1438 | | |
1438 | 1439 | | |
1439 | | - | |
1440 | | - | |
| 1440 | + | |
| 1441 | + | |
| 1442 | + | |
1441 | 1443 | | |
1442 | 1444 | | |
1443 | 1445 | | |
| |||
0 commit comments