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:
committed by
Igor Lins e Silva
parent
46d9eb5df0
commit
7b49478ef7
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user