Skip to content

fix(publisher): validate JSON encoding before publishing to catch Windows codepage corruption#1439

Closed
hiro-nikaitou wants to merge 1 commit into
modelcontextprotocol:mainfrom
hiro-nikaitou:fix/validate-utf8-publish-data
Closed

fix(publisher): validate JSON encoding before publishing to catch Windows codepage corruption#1439
hiro-nikaitou wants to merge 1 commit into
modelcontextprotocol:mainfrom
hiro-nikaitou:fix/validate-utf8-publish-data

Conversation

@hiro-nikaitou

Copy link
Copy Markdown

Summary

On Windows systems running under Git Bash/MSYS with a non-UTF-8 ANSI codepage (e.g. zh-CN CP-936/GBK), UTF-8 bytes in server.json description fields can be silently reinterpreted through the system codepage. The result is corrupted metadata in the registry containing lone surrogate characters (e.g. \udc94).

This adds a validatePublishData() function that checks both valid UTF-8 encoding and absence of JSON-escaped lone surrogates (\udc00-\udfff) before transmitting the publish or validate request. If corruption is detected, the command fails with a clear error message suggesting running from PowerShell or CMD instead of Git Bash.

Changes

  • publish.go: Added validatePublishData() function and call before HTTP send
  • validate.go: Added validatePublishData() call in validateViaAPI for consistency
  • publish_internal_test.go: 9 test cases covering valid ASCII, UTF-8 Unicode, invalid UTF-8, lone surrogate detection (lowercase, uppercase, end range), and false-positive avoidance

Testing

  • go build ./cmd/publisher/... passes
  • go vet ./cmd/publisher/commands/ passes
  • All 9 validation unit tests pass
  • Existing publish integration tests pass

Fixes #1306

…dows codepage corruption

On Windows systems running under Git Bash/MSYS with a non-UTF-8 ANSI
codepage (e.g. zh-CN CP-936/GBK), UTF-8 bytes in server.json description
fields can be silently reinterpreted through the system codepage,
producing invalid JSON with lone surrogate characters (e.g. \udc94).

This adds validatePublishData() that checks both valid UTF-8 encoding
and absence of JSON-escaped lone surrogates (\udc00-\udfff) before
transmitting the publish or validate request. If corruption is detected,
the command fails with a clear error message suggesting a workaround.

Fixes modelcontextprotocol#1306

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@rdimitrov

Copy link
Copy Markdown
Member

Hey, @hiro-nikaitou, thanks for the contribution but there was another PR already opened (#1310) and it was fair to go with it! Anyway, the issue is now addressed so with the next release it would be available to everyone! Thanks again!

@rdimitrov rdimitrov closed this Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mcp-publisher mangles non-ASCII description bytes on Windows (em-dash → \udc94 lone surrogate)

2 participants