Skip to content

fix: preserve non-ASCII text in MCP JSON serialization (#6995)#7193

Open
ichbinlucaskim wants to merge 1 commit intomicrosoft:mainfrom
ichbinlucaskim:fix/6995-mcp-ensure-ascii
Open

fix: preserve non-ASCII text in MCP JSON serialization (#6995)#7193
ichbinlucaskim wants to merge 1 commit intomicrosoft:mainfrom
ichbinlucaskim:fix/6995-mcp-ensure-ascii

Conversation

@ichbinlucaskim
Copy link

Summary

This PR fixes MCP JSON serialization so that non-ASCII text (for example, Japanese) is preserved instead of being escaped as \\uXXXX.

Changes

  • Added an internal helper _to_json_str in autogen_ext.tools.mcp._base that calls json.dumps(..., ensure_ascii=False, indent=indent).
  • Updated McpToolAdapter.return_value_as_string to use _to_json_str for serializing tool return values.
  • Updated StreamElicitor.elicit in _host/_elicitation.py to use _to_json_str when rendering the requested schema for the user.
  • Added tests/tools/test_mcp_serialization.py to verify that Japanese text is not escaped.

Tests

  • uv run pytest tests/tools/test_mcp_serialization.py
  • uv run pytest for autogen-ext reports import errors for optional integrations
    (chromadb, mem0, redisvl, torch, ollama, semantic_kernel, graphrag,
    json_schema_to_pydantic) that are not installed in my local environment, but the new MCP serialization tests pass.

## Summary

This PR fixes MCP JSON serialization so that non-ASCII text (for example, Japanese) is preserved instead of being escaped as `\uXXXX`.

## Changes

- Added an internal helper `_to_json_str` in `autogen_ext.tools.mcp._base` that calls `json.dumps(..., ensure_ascii=False, indent=indent)`.
- Updated `McpToolAdapter.return_value_as_string` to use `_to_json_str` for serializing tool return values.
- Updated `StreamElicitor.elicit` in `_host/_elicitation.py` to use `_to_json_str` when rendering the requested schema for the user.
- Added `tests/tools/test_mcp_serialization.py` to verify that Japanese text is not escaped.

## Tests

- `uv run pytest tests/tools/test_mcp_serialization.py` ✓
- `uv run pytest` for `autogen-ext` fails on optional integrations (`chromadb`, `mem0`, `redisvl`, `torch`, `ollama`, `semantic_kernel`, `graphrag`, `json_schema_to_pydantic`) that are not installed in my local environment, but the new MCP tests pass.
@ichbinlucaskim
Copy link
Author

@microsoft-github-policy-service agree

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.

1 participant