| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,7 +8,10 @@ | |||
| 8 | 8 | mcp = FastMCP() | |
| 9 | 9 | ||
| 10 | 10 | ||
| 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 | + ) | ||
| 12 | 15 | def hello_unicode(name: str = "世界", greeting: str = "¡Hola") -> str: | |
| 13 | 16 | """ | |
| 14 | 17 | A simple tool that demonstrates Unicode handling in: | |
@@ -31,29 +34,31 @@ def list_emoji_categories() -> list[str]: | |||
| 31 | 34 | "🌍 Travel & Places", | |
| 32 | 35 | "💡 Objects", | |
| 33 | 36 | "❤️ Symbols", | |
| 34 | - "🚩 Flags" | ||
| 37 | + "🚩 Flags", | ||
| 35 | 38 | ] | |
| 36 | 39 | ||
| 37 | 40 | ||
| 38 | 41 | @mcp.tool(description="🔤 Tool that returns text in different scripts") | |
| 39 | 42 | def multilingual_hello() -> str: | |
| 40 | 43 | """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 | + ) | ||
| 56 | 61 | ||
| 57 | 62 | ||
| 58 | 63 | if __name__ == "__main__": | |
| 59 | - mcp.run() | ||
| 64 | + mcp.run() | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,5 @@ | |||
| 1 | 1 | import json | |
| 2 | 2 | import subprocess | |
| 3 | - from pathlib import Path | ||
| 4 | 3 | from unittest.mock import patch | |
| 5 | 4 | ||
| 6 | 5 | import pytest | |
@@ -15,42 +14,39 @@ def temp_config_dir(tmp_path): | |||
| 15 | 14 | config_dir.mkdir() | |
| 16 | 15 | return config_dir | |
| 17 | 16 | ||
| 17 | + | ||
| 18 | 18 | @pytest.fixture | |
| 19 | 19 | def mock_config_path(temp_config_dir): | |
| 20 | 20 | """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): | ||
| 22 | 22 | yield temp_config_dir | |
| 23 | 23 | ||
| 24 | + | ||
| 24 | 25 | def test_command_execution(mock_config_path): | |
| 25 | 26 | """Test that the generated command can actually be executed.""" | |
| 26 | 27 | # Setup | |
| 27 | 28 | server_name = "test_server" | |
| 28 | 29 | file_spec = "test_server.py:app" | |
| 29 | - | ||
| 30 | + | ||
| 30 | 31 | # Update config | |
| 31 | 32 | success = update_claude_config( | |
| 32 | 33 | file_spec=file_spec, | |
| 33 | 34 | server_name=server_name, | |
| 34 | 35 | ) | |
| 35 | 36 | assert success | |
| 36 | - | ||
| 37 | + | ||
| 37 | 38 | # Read the generated config | |
| 38 | 39 | config_file = mock_config_path / "claude_desktop_config.json" | |
| 39 | 40 | config = json.loads(config_file.read_text()) | |
| 40 | - | ||
| 41 | + | ||
| 41 | 42 | # Get the command and args | |
| 42 | 43 | server_config = config["mcpServers"][server_name] | |
| 43 | 44 | command = server_config["command"] | |
| 44 | 45 | args = server_config["args"] | |
| 45 | 46 | ||
| 46 | 47 | 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 | + | ||
| 55 | 51 | assert result.returncode == 0 | |
| 56 | - assert "usage" in result.stdout.lower() | ||
| 52 | + assert "usage" in result.stdout.lower() | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,25 +3,32 @@ | |||
| 3 | 3 | ||
| 4 | 4 | pytestmark = pytest.mark.anyio | |
| 5 | 5 | ||
| 6 | + | ||
| 6 | 7 | async def test_list_tools_returns_all_tools(): | |
| 7 | 8 | mcp = FastMCP("TestTools") | |
| 8 | - | ||
| 9 | + | ||
| 9 | 10 | # Create 100 tools with unique names | |
| 10 | 11 | num_tools = 100 | |
| 11 | 12 | for i in range(num_tools): | |
| 13 | + | ||
| 12 | 14 | @mcp.tool(name=f"tool_{i}") | |
| 13 | 15 | def dummy_tool_func(): | |
| 14 | 16 | f"""Tool number {i}""" | |
| 15 | 17 | 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 | + | ||
| 18 | 23 | # Get all tools | |
| 19 | 24 | tools = await mcp.list_tools() | |
| 20 | - | ||
| 25 | + | ||
| 21 | 26 | # Verify we get all tools | |
| 22 | 27 | assert len(tools) == num_tools, f"Expected {num_tools} tools, but got {len(tools)}" | |
| 23 | - | ||
| 28 | + | ||
| 24 | 29 | # Verify each tool is unique and has the correct name | |
| 25 | 30 | tool_names = [tool.name for tool in tools] | |
| 26 | 31 | 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" | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,14 +35,17 @@ async def test_non_ascii_description(self): | |||
| 35 | 35 | """Test that FastMCP handles non-ASCII characters in descriptions correctly""" | |
| 36 | 36 | mcp = FastMCP() | |
| 37 | 37 | ||
| 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 | + ) | ||
| 39 | 41 | def hello_world(name: str = "世界") -> str: | |
| 40 | 42 | return f"¡Hola, {name}! 👋" | |
| 41 | 43 | ||
| 42 | 44 | async with client_session(mcp._mcp_server) as client: | |
| 43 | 45 | tools = await client.list_tools() | |
| 44 | 46 | assert len(tools.tools) == 1 | |
| 45 | 47 | tool = tools.tools[0] | |
| 48 | + assert tool.description is not None | ||
| 46 | 49 | assert "🌟" in tool.description | |
| 47 | 50 | assert "漢字" in tool.description | |
| 48 | 51 | assert "🎉" in tool.description | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,8 +18,12 @@ | |||
| 18 | 18 | ||
| 19 | 19 | @pytest.mark.anyio | |
| 20 | 20 | 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) | ||
| 23 | 27 | ||
| 24 | 28 | async def run_client(client: ClientSession): | |
| 25 | 29 | async for message in client_session.incoming_messages: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments