Skip to content

Commit 10174b9

Browse files
simplify cursor tests and add comment about pagination support
- Reduce test complexity to just verify cursor parameter acceptance - Add docstring note explaining that FastMCP doesn't implement pagination yet - Test cursor as None, string, empty string, and omitted
1 parent e4d49d9 commit 10174b9

File tree

1 file changed

+18
-73
lines changed

1 file changed

+18
-73
lines changed

tests/client/test_list_tools_cursor.py

Lines changed: 18 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -9,50 +9,15 @@
99
pytestmark = pytest.mark.anyio
1010

1111

12-
async def test_list_tools_with_cursor_pagination():
13-
"""Test list_tools with cursor pagination using a server with many tools."""
12+
async def test_list_tools_cursor_parameter():
13+
"""Test that the cursor parameter is accepted in various forms.
14+
15+
Note: FastMCP doesn't currently implement pagination, so these tests
16+
only verify that the cursor parameter is accepted by the client.
17+
"""
1418
server = FastMCP("test")
1519

16-
# Create 100 tools to test pagination
17-
num_tools = 100
18-
for i in range(num_tools):
19-
20-
@server.tool(name=f"tool_{i}")
21-
async def dummy_tool(index: int = i) -> str:
22-
f"""Tool number {index}"""
23-
return f"Result from tool {index}"
24-
25-
# Keep reference to avoid garbage collection
26-
globals()[f"dummy_tool_{i}"] = dummy_tool
27-
28-
async with create_session(server._mcp_server) as client_session:
29-
all_tools = []
30-
cursor = None
31-
32-
# Paginate through all results
33-
while True:
34-
result = await client_session.list_tools(cursor=cursor)
35-
all_tools.extend(result.tools)
36-
37-
if result.nextCursor is None:
38-
break
39-
40-
cursor = result.nextCursor
41-
42-
# Verify we got all tools
43-
assert len(all_tools) == num_tools
44-
45-
# Verify each tool is unique and has the correct name
46-
tool_names = [tool.name for tool in all_tools]
47-
expected_names = [f"tool_{i}" for i in range(num_tools)]
48-
assert sorted(tool_names) == sorted(expected_names)
49-
50-
51-
async def test_list_tools_without_cursor():
52-
"""Test the list_tools method without cursor (backward compatibility)."""
53-
server = FastMCP("test")
54-
55-
# Create a few tools
20+
# Create a couple of test tools
5621
@server.tool(name="test_tool_1")
5722
async def test_tool_1() -> str:
5823
"""First test tool"""
@@ -64,38 +29,18 @@ async def test_tool_2() -> str:
6429
return "Result 2"
6530

6631
async with create_session(server._mcp_server) as client_session:
67-
# Should work without cursor argument
68-
result = await client_session.list_tools()
69-
assert len(result.tools) == 2
70-
tool_names = [tool.name for tool in result.tools]
71-
assert "test_tool_1" in tool_names
72-
assert "test_tool_2" in tool_names
73-
74-
75-
async def test_list_tools_cursor_parameter_accepted():
76-
"""Test that the cursor parameter is accepted by the client method."""
77-
server = FastMCP("test")
78-
79-
# Create a few tools
80-
for i in range(5):
81-
82-
@server.tool(name=f"tool_{i}")
83-
async def dummy_tool(index: int = i) -> str:
84-
f"""Tool number {index}"""
85-
return f"Result from tool {index}"
86-
87-
globals()[f"dummy_tool_{i}"] = dummy_tool
88-
89-
async with create_session(server._mcp_server) as client_session:
90-
# Test that cursor parameter is accepted
32+
# Test without cursor parameter (omitted)
9133
result1 = await client_session.list_tools()
92-
assert len(result1.tools) == 5
34+
assert len(result1.tools) == 2
9335

94-
# Test with explicit None cursor
36+
# Test with cursor=None
9537
result2 = await client_session.list_tools(cursor=None)
96-
assert len(result2.tools) == 5
38+
assert len(result2.tools) == 2
39+
40+
# Test with cursor as string
41+
result3 = await client_session.list_tools(cursor="some_cursor_value")
42+
assert len(result3.tools) == 2
9743

98-
# Test with a cursor value (even though this server doesn't paginate)
99-
result3 = await client_session.list_tools(cursor="some_cursor")
100-
# The cursor is sent to the server, but this particular server ignores it
101-
assert len(result3.tools) == 5
44+
# Test with empty string cursor
45+
result4 = await client_session.list_tools(cursor="")
46+
assert len(result4.tools) == 2

0 commit comments

Comments
 (0)