Skip to content

fix(output): emit UTF-8 JSON instead of \u escapes - #67

Open
syf2211 wants to merge 1 commit into
knowsuchagency:mainfrom
syf2211:fix/ensure-ascii-false-json-output
Open

fix(output): emit UTF-8 JSON instead of \u escapes#67
syf2211 wants to merge 1 commit into
knowsuchagency:mainfrom
syf2211:fix/ensure-ascii-false-json-output

Conversation

@syf2211

@syf2211 syf2211 commented Jul 21, 2026

Copy link
Copy Markdown

Summary

Set ensure_ascii=False on user-facing json.dumps() calls so non-ASCII characters in MCP tool output (CJK, emoji, accented Latin, etc.) are serialized as UTF-8 instead of \uXXXX escape sequences.

Fixes #62

Motivation

Python's default ensure_ascii=True expands every non-ASCII character from 1–2 UTF-8 bytes to 6 ASCII bytes (\uXXXX). For CJK-heavy MCP tool responses this means 4–6× more tokens when output is consumed by an LLM, plus harder-to-read stdout for debugging.

Changes

  • _emit_json() — pretty and compact JSON output paths
  • output_result()--raw dict fallback and --toon pre-encoding
  • _bake_show() — baked tool config display
  • Added test_non_ascii_emitted_as_utf8 in tests/test_json.py

Internal persistence paths (cache, usage tracking, OAuth meta, baked config files, session daemon IPC) are intentionally unchanged to preserve cache-key stability and cross-platform file safety.

Tests

pytest tests/test_json.py — 25/25 passed

Notes

On legacy non-UTF-8 stdout encodings, print() could raise UnicodeEncodeError where escaped output would not. This trade-off is expected for a CLI targeting UTF-8 JSON consumers and matches the issue intent.

Set ensure_ascii=False on user-facing json.dumps() calls so non-ASCII
MCP tool output (CJK, emoji, etc.) is serialized as UTF-8 rather than
\uXXXX escapes, reducing token waste and improving readability.

Fixes knowsuchagency#62
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.

uses (default), producing -escaped non-ASCII output

1 participant