Skip to content

Commit eae3aba

Browse files
committed
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 <suryateja.g13@gmail.com>
1 parent c09ee67 commit eae3aba

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

mcp-core/src/main/java/io/modelcontextprotocol/client/transport/StdioClientTransport.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public void awaitForExit() {
180180
private void startErrorProcessing() {
181181
this.errorScheduler.schedule(() -> {
182182
try (BufferedReader processErrorReader = new BufferedReader(
183-
new InputStreamReader(process.getErrorStream()))) {
183+
new InputStreamReader(process.getErrorStream(), StandardCharsets.UTF_8))) {
184184
String line;
185185
while (!isClosing && (line = processErrorReader.readLine()) != null) {
186186
try {
@@ -246,7 +246,8 @@ public Mono<Void> sendMessage(JSONRPCMessage message) {
246246
*/
247247
private void startInboundProcessing() {
248248
this.inboundScheduler.schedule(() -> {
249-
try (BufferedReader processReader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
249+
try (BufferedReader processReader = new BufferedReader(
250+
new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8))) {
250251
String line;
251252
while (!isClosing && (line = processReader.readLine()) != null) {
252253
try {

0 commit comments

Comments
 (0)