Skip to content

Commit 2d8f08d

Browse files
committed
fix: Address formatting and type checking issues
1 parent 79ec8dc commit 2d8f08d

File tree

5 files changed

+56
-41
lines changed

5 files changed

+56
-41
lines changed

examples/fastmcp/unicode_example.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
mcp = FastMCP()
99

1010

11-
@mcp.tool(description="🌟 A tool that uses various Unicode characters in its description: á é í ó ú ñ 漢字 🎉")
11+
@mcp.tool(
12+
description="🌟 A tool that uses various Unicode characters in its description: "
13+
"á é í ó ú ñ 漢字 🎉"
14+
)
1215
def hello_unicode(name: str = "世界", greeting: str = "¡Hola") -> str:
1316
"""
1417
A simple tool that demonstrates Unicode handling in:
@@ -31,29 +34,31 @@ def list_emoji_categories() -> list[str]:
3134
"🌍 Travel & Places",
3235
"💡 Objects",
3336
"❤️ Symbols",
34-
"🚩 Flags"
37+
"🚩 Flags",
3538
]
3639

3740

3841
@mcp.tool(description="🔤 Tool that returns text in different scripts")
3942
def multilingual_hello() -> str:
4043
"""Returns hello in different scripts and writing systems."""
41-
return "\n".join([
42-
"English: Hello!",
43-
"Spanish: ¡Hola!",
44-
"French: Bonjour!",
45-
"German: Grüß Gott!",
46-
"Russian: Привет!",
47-
"Greek: Γεια σας!",
48-
"Hebrew: !שָׁלוֹם",
49-
"Arabic: !مرحبا",
50-
"Hindi: नमस्ते!",
51-
"Chinese: 你好!",
52-
"Japanese: こんにちは!",
53-
"Korean: 안녕하세요!",
54-
"Thai: สวัสดี!",
55-
])
44+
return "\n".join(
45+
[
46+
"English: Hello!",
47+
"Spanish: ¡Hola!",
48+
"French: Bonjour!",
49+
"German: Grüß Gott!",
50+
"Russian: Привет!",
51+
"Greek: Γεια σας!",
52+
"Hebrew: !שָׁלוֹם",
53+
"Arabic: !مرحبا",
54+
"Hindi: नमस्ते!",
55+
"Chinese: 你好!",
56+
"Japanese: こんにちは!",
57+
"Korean: 안녕하세요!",
58+
"Thai: สวัสดี!",
59+
]
60+
)
5661

5762

5863
if __name__ == "__main__":
59-
mcp.run()
64+
mcp.run()

tests/client/test_config.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import json
22
import subprocess
3-
from pathlib import Path
43
from unittest.mock import patch
54

65
import pytest
@@ -15,42 +14,39 @@ def temp_config_dir(tmp_path):
1514
config_dir.mkdir()
1615
return config_dir
1716

17+
1818
@pytest.fixture
1919
def mock_config_path(temp_config_dir):
2020
"""Mock get_claude_config_path to return our temporary directory."""
21-
with patch('mcp.cli.claude.get_claude_config_path', return_value=temp_config_dir):
21+
with patch("mcp.cli.claude.get_claude_config_path", return_value=temp_config_dir):
2222
yield temp_config_dir
2323

24+
2425
def test_command_execution(mock_config_path):
2526
"""Test that the generated command can actually be executed."""
2627
# Setup
2728
server_name = "test_server"
2829
file_spec = "test_server.py:app"
29-
30+
3031
# Update config
3132
success = update_claude_config(
3233
file_spec=file_spec,
3334
server_name=server_name,
3435
)
3536
assert success
36-
37+
3738
# Read the generated config
3839
config_file = mock_config_path / "claude_desktop_config.json"
3940
config = json.loads(config_file.read_text())
40-
41+
4142
# Get the command and args
4243
server_config = config["mcpServers"][server_name]
4344
command = server_config["command"]
4445
args = server_config["args"]
4546

4647
test_args = [command] + args + ["--help"]
47-
48-
result = subprocess.run(
49-
test_args,
50-
capture_output=True,
51-
text=True,
52-
timeout=5
53-
)
54-
48+
49+
result = subprocess.run(test_args, capture_output=True, text=True, timeout=5)
50+
5551
assert result.returncode == 0
56-
assert "usage" in result.stdout.lower()
52+
assert "usage" in result.stdout.lower()

tests/issues/test_100_tool_listing.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,32 @@
33

44
pytestmark = pytest.mark.anyio
55

6+
67
async def test_list_tools_returns_all_tools():
78
mcp = FastMCP("TestTools")
8-
9+
910
# Create 100 tools with unique names
1011
num_tools = 100
1112
for i in range(num_tools):
13+
1214
@mcp.tool(name=f"tool_{i}")
1315
def dummy_tool_func():
1416
f"""Tool number {i}"""
1517
return i
16-
globals()[f'dummy_tool_{i}'] = dummy_tool_func # Keep reference to avoid garbage collection
17-
18+
19+
globals()[f"dummy_tool_{i}"] = (
20+
dummy_tool_func # Keep reference to avoid garbage collection
21+
)
22+
1823
# Get all tools
1924
tools = await mcp.list_tools()
20-
25+
2126
# Verify we get all tools
2227
assert len(tools) == num_tools, f"Expected {num_tools} tools, but got {len(tools)}"
23-
28+
2429
# Verify each tool is unique and has the correct name
2530
tool_names = [tool.name for tool in tools]
2631
expected_names = [f"tool_{i}" for i in range(num_tools)]
27-
assert sorted(tool_names) == sorted(expected_names), "Tool names don't match expected names"
32+
assert sorted(tool_names) == sorted(
33+
expected_names
34+
), "Tool names don't match expected names"

tests/server/fastmcp/test_server.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,17 @@ async def test_non_ascii_description(self):
3535
"""Test that FastMCP handles non-ASCII characters in descriptions correctly"""
3636
mcp = FastMCP()
3737

38-
@mcp.tool(description="🌟 This tool uses emojis and UTF-8 characters: á é í ó ú ñ 漢字 🎉")
38+
@mcp.tool(
39+
description="🌟 This tool uses emojis and UTF-8 characters: á é í ó ú ñ 漢字 🎉"
40+
)
3941
def hello_world(name: str = "世界") -> str:
4042
return f"¡Hola, {name}! 👋"
4143

4244
async with client_session(mcp._mcp_server) as client:
4345
tools = await client.list_tools()
4446
assert len(tools.tools) == 1
4547
tool = tools.tools[0]
48+
assert tool.description is not None
4649
assert "🌟" in tool.description
4750
assert "漢字" in tool.description
4851
assert "🎉" in tool.description

tests/server/test_session.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@
1818

1919
@pytest.mark.anyio
2020
async def test_server_session_initialize():
21-
server_to_client_send, server_to_client_receive = anyio.create_memory_object_stream[JSONRPCMessage](1)
22-
client_to_server_send, client_to_server_receive = anyio.create_memory_object_stream[JSONRPCMessage](1)
21+
server_to_client_send, server_to_client_receive = anyio.create_memory_object_stream[
22+
JSONRPCMessage
23+
](1)
24+
client_to_server_send, client_to_server_receive = anyio.create_memory_object_stream[
25+
JSONRPCMessage
26+
](1)
2327

2428
async def run_client(client: ClientSession):
2529
async for message in client_session.incoming_messages:

0 commit comments

Comments
 (0)