Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Garbled Japanese Characters When Using fastmcp #123

Open
te-chan opened this issue Jan 1, 2025 · 1 comment
Open

Garbled Japanese Characters When Using fastmcp #123

te-chan opened this issue Jan 1, 2025 · 1 comment
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed
Milestone

Comments

@te-chan
Copy link

te-chan commented Jan 1, 2025

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.

@te-chan
Copy link
Author

te-chan commented Jan 1, 2025

This probrem can be resolved by #112

@dsp-ant dsp-ant added this to the SDK 1.2.0 milestone Jan 3, 2025
@dsp-ant dsp-ant added bug Something isn't working help wanted Extra attention is needed labels Jan 3, 2025
@dsp-ant dsp-ant self-assigned this Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants