From 79ec8dccdb62e1a7d7e2de711af185236c5f87fb Mon Sep 17 00:00:00 2001 From: David Soria Parra Date: Fri, 3 Jan 2025 15:19:57 +0000 Subject: [PATCH] test: Add test for unlimited tool listing (issue #100) --- tests/issues/test_100_tool_listing.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/issues/test_100_tool_listing.py diff --git a/tests/issues/test_100_tool_listing.py b/tests/issues/test_100_tool_listing.py new file mode 100644 index 0000000..2810a02 --- /dev/null +++ b/tests/issues/test_100_tool_listing.py @@ -0,0 +1,27 @@ +import pytest +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 + + # Get all tools + tools = await mcp.list_tools() + + # Verify we get all tools + assert len(tools) == num_tools, f"Expected {num_tools} tools, but got {len(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" \ No newline at end of file