mirror of
https://github.com/aljazceru/mcp-python-sdk.git
synced 2025-12-19 14:54:24 +01:00
fix: Address formatting and type checking issues
This commit is contained in:
@@ -8,7 +8,10 @@ from mcp.server.fastmcp import FastMCP
|
||||
mcp = FastMCP()
|
||||
|
||||
|
||||
@mcp.tool(description="🌟 A tool that uses various Unicode characters in its description: á é í ó ú ñ 漢字 🎉")
|
||||
@mcp.tool(
|
||||
description="🌟 A tool that uses various Unicode characters in its description: "
|
||||
"á é í ó ú ñ 漢字 🎉"
|
||||
)
|
||||
def hello_unicode(name: str = "世界", greeting: str = "¡Hola") -> str:
|
||||
"""
|
||||
A simple tool that demonstrates Unicode handling in:
|
||||
@@ -31,14 +34,15 @@ def list_emoji_categories() -> list[str]:
|
||||
"🌍 Travel & Places",
|
||||
"💡 Objects",
|
||||
"❤️ Symbols",
|
||||
"🚩 Flags"
|
||||
"🚩 Flags",
|
||||
]
|
||||
|
||||
|
||||
@mcp.tool(description="🔤 Tool that returns text in different scripts")
|
||||
def multilingual_hello() -> str:
|
||||
"""Returns hello in different scripts and writing systems."""
|
||||
return "\n".join([
|
||||
return "\n".join(
|
||||
[
|
||||
"English: Hello!",
|
||||
"Spanish: ¡Hola!",
|
||||
"French: Bonjour!",
|
||||
@@ -52,7 +56,8 @@ def multilingual_hello() -> str:
|
||||
"Japanese: こんにちは!",
|
||||
"Korean: 안녕하세요!",
|
||||
"Thai: สวัสดี!",
|
||||
])
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import json
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
@@ -15,12 +14,14 @@ def temp_config_dir(tmp_path):
|
||||
config_dir.mkdir()
|
||||
return config_dir
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_config_path(temp_config_dir):
|
||||
"""Mock get_claude_config_path to return our temporary directory."""
|
||||
with patch('mcp.cli.claude.get_claude_config_path', return_value=temp_config_dir):
|
||||
with patch("mcp.cli.claude.get_claude_config_path", return_value=temp_config_dir):
|
||||
yield temp_config_dir
|
||||
|
||||
|
||||
def test_command_execution(mock_config_path):
|
||||
"""Test that the generated command can actually be executed."""
|
||||
# Setup
|
||||
@@ -45,12 +46,7 @@ def test_command_execution(mock_config_path):
|
||||
|
||||
test_args = [command] + args + ["--help"]
|
||||
|
||||
result = subprocess.run(
|
||||
test_args,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=5
|
||||
)
|
||||
result = subprocess.run(test_args, capture_output=True, text=True, timeout=5)
|
||||
|
||||
assert result.returncode == 0
|
||||
assert "usage" in result.stdout.lower()
|
||||
@@ -3,17 +3,22 @@ from mcp.server.fastmcp import FastMCP
|
||||
|
||||
pytestmark = pytest.mark.anyio
|
||||
|
||||
|
||||
async def test_list_tools_returns_all_tools():
|
||||
mcp = FastMCP("TestTools")
|
||||
|
||||
# Create 100 tools with unique names
|
||||
num_tools = 100
|
||||
for i in range(num_tools):
|
||||
|
||||
@mcp.tool(name=f"tool_{i}")
|
||||
def dummy_tool_func():
|
||||
f"""Tool number {i}"""
|
||||
return i
|
||||
globals()[f'dummy_tool_{i}'] = dummy_tool_func # Keep reference to avoid garbage collection
|
||||
|
||||
globals()[f"dummy_tool_{i}"] = (
|
||||
dummy_tool_func # Keep reference to avoid garbage collection
|
||||
)
|
||||
|
||||
# Get all tools
|
||||
tools = await mcp.list_tools()
|
||||
@@ -24,4 +29,6 @@ async def test_list_tools_returns_all_tools():
|
||||
# Verify each tool is unique and has the correct name
|
||||
tool_names = [tool.name for tool in tools]
|
||||
expected_names = [f"tool_{i}" for i in range(num_tools)]
|
||||
assert sorted(tool_names) == sorted(expected_names), "Tool names don't match expected names"
|
||||
assert sorted(tool_names) == sorted(
|
||||
expected_names
|
||||
), "Tool names don't match expected names"
|
||||
|
||||
@@ -35,7 +35,9 @@ class TestServer:
|
||||
"""Test that FastMCP handles non-ASCII characters in descriptions correctly"""
|
||||
mcp = FastMCP()
|
||||
|
||||
@mcp.tool(description="🌟 This tool uses emojis and UTF-8 characters: á é í ó ú ñ 漢字 🎉")
|
||||
@mcp.tool(
|
||||
description="🌟 This tool uses emojis and UTF-8 characters: á é í ó ú ñ 漢字 🎉"
|
||||
)
|
||||
def hello_world(name: str = "世界") -> str:
|
||||
return f"¡Hola, {name}! 👋"
|
||||
|
||||
@@ -43,6 +45,7 @@ class TestServer:
|
||||
tools = await client.list_tools()
|
||||
assert len(tools.tools) == 1
|
||||
tool = tools.tools[0]
|
||||
assert tool.description is not None
|
||||
assert "🌟" in tool.description
|
||||
assert "漢字" in tool.description
|
||||
assert "🎉" in tool.description
|
||||
|
||||
@@ -18,8 +18,12 @@ from mcp.types import (
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_server_session_initialize():
|
||||
server_to_client_send, server_to_client_receive = anyio.create_memory_object_stream[JSONRPCMessage](1)
|
||||
client_to_server_send, client_to_server_receive = anyio.create_memory_object_stream[JSONRPCMessage](1)
|
||||
server_to_client_send, server_to_client_receive = anyio.create_memory_object_stream[
|
||||
JSONRPCMessage
|
||||
](1)
|
||||
client_to_server_send, client_to_server_receive = anyio.create_memory_object_stream[
|
||||
JSONRPCMessage
|
||||
](1)
|
||||
|
||||
async def run_client(client: ClientSession):
|
||||
async for message in client_session.incoming_messages:
|
||||
|
||||
Reference in New Issue
Block a user