modelcontextprotocol / modelcontextprotocol/java-sdk

StdioClientTransport missing explicit UTF-8 charset in InputStreamReader (same issue as #295, but on client side)

Open Beginner friendly
#898 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P2 ready for work
Dominant language
Java
Stars
3.7k
Forks
1.1k
Avg merge
1d 15h
Merged PRs (30d)
9

Description

Bug description

StdioClientTransport has the same encoding mismatch issue that was identified in #295 and fixed for StdioServerTransportProvider in #826 — but the fix was only applied to the server side. The client transport still lacks explicit UTF-8 charset
specification when reading from the subprocess.

In startInboundProcessing, the InputStreamReader is created without specifying a charset:

https://github.com/modelcontextprotocol/java-sdk/blob/main/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/StdioClientTransport.java#L249

try (BufferedReader processReader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {

Similarly, in startErrorProcessing:

https://github.com/modelcontextprotocol/java-sdk/blob/main/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/StdioClientTransport.java#L182-L183

try (BufferedReader processErrorReader = new BufferedReader(
        new InputStreamReader(process.getErrorStream()))) {

Meanwhile, startOutboundProcessing already correctly specifies UTF-8:

os.write(jsonMessage.getBytes(StandardCharsets.UTF_8));
os.write("\n".getBytes(StandardCharsets.UTF_8));

This is the exact same inconsistency that #295 reported for StdioServerTransportProvider, and that #826 fixed — only on the server side.

Steps to reproduce

  1. Start a JVM with default charset set to something other than UTF-8 (e.g., -Dfile.encoding=COMPAT on Windows with Japanese locale, which resolves to MS932/Shift_JIS)
  2. Connect to an MCP server via StdioClientTransport
  3. Call a tool that returns multi-byte UTF-8 characters (e.g., Japanese, Chinese, Korean, emoji) in its response

Expected behavior

Multi-byte characters in the server's JSON-RPC response should be decoded correctly, since the MCP stdio transport specification requires UTF-8.

Actual behavior

The InputStreamReader uses Charset.defaultCharset() instead of UTF-8. When the default charset is not UTF-8, the response bytes are decoded with the wrong charset, corrupting multi-byte characters. This corruption can also break the JSON structure itself,
resulting in JsonParseException:

com.fasterxml.jackson.core.JsonParseException: Unexpected character ('' (code 92)): was expecting double-quote to start field name

For example, with MS932 as the default charset, the last byte of certain UTF-8 characters (0x8B, etc.) is interpreted as a MS932 lead byte, which then consumes the following byte — potentially a JSON structural character like \ (0x5C). This shifts the parser
state and breaks JSON parsing entirely.

Environment

  • MCP Java SDK version: 1.1.1
  • Java version: 21
  • OS: Windows 11 (Japanese locale, default charset MS932 with -Dfile.encoding=COMPAT)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in mcp-core/src/main/java/io/modelcontextprotocol/client/transport/StdioClientTransport.java, reading startErrorProcessing and startInboundProcessing alongside the existing UTF-8 handling in startOutboundProcessing. Compare the related server-side fix in #826 and verify that responses and errors remain correctly decoded when the JVM default charset is not UTF-8.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
74/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.