Commit f4cd962
committed
feat(server): surface structured validation errors in CallToolResult._meta
Fixes #3351. When a tool call fails schema validation, the low-level
Server previously returned only the interpolated free-text message,
forcing clients to regex-match brittle wording to classify failures.
This change forwards jsonschema.ValidationError's stable machine-readable
fields (validator, validator_value, schema_path, json_path, message) into
CallToolResult._meta under the MCP-namespaced key
'io.modelcontextprotocol/schema-validation-error', for both input- and
output-schema failures. The human-readable message and isError=True stay
unchanged, so existing clients keep working.
- _make_error_result now accepts optional structured_data
- new _validation_error_data helper extracts jsonschema fields
- new _jsonable helper coerces non-JSON schema fragments (deques, sets,
callables) to JSON-safe values before they cross the transport
- added tests covering required/type/enum classification via _meta1 parent b222713 commit f4cd962
2 files changed
Lines changed: 142 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
112 | 129 | | |
113 | 130 | | |
114 | 131 | | |
| |||
470 | 487 | | |
471 | 488 | | |
472 | 489 | | |
473 | | - | |
474 | | - | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
475 | 506 | | |
476 | 507 | | |
477 | 508 | | |
478 | 509 | | |
| 510 | + | |
479 | 511 | | |
480 | 512 | | |
481 | 513 | | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
482 | 533 | | |
483 | 534 | | |
484 | 535 | | |
| |||
535 | 586 | | |
536 | 587 | | |
537 | 588 | | |
538 | | - | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
539 | 593 | | |
540 | 594 | | |
541 | 595 | | |
| |||
572 | 626 | | |
573 | 627 | | |
574 | 628 | | |
575 | | - | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
576 | 633 | | |
577 | 634 | | |
578 | 635 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
309 | 309 | | |
310 | 310 | | |
311 | 311 | | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 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 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
0 commit comments