fix: MCP server JSON output ensure_ascii=False for non-ASCII support

Without ensure_ascii=False, non-ASCII characters (e.g. Chinese) in tool
results and JSON-RPC responses are escaped as \uXXXX, which causes
downstream MCP clients to receive escaped text instead of the original
characters. This affects all platforms, not just Windows.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
黄祖鑫(940219)
2026-05-01 20:46:36 +08:00
committed by Igor Lins e Silva
parent 46d9eb5df0
commit 7b49478ef7
+2 -2
View File
@@ -2053,7 +2053,7 @@ def handle_request(request):
return {
"jsonrpc": "2.0",
"id": req_id,
"result": {"content": [{"type": "text", "text": json.dumps(result, indent=2)}]},
"result": {"content": [{"type": "text", "text": json.dumps(result, indent=2, ensure_ascii=False)}]},
}
except Exception:
logger.exception(f"Tool error in {tool_name}")
@@ -2114,7 +2114,7 @@ def main():
request = json.loads(line)
response = handle_request(request)
if response is not None:
sys.stdout.write(json.dumps(response) + "\n")
sys.stdout.write(json.dumps(response, ensure_ascii=False) + "\n")
sys.stdout.flush()
except KeyboardInterrupt:
break