StdioClientTransport missing explicit UTF-8 charset in InputStreamReader (same issue as #295, but on client side)
還沒有人認領這個 Issue。
評估
研究方向
從 mcp-core/src/main/java/io/modelcontextprotocol/client/transport/StdioClientTransport.java 開始,閱讀 startErrorProcessing 和 startInboundProcessing,並參考 startOutboundProcessing 中現有的 UTF-8 處理。比較 #826 中相關的伺服器端修正,並確認當 JVM 預設字元集不是 UTF-8 時,回應和錯誤仍能正確解碼。
由索引模型根據 Issue 內容生成。
描述
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:
try (BufferedReader processReader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
Similarly, in startErrorProcessing:
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
- 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)
- Connect to an MCP server via StdioClientTransport
- 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)
- 主要語言
- Java
- 星號
- 3.7k
- 分支
- 1.1k
- 平均合併
- 1 天 15 小時
- 30 天內合併 PR
- 9
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
modelcontextprotocol/java-sdk 的其他 Issue
-
area/transport bug P2
難度 2/5 1-3 小時 新手友好度 88/100
modelcontextprotocol/java-sdk#1136 ·
-
area/client bug P2
難度 2/5 1-3 小時 新手友好度 84/100
modelcontextprotocol/java-sdk#1124 · 1 則留言 ·
-
ServerCapabilities.logging is added unconditionally, overriding the caller's explicit capabilities 未關閉bug P2 ready for work
難度 2/5 1-3 小時 新手友好度 68/100
modelcontextprotocol/java-sdk#1086 · 1 則留言 ·
-
enhancement good first issue P3
難度 2/5 1-3 小時 新手友好度 82/100
modelcontextprotocol/java-sdk#1067 ·
-
documentation P2
難度 2/5 1-3 小時 新手友好度 65/100
modelcontextprotocol/java-sdk#798 · 1 則留言 ·
查看 modelcontextprotocol/java-sdk 的全部 Issue
相似的 Issue
-
Bug Java Platform: Java
難度 2/5 1-3 小時 新手友好度 78/100
getsentry/sentry-java#6138 · 1 則留言 ·
-
bug needs triage p2
難度 2/5 1-3 小時 新手友好度 78/100
GoogleCloudPlatform/DataflowTemplates#4273 · 1 則留言 ·
-
難度 2/5 1-3 小時 新手友好度 78/100
-
難度 2/5 1-3 小時 新手友好度 76/100
-
bug needs triage
難度 2/5 1-3 小時 新手友好度 76/100