fix: force UTF-8 encoding for stdio streams#6
Merged
topherbullock merged 1 commit intomodelcontextprotocol:mainfrom May 20, 2025
Merged
Conversation
This change forces $stdin/$stdout to use UTF-8 encoding, similar to PR 198 in the python-sdk. modelcontextprotocol/python-sdk#198 It addresses platform-dependent encoding issues.
topherbullock
approved these changes
May 20, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change forces the stdin and stdout encodings to UTF-8, resolving platform-dependent issues—specifically, errors arising from handling multibyte characters (such as Japanese) under US-ASCII encoding.
Motivation and Context
On certain platforms the default encoding may be US-ASCII, which causes errors when processing multibyte characters like Japanese. By ensuring that the I/O streams always use UTF-8, it fix encoding-related issues that arise from varying default settings.
Related issues
How Has This Been Tested?
The changes were tested in an environment where the MCP server (using the Ruby SDK) was executed via llm-functions. The testing steps and results were as follows:
ref: https://github.com/sigoden/llm-functions/tree/main/mcp/bridge
{ "mcpServers": { "example": { "command": "ruby", "args": [ "/home/iberianpig/.ghq/github.com/modelcontextprotocol/ruby-sdk/mcp_demo.rb" ], "env": { "PATH": "/home/iberianpig/.rbenv/shims:/usr/bin" } } } }server:
$ DEBUG=mcp:* argc mcp start Start MCP Bridge server... Merge MCP tools into functions.json Build bin/example_example_tool$ curl http://localhost:8808/tools [{"name":"example_example_tool","description":"A simple example tool that echoes back its arguments","parameters":{"type":"object","properties":{"message":{"type":"string"}},"required":["message"]},"mcp":"example"}]The server log indicated the following error:
Breaking Changes
None. This change does not introduce any breaking changes to the existing functionality of the MCP server or its tools.
Types of changes
Checklist
Additional context
This change is similar to the modifications made in modelcontextprotocol/python-sdk#198.