Skip to content

Commit e5c9bc4

Browse files
author
aj
committed
fix(mcp): preserve non-ASCII text in JSON serialization
json.dumps calls in MCP tool return_value_as_string and StreamElicitor.elicit were missing ensure_ascii=False, causing non-ASCII characters (Japanese, Chinese, Korean, etc.) to be escaped as \uXXXX sequences. This degrades LLM performance when working with non-English text since models handle native characters better than unicode escapes. Fixes #6995
1 parent 13e144e commit e5c9bc4

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

python/packages/autogen-ext/src/autogen_ext/tools/mcp/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,4 @@ def serialize_item(item: Any) -> dict[str, Any]:
194194
else:
195195
return {}
196196

197-
return json.dumps([serialize_item(item) for item in value])
197+
return json.dumps([serialize_item(item) for item in value], ensure_ascii=False)

python/packages/autogen-ext/src/autogen_ext/tools/mcp/_host/_elicitation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ async def elicit(self, params: mcp_types.ElicitRequestParams) -> mcp_types.Elici
8282
prompt = "\n".join(
8383
[
8484
"Input Schema:",
85-
json.dumps(params.requestedSchema, indent=2),
85+
json.dumps(params.requestedSchema, indent=2, ensure_ascii=False),
8686
"Please enter a JSON string following the above schema: ",
8787
]
8888
)

0 commit comments

Comments
 (0)