Skip to content

fix: add ensure_ascii=False to json.dumps in MCP server#783

Open
OmkarKirpan wants to merge 1 commit intoMemPalace:developfrom
OmkarKirpan:fix/json-ensure-ascii-false
Open

fix: add ensure_ascii=False to json.dumps in MCP server#783
OmkarKirpan wants to merge 1 commit intoMemPalace:developfrom
OmkarKirpan:fix/json-ensure-ascii-false

Conversation

@OmkarKirpan
Copy link
Copy Markdown

Summary

Closes #359

json.dumps() in the MCP server escapes non-ASCII characters by default, which causes surrogate encoding errors on Windows when processing Chinese/Korean/CJK content. This crashes the server with:

UnicodeEncodeError: 'utf-8' codec can't encode character '\udca3'

This PR adds ensure_ascii=False to all three json.dumps() calls in mcp_server.py:

  1. WAL entry logging — non-ASCII content in tool params/results is preserved
  2. Tool result serialization — CJK search results render correctly
  3. Response output — the final JSON-RPC response writes CJK characters directly

This matches the pattern already used in hooks_cli.py:95 and config.py:193.

Test plan

  • All 60 MCP server tests pass
  • ruff check and ruff format clean
  • Manual: search for CJK content and verify results contain raw characters, not \uXXXX escapes

@OmkarKirpan OmkarKirpan force-pushed the fix/json-ensure-ascii-false branch from dc8b8db to 17a5d75 Compare April 13, 2026 10:33
@igorls igorls added area/mcp MCP server and tools bug Something isn't working labels Apr 14, 2026
Without ensure_ascii=False, json.dumps escapes non-ASCII characters
(Chinese, Korean, etc.) which can trigger surrogate encoding errors
on Windows and produce unreadable escaped output on all platforms.

Adds ensure_ascii=False to all three json.dumps calls in mcp_server.py:
- WAL entry logging (line 124)
- Tool result serialization (line 1492)
- Response output to stdout (line 1525)

This matches the pattern already used in hooks_cli.py and config.py.

Closes MemPalace#359
@OmkarKirpan OmkarKirpan force-pushed the fix/json-ensure-ascii-false branch from 17a5d75 to e6866cf Compare April 15, 2026 09:44
@OmkarKirpan
Copy link
Copy Markdown
Author

Hi @bensig,
Rebased onto develop and force-pushed - conflicts resolved, all tests passing. Ready to merge.

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

Labels

area/mcp MCP server and tools bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

【bug】json.dumps(response) does not set ensure_ascii=False

3 participants