test: Add test for non-ASCII character handling in FastMCP tools

This commit is contained in:
David Soria Parra
2025-01-03 14:50:48 +00:00
parent d93b99e163
commit 43796bfa24

View File

@@ -30,6 +30,29 @@ class TestServer:
mcp = FastMCP()
assert mcp.name == "FastMCP"
@pytest.mark.anyio
async def test_non_ascii_description(self):
"""Test that FastMCP handles non-ASCII characters in descriptions correctly"""
mcp = FastMCP()
@mcp.tool(description="🌟 This tool uses emojis and UTF-8 characters: á é í ó ú ñ 漢字 🎉")
def hello_world(name: str = "世界") -> str:
return f"¡Hola, {name}! 👋"
async with client_session(mcp._mcp_server) as client:
tools = await client.list_tools()
assert len(tools.tools) == 1
tool = tools.tools[0]
assert "🌟" in tool.description
assert "漢字" in tool.description
assert "🎉" in tool.description
result = await client.call_tool("hello_world", {})
assert len(result.content) == 1
content = result.content[0]
assert isinstance(content, TextContent)
assert "¡Hola, 世界! 👋" == content.text
@pytest.mark.anyio
async def test_add_tool_decorator(self):
mcp = FastMCP()