Repository navigation
Commit e757931
committed
Strip stdio client frames as bytes
## Motivation and Context
`MCP::Client::Stdio` reads the server's stdout as UTF-8 and strips each frame before parsing it. `String#strip`
raises for a UTF-8 string holding an invalid byte at either end on every supported Ruby, and anywhere in it from
Ruby 3.2 on, and the read loop rescued only `JSON::ParserError`. A server writing such a frame therefore failed
the awaited request with `ArgumentError` or `Encoding::CompatibilityError` instead of the transport's own
`RequestHandlerError`, which callers rescue. The server transport strips its frames the same way and has the same
change separately.
Frames are now stripped as bytes. A frame that is not JSON fails the request with the transport's parse failure,
as any other unparsable frame does, and a response holding such a byte in a value is returned with the byte kept.
## How Has This Been Tested?
`test/mcp/client/stdio_test.rb`: a frame starting with an invalid byte and a response holding one in a value.
Against the previous library the first raises `ArgumentError` and the second `Encoding::CompatibilityError`.
## Breaking Changes
None.1 parent 0e59bb4 commit e757931
2 files changed
Lines changed: 44 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
434 | 434 | | |
435 | 435 | | |
436 | 436 | | |
437 | | - | |
| 437 | + | |
438 | 438 | | |
439 | 439 | | |
440 | 440 | | |
| |||
534 | 534 | | |
535 | 535 | | |
536 | 536 | | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
537 | 545 | | |
538 | 546 | | |
539 | 547 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
709 | 709 | | |
710 | 710 | | |
711 | 711 | | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
712 | 747 | | |
713 | 748 | | |
714 | 749 | | |
| |||
0 commit comments