Repository navigation
Commit e180dff
fix(mcp): return tool execution failures as isError results (#258)
## What type of PR is this?
- [x] fix (bug fix)
## Which issue(s) this PR fixes
Fixes #254
## What this PR does / why we need it
Tool execution failures currently become JSON-RPC errors or unmarked
success text, making it difficult for clients to present actionable
failures to the model. Return execution failures as tool results with
`isError: true`, while keeping malformed tool-call envelopes and unknown
tools as JSON-RPC `-32602` errors.
- Share protocol validation and error-result construction across stdio,
embedded HTTP, and remote execution. Preserve existing known hidden tool
names.
- Mark existing validation/rejection text as tool errors, preserve
actionable validation and conflict messages, and redact typed
internal/database/embedding and transport failure details from
model-visible results.
- Validate unknown tools before HTTP scope classification; known tools
still require their existing scopes, and group write guards remain in
place.
- Keep `rpc_success` as the protocol outcome. Add nullable
`tool_success` and `tool_error_kind` call-log columns with additive
migrations and expose per-tool input/rejection/backend failure counts
through admin statistics. Historical rows retain an unknown tool
outcome. Expected input/rejection errors do not generate backend
warning/health-error signals.
- Preserve `arguments: null` compatibility, plain-text REST
validation/rejection messages, and failure markers for duplicate
snapshots/branches, missing branch deletion, and empty apply selections.
REST delegation propagates marked tool failures as HTTP errors.
- Limit partial-write warnings to tools that may mutate state; read-only
failures do not imply a write.
MCP remains at `2024-11-05`; this does not depend on #236 or the
notification fix.
## Review and validation
- Reviewed both dispatchers, remote response parsing, existing
soft-error branches, HTTP admission, and the distinction between
protocol and execution success.
- `cargo test -p memoria-mcp -p memoria-api --lib --offline`: 138 tests
passed (104 API, 34 MCP).
- `cargo test -p memoria-mcp --test tools_unit --offline`: 9 tests
passed.
- `cargo clippy -p memoria-mcp -p memoria-api --lib --offline -- -D
warnings`: passed.
- `cargo test -p memoria-api --test api_e2e --no-run --offline`: passed;
updated the unknown-tool assertions to expect `-32602`.
- Branch and snapshot end-to-end test targets compile successfully
(`--no-run --offline`).
- Added regression coverage for null arguments, remote plain-text/JSON
errors and HTML redaction, read-only error messaging, REST error
propagation, and persisted per-tool error classification.
- `git diff --check`: passed.
- Database-backed end-to-end tests were not run locally because Docker
is unavailable. Those tests remain for CI; local tests use lazy,
unconnected pools and a local HTTP stub/transport failure to exercise
protocol behavior.
## Follow-up CI fixes
- Update the snapshot quota integration test to expect the REST error
response, and verify that rejection does not create an extra snapshot.
- Preserve legacy input-error text while carrying a typed input
classification. Add database-independent regression coverage for the
missing session-id message and its tool-error classification; the
existing database integration assertions remain unchanged.
---------
Co-authored-by: Cursor <cursoragent@cursor.com>1 parent 9101313 commit e180dff
15 files changed
Lines changed: 1741 additions & 259 deletions
File tree
- memoria/crates
- memoria-api
- src
- routes
- tests
- memoria-mcp
- src
- tests
- memoria-storage/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
898 | 898 | | |
899 | 899 | | |
900 | 900 | | |
| 901 | + | |
| 902 | + | |
901 | 903 | | |
902 | 904 | | |
903 | 905 | | |
904 | 906 | | |
905 | 907 | | |
906 | 908 | | |
907 | 909 | | |
| 910 | + | |
| 911 | + | |
908 | 912 | | |
909 | 913 | | |
910 | 914 | | |
911 | 915 | | |
912 | 916 | | |
913 | 917 | | |
| 918 | + | |
| 919 | + | |
914 | 920 | | |
915 | 921 | | |
916 | 922 | | |
| |||
927 | 933 | | |
928 | 934 | | |
929 | 935 | | |
| 936 | + | |
| 937 | + | |
930 | 938 | | |
931 | 939 | | |
932 | 940 | | |
| |||
997 | 1005 | | |
998 | 1006 | | |
999 | 1007 | | |
| 1008 | + | |
| 1009 | + | |
1000 | 1010 | | |
1001 | 1011 | | |
1002 | 1012 | | |
| |||
1065 | 1075 | | |
1066 | 1076 | | |
1067 | 1077 | | |
1068 | | - | |
| 1078 | + | |
1069 | 1079 | | |
1070 | 1080 | | |
1071 | 1081 | | |
1072 | 1082 | | |
1073 | | - | |
| 1083 | + | |
1074 | 1084 | | |
1075 | 1085 | | |
1076 | 1086 | | |
| |||
1082 | 1092 | | |
1083 | 1093 | | |
1084 | 1094 | | |
1085 | | - | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
1086 | 1098 | | |
1087 | 1099 | | |
1088 | 1100 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
594 | 594 | | |
595 | 595 | | |
596 | 596 | | |
597 | | - | |
| 597 | + | |
598 | 598 | | |
599 | 599 | | |
600 | 600 | | |
601 | 601 | | |
602 | | - | |
| 602 | + | |
603 | 603 | | |
604 | 604 | | |
605 | 605 | | |
| |||
624 | 624 | | |
625 | 625 | | |
626 | 626 | | |
627 | | - | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
628 | 632 | | |
629 | 633 | | |
630 | 634 | | |
| |||
647 | 651 | | |
648 | 652 | | |
649 | 653 | | |
650 | | - | |
651 | | - | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
652 | 657 | | |
653 | 658 | | |
654 | 659 | | |
| |||
657 | 662 | | |
658 | 663 | | |
659 | 664 | | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
660 | 669 | | |
661 | 670 | | |
662 | 671 | | |
| |||
665 | 674 | | |
666 | 675 | | |
667 | 676 | | |
668 | | - | |
| 677 | + | |
669 | 678 | | |
670 | | - | |
| 679 | + | |
671 | 680 | | |
672 | 681 | | |
673 | 682 | | |
| |||
690 | 699 | | |
691 | 700 | | |
692 | 701 | | |
693 | | - | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
694 | 705 | | |
695 | 706 | | |
696 | 707 | | |
| |||
699 | 710 | | |
700 | 711 | | |
701 | 712 | | |
| 713 | + | |
| 714 | + | |
702 | 715 | | |
703 | 716 | | |
704 | 717 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
189 | 189 | | |
190 | 190 | | |
191 | 191 | | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
192 | 212 | | |
193 | 213 | | |
194 | 214 | | |
| |||
317 | 337 | | |
318 | 338 | | |
319 | 339 | | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
320 | 351 | | |
321 | 352 | | |
322 | 353 | | |
| |||
455 | 486 | | |
456 | 487 | | |
457 | 488 | | |
458 | | - | |
| 489 | + | |
459 | 490 | | |
460 | 491 | | |
461 | | - | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
462 | 496 | | |
463 | 497 | | |
464 | 498 | | |
465 | 499 | | |
466 | | - | |
467 | | - | |
468 | | - | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
469 | 507 | | |
470 | 508 | | |
471 | 509 | | |
| |||
495 | 533 | | |
496 | 534 | | |
497 | 535 | | |
498 | | - | |
499 | | - | |
500 | | - | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
501 | 539 | | |
502 | 540 | | |
503 | 541 | | |
| |||
507 | 545 | | |
508 | 546 | | |
509 | 547 | | |
| 548 | + | |
| 549 | + | |
510 | 550 | | |
511 | 551 | | |
512 | 552 | | |
513 | | - | |
| 553 | + | |
| 554 | + | |
514 | 555 | | |
515 | 556 | | |
516 | 557 | | |
| |||
521 | 562 | | |
522 | 563 | | |
523 | 564 | | |
| 565 | + | |
524 | 566 | | |
525 | 567 | | |
526 | 568 | | |
527 | | - | |
| 569 | + | |
528 | 570 | | |
529 | 571 | | |
530 | 572 | | |
531 | 573 | | |
532 | 574 | | |
533 | | - | |
534 | | - | |
535 | | - | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
536 | 582 | | |
537 | 583 | | |
538 | 584 | | |
| |||
544 | 590 | | |
545 | 591 | | |
546 | 592 | | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
547 | 613 | | |
548 | 614 | | |
549 | 615 | | |
| |||
664 | 730 | | |
665 | 731 | | |
666 | 732 | | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
667 | 792 | | |
668 | 793 | | |
669 | 794 | | |
| |||
0 commit comments