Repository navigation
Commit 42e8cd5
committed
Skip a stdio ping whose id cannot be encoded
## Motivation and Context
`MCP::Client::Stdio` answers a server's `ping` inline while it waits for a response, and it already skips a ping
whose id is not a JSON-RPC id. A String id holding bytes that are not valid UTF-8 passed that check, and the pong
echoing it failed in `JSON.generate` with `JSON::GeneratorError`. The pong's own rescue covers only a pong that
cannot be written, so the error escaped and failed the unrelated request whose response the loop was reading.
Such a ping is now skipped like one with a malformed id, since a pong could not carry the id back.
A number such as `1e400` fails the same way: the parser reads it as an infinite Float, which `JSON.generate`
refuses, so a ping carrying one is skipped as well. A String id that is not valid UTF-8 can arrive in
a plain ASCII frame too: the json gem's 2.x releases decode a lone surrogate escape into one.
## How Has This Been Tested?
`test/mcp/client/stdio_test.rb`: a ping whose id is not valid UTF-8 is not answerable, and one with a valid id
still is. Against the previous library the first is answerable.
A ping whose id is `1e400`, sent ahead of the awaited response, is not answered and the request completes;
against the previous library it raises `JSON::GeneratorError`.
## Breaking Changes
None.1 parent 0e59bb4 commit 42e8cd5
2 files changed
Lines changed: 35 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
484 | 484 | | |
485 | 485 | | |
486 | 486 | | |
| 487 | + | |
| 488 | + | |
487 | 489 | | |
488 | | - | |
| 490 | + | |
489 | 491 | | |
490 | 492 | | |
491 | 493 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
324 | 324 | | |
325 | 325 | | |
326 | 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 | + | |
327 | 359 | | |
328 | 360 | | |
329 | 361 | | |
| |||
0 commit comments