Skip to content

Garbled Japanese Characters When Using fastmcp #123

@te-chan

Description

@te-chan

Describe the bug
Hello, I encountered an issue where Japanese characters become garbled when using fastmcp.

To Reproduce
Steps to reproduce the behavior:

  1. Use mcp==1.2.0rc1
  2. 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
  1. mcp dev test.py
  2. In the Tools tab, the description is garbled.

Expected behavior
image
not garbled description.

Screenshots
image
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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions