Skip to content

Commit efa82ca

Browse files
author
Sarvesh
committed
style: ruff format fix
1 parent 5a470d7 commit efa82ca

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

pr_body.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Summary
2+
- Changes the default `encoding_error_handler` in `StdioServerParameters` from `"strict"` to `"replace"`.
3+
- Malformed UTF-8 bytes from a child server stdout previously crashed the client transport with `UnicodeDecodeError`.
4+
- With `"replace"`, invalid bytes become U+FFFD and the line fails JSON-RPC validation, which is surfaced as an in-stream `Exception` that the session can handle.
5+
- This mirrors the server-side stdio hardening from PR #2302.
6+
7+
## Test Plan
8+
- [x] Reproduced the crash with a child process emitting `\xff\xfe\n` followed by valid JSON-RPC.
9+
- [x] Verified the fix: first item is a `ValidationError`, second item is the valid `SessionMessage`.
10+
- [x] Added regression test `test_invalid_utf8_from_the_server_surfaces_as_an_in_stream_exception`.
11+
- [x] Full `tests/client/test_stdio.py` suite passes (34 passed, 1 skipped).
12+
13+
## Notes
14+
- Fixes #2454
15+
- Scope intentionally small.

src/mcp/server/mcpserver/server.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,7 @@ async def call_tool(
389389
if isinstance(result, CallToolResult):
390390
return result
391391
if isinstance(result, tuple) and len(result) == 2: # type: ignore[arg-type]
392-
unstructured_content, structured_content = cast(
393-
tuple[Sequence[ContentBlock], dict[str, Any]], result
394-
)
392+
unstructured_content, structured_content = cast(tuple[Sequence[ContentBlock], dict[str, Any]], result)
395393
return CallToolResult(
396394
content=list(unstructured_content),
397395
structured_content=structured_content,

0 commit comments

Comments
 (0)