Force stdin/stdout encoding to UTF-8 #198
Merged
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.
The character encoding of the stdin/stdout streams in Python is platform- dependent. On Windows it will be something weird, like CP437 or CP1252, depending on the locale. This change ensures that no matter the platform, UTF-8 is used.
Motivation and Context
How Has This Been Tested?
Breaking Changes
None known.
Types of changes
Checklist
Existing tests fail on Windows because of backslashes vs forward slashes in path names before my change. The same tests still fail on Windows with my change. Tests pass on Linux.
Additional context
This enforces that stdin/stdout are UTF-8-encoded independent of platform; otherwise it's a grab-bag what you get on Windows. The JSON spec requires UTF-8, UTF-16, or UTF-32 encoding, and UTF-8 is by far the most common, so this seems safe.
A proper "fix" would be for the MCP specification to either specify an exact encoding or have a handshake where encoding is established before any other messages are exchanged. (I would lean toward requiring UTF-8.)