Skip to content

MCP stdio server crashes on Windows with UnicodeEncodeError: 'charmap' codec can't encode character '\u2713' #886

Description

@svetkis

What version of Kimi Code is running?

0.5.10

Which open platform/subscription were you using?

Platform: Kimi Code VS Code extension Subscription: Kimi Allegretto

Which model were you using?

kimi-k2.7

What platform is your computer?

Windows 10

What issue are you seeing?

Bug Description

Kimi Code fails to decode UTF-8 responses from MCP stdio servers on Windows. The connection crashes with UnicodeEncodeError when the server sends Unicode characters (e.g., ✓ U+2713).

Environment

  • OS: Windows 10
  • Kimi Code version: 0.5.10
  • MCP Server: Serena 1.5.3 (stdio)
  • Context7: 3.2.1 (stdio)

First log line before crash

INFO ... mcp.server.lowlevel.server:_handle_request:727 - Processing request of type ListToolsRequest

Error Log

Context7 Documentation MCP Server v3.2.1 running on stdio
\u2717 Connection failed: UnicodeEncodeError: 'charmap' codec can't encode character '\u2713' in position 0: character maps to

Works outside Kimi Code?

Yes — Serena starts fine from PowerShell with UTF-8 console. Crashes only when launched by Kimi Code. Also Serena works in Codex without any problems.

What steps can reproduce the bug?

  1. Install any MCP server that outputs Unicode in responses (e.g., Serena, Context7)
  2. Configure in Kimi Code via stdio transport
  3. Server starts, processes ListToolsRequest, then crashes on encoding

Expected Behavior

Kimi Code should handle UTF-8 stdio correctly on Windows, or at least use errors='replace'/'ignore' when decoding.

Actual Behavior

Connection fails, server shuts down, Kimi Code falls back to generic tools (grep).

Workaround

None found. The issue is in Kimi Code's stdio reader/writer, not the server.

What is the expected behavior?

Kimi Code should handle UTF-8 stdio correctly on Windows.

Additional information

Image

Activity

  1. maxim-ultra commented on Jun 18, 2026

    @maxim-ultra

    From the public issue context, a small diagnostic structure that may help keep this actionable:

    • exact MCP client and version
    • exact server launch command or config entry
    • whether transport is stdio, SSE, or streamable HTTP
    • first stderr/stdout line before the failure
    • whether the same command works outside the MCP client
    • expected tool/list response vs actual error

    For a durable fix, I would also add a tiny regression fixture around the failing config shape so this does not reappear after a release. That seems especially relevant for this issue: MCP stdio server crashes on Windows with UnicodeEncodeError: 'charmap' codec can't encode character '\u2713'

  2. svetkis commented on Jun 18, 2026

    @svetkis
    Author

    Updated the issue with requested details:

    • Kimi Code version: 0.5.10
    • Platform: Kimi Code VS Code extension, Kimi Allegretto subscription
    • Model: kimi-k2.7
    • Added Context7 3.2.1 as second affected server
    • Added "first log line before crash" and "works outside Kimi Code" sections

    Bug confirmed in Kimi Code's stdio UTF-8 handling on Windows. Two independent servers (Python and Node.js) fail with identical error. Same servers work in Codex and manually from console.

  3. maxim-ultra commented on Jun 18, 2026

    @maxim-ultra

    From the public issue context and the reporter's public update, thanks for adding the details. Since both Serena and Context7 work outside Kimi Code, I would narrow the next public-only check to Kimi's Windows stdio launcher boundary rather than either MCP server.

    A useful regression shape would be:

    • fake stdio MCP server emits a Unicode checkmark in a tools/list response
    • launch it under a Windows non-UTF-8 locale/codepage fixture
    • assert Kimi reads protocol bytes as UTF-8 at the JSON-RPC boundary instead of using the process locale text codec
    • capture the effective child-process env for PYTHONUTF8, PYTHONIOENCODING, and any shell/codepage setup
    • make the failure report the launcher encoding decision, not just the server stderr line

    No private logs, credentials, or account data are needed. That should separate server emitted invalid output from client launcher decoded valid UTF-8 through cp1252/charmap.

  4. svetkis commented on Jun 18, 2026

    @svetkis
    Author

    Following up on the regression shape suggested above.

    Narrowed boundary: The crash is in Kimi Code's Windows stdio launcher, not in Serena or Context7. When Kimi spawns a Python MCP stdio server on Windows, the child inherits the console codepage (cp1252 / "charmap") for stdout/stderr. Emitting U+2713 (✓) triggers:

    UnicodeEncodeError: 'charmap' codec can't encode character '\u2713' in position 0: character maps to <undefined>
    

    Regression reproduction:

    I created a minimal Python fake MCP stdio server that:

    • emits a U+2713 checkmark in its tools/list response;
    • logs the effective stdout.encoding, stderr.encoding, PYTHONUTF8, and PYTHONIOENCODING of the child process.

    Launching it without Kimi's UTF-8 setup on a Windows cp1252 console gives:

    stdout.encoding=cp1252, stderr.encoding=cp1252, PYTHONUTF8=<unset>
    \u2713 Fake Unicode MCP server running on stdio
    

    With PYTHONUTF8=1 and PYTHONIOENCODING=utf-8 injected by the launcher:

    stdout.encoding=utf-8, stderr.encoding=utf-8, PYTHONUTF8=1
    ✓ Fake Unicode MCP server running on stdio
    

    This separates "server emitted invalid output" from "client launcher decoded valid UTF-8 through cp1252/charmap" — the failure now reports the launcher encoding decision (cp1252) explicitly.

    Fix: PR #899 defaults the child env to PYTHONUTF8=1 and PYTHONIOENCODING=utf-8 in mergeStdioEnv(). It also adds:

    • a unicode-stdio-server.mjs fixture that emits U+2713 in tools/list and tool results;
    • integration tests asserting UTF-8 round-trip at the JSON-RPC boundary and env injection;
    • unit tests for mergeStdioEnv defaults/override semantics.

    pnpm exec vitest run test/mcp/client-stdio.test.ts → 18/18 passed.

    I also verified the fix end-to-end with Serena: after the patch Serena activates projects successfully instead of crashing on the checkmark character.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions