Repository navigation
fix(mcp): read path-like MCP app documents as UTF-8 - #3608
Open
pcbeingused333 wants to merge 1 commit into
Open
pcbeingused333 wants to merge 1 commit into
pcbeingused333 wants to merge 1 commit into
Conversation
Path.read_text() without an encoding uses the locale encoding, so HTML documents containing non-ASCII text were decoded wrongly (or failed) on hosts whose locale is not UTF-8, e.g. Windows cp1252. Read as UTF-8 and report undecodable files with the same 'Could not read MCP app document' error instead of leaking a bare UnicodeDecodeError.
Codecov Report✅ All modified and coverable lines are covered by tests.
... and 1 file with indirect coverage changes 🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
Why are these changes needed?
_resolve_contentinag2/mcp/apps.pyreads a path-like MCP app document withPath(resolved).read_text()and no encoding, so it uses the host's locale encoding. HTML containing non-ASCII text is mis-decoded (or fails) where the locale is not UTF-8, e.g. Windows cp1252. Theexceptonly coveredOSError, so aUnicodeDecodeErrorescaped unwrapped.Fix: read with
encoding="utf-8"and turnUnicodeDecodeErrorinto the sameCould not read MCP app document from …ValueErrorused for other read failures.Tests (
test/mcp/test_apps.py): one simulates a cp1252 locale default and checks UTF-8 content is served intact; one checks a non-UTF-8 file gives the wrapped error. Both fail before the change;test/mcp/test_apps.pyis 61 passed after.Related issue number
None (found while reading the code).
Checks
AI assistance
This change was prepared with the help of an AI coding assistant (Claude Code) and reviewed before submission.