fix: force UTF-8 encoding for stdio streams #6
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
server:
$ DEBUG=mcp:* argc mcp start Start MCP Bridge server... Merge MCP tools into functions.json Build bin/example_example_tool
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.