From eae3abaf4b1955f35e2cfa8736770f4c26d49dfa Mon Sep 17 00:00:00 2001 From: Gorre Surya Date: Sat, 16 May 2026 17:39:25 -0400 Subject: [PATCH] fix: use UTF-8 charset in StdioClientTransport stream readers InputStreamReader defaults to the system charset, which can corrupt MCP messages on non-UTF-8 JVMs. Use StandardCharsets.UTF_8 explicitly in both startInboundProcessing and startErrorProcessing, consistent with the outbound writer which already uses UTF-8. Fixes #898 Signed-off-by: Gorre Surya --- .../client/transport/StdioClientTransport.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/StdioClientTransport.java b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/StdioClientTransport.java index 1b4eaca97..a88d636e3 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/StdioClientTransport.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/StdioClientTransport.java @@ -180,7 +180,7 @@ public void awaitForExit() { private void startErrorProcessing() { this.errorScheduler.schedule(() -> { try (BufferedReader processErrorReader = new BufferedReader( - new InputStreamReader(process.getErrorStream()))) { + new InputStreamReader(process.getErrorStream(), StandardCharsets.UTF_8))) { String line; while (!isClosing && (line = processErrorReader.readLine()) != null) { try { @@ -246,7 +246,8 @@ public Mono sendMessage(JSONRPCMessage message) { */ private void startInboundProcessing() { this.inboundScheduler.schedule(() -> { - try (BufferedReader processReader = new BufferedReader(new InputStreamReader(process.getInputStream()))) { + try (BufferedReader processReader = new BufferedReader( + new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8))) { String line; while (!isClosing && (line = processReader.readLine()) != null) { try {