Closed
Description
Describe the bug
Hello, I encountered an issue where Japanese characters become garbled when using fastmcp.
To Reproduce
Steps to reproduce the behavior:
- Use mcp==1.2.0rc1
- Create test.py
# encoding: utf-8
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("Demo", log_level="DEBUG")
# Add an addition tool
@mcp.tool()
def add(a: int, b: int) -> int:
"""2つの数字を足し合わせます。"""
return a + b
mcp dev test.py
- In the Tools tab, the description is garbled.
Expected behavior
not garbled description.
Screenshots
garbled description.
Desktop (please complete the following information):
- OS: Windows 11
- Python 3.12.8
Additional context
By specifying ensure_ascii=False
when calling json.dumps, the Japanese characters are displayed correctly.
For example, in mcp/server/stdio.py
:
# mcp/server/stdio.py
async def stdout_writer():
try:
async with write_stream_reader:
async for message in write_stream_reader:
model = message.model_dump(by_alias=True, exclude_none=True)
body = json.dumps(model, ensure_ascii=False)
await stdout.write(body + "\n")
await stdout.flush()
except anyio.ClosedResourceError:
await anyio.lowlevel.checkpoint()
If needed, I can open a PR with this change.