|
| 1 | +import pytest |
| 2 | + |
| 3 | +from mcp.server.fastmcp import FastMCP |
| 4 | +from mcp.shared.memory import ( |
| 5 | + create_connected_server_and_client_session as create_session, |
| 6 | +) |
| 7 | + |
| 8 | +# Mark the whole module for async tests |
| 9 | +pytestmark = pytest.mark.anyio |
| 10 | + |
| 11 | + |
| 12 | +async def test_list_tools_cursor_parameter(): |
| 13 | + """Test that the cursor parameter is accepted for list_tools. |
| 14 | + |
| 15 | + Note: FastMCP doesn't currently implement pagination, so this test |
| 16 | + only verifies that the cursor parameter is accepted by the client. |
| 17 | + """ |
| 18 | + server = FastMCP("test") |
| 19 | + |
| 20 | + # Create a couple of test tools |
| 21 | + @server.tool(name="test_tool_1") |
| 22 | + async def test_tool_1() -> str: |
| 23 | + """First test tool""" |
| 24 | + return "Result 1" |
| 25 | + |
| 26 | + @server.tool(name="test_tool_2") |
| 27 | + async def test_tool_2() -> str: |
| 28 | + """Second test tool""" |
| 29 | + return "Result 2" |
| 30 | + |
| 31 | + async with create_session(server._mcp_server) as client_session: |
| 32 | + # Test without cursor parameter (omitted) |
| 33 | + result1 = await client_session.list_tools() |
| 34 | + assert len(result1.tools) == 2 |
| 35 | + |
| 36 | + # Test with cursor=None |
| 37 | + result2 = await client_session.list_tools(cursor=None) |
| 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 |
| 43 | + |
| 44 | + # Test with empty string cursor |
| 45 | + result4 = await client_session.list_tools(cursor="") |
| 46 | + assert len(result4.tools) == 2 |
| 47 | + |
| 48 | + |
| 49 | +async def test_list_resources_cursor_parameter(): |
| 50 | + """Test that the cursor parameter is accepted for list_resources. |
| 51 | +
|
| 52 | + Note: FastMCP doesn't currently implement pagination, so this test |
| 53 | + only verifies that the cursor parameter is accepted by the client. |
| 54 | + """ |
| 55 | + server = FastMCP("test") |
| 56 | + |
| 57 | + # Create a test resource |
| 58 | + @server.resource("resource://test/data") |
| 59 | + async def test_resource() -> str: |
| 60 | + """Test resource""" |
| 61 | + return "Test data" |
| 62 | + |
| 63 | + async with create_session(server._mcp_server) as client_session: |
| 64 | + # Test without cursor parameter (omitted) |
| 65 | + result1 = await client_session.list_resources() |
| 66 | + assert len(result1.resources) >= 1 |
| 67 | + |
| 68 | + # Test with cursor=None |
| 69 | + result2 = await client_session.list_resources(cursor=None) |
| 70 | + assert len(result2.resources) >= 1 |
| 71 | + |
| 72 | + # Test with cursor as string |
| 73 | + result3 = await client_session.list_resources(cursor="some_cursor") |
| 74 | + assert len(result3.resources) >= 1 |
| 75 | + |
| 76 | + # Test with empty string cursor |
| 77 | + result4 = await client_session.list_resources(cursor="") |
| 78 | + assert len(result4.resources) >= 1 |
| 79 | + |
| 80 | + |
| 81 | +async def test_list_prompts_cursor_parameter(): |
| 82 | + """Test that the cursor parameter is accepted for list_prompts. |
| 83 | +
|
| 84 | + Note: FastMCP doesn't currently implement pagination, so this test |
| 85 | + only verifies that the cursor parameter is accepted by the client. |
| 86 | + """ |
| 87 | + server = FastMCP("test") |
| 88 | + |
| 89 | + # Create a test prompt |
| 90 | + @server.prompt() |
| 91 | + async def test_prompt(name: str) -> str: |
| 92 | + """Test prompt""" |
| 93 | + return f"Hello, {name}!" |
| 94 | + |
| 95 | + async with create_session(server._mcp_server) as client_session: |
| 96 | + # Test without cursor parameter (omitted) |
| 97 | + result1 = await client_session.list_prompts() |
| 98 | + assert len(result1.prompts) >= 1 |
| 99 | + |
| 100 | + # Test with cursor=None |
| 101 | + result2 = await client_session.list_prompts(cursor=None) |
| 102 | + assert len(result2.prompts) >= 1 |
| 103 | + |
| 104 | + # Test with cursor as string |
| 105 | + result3 = await client_session.list_prompts(cursor="some_cursor") |
| 106 | + assert len(result3.prompts) >= 1 |
| 107 | + |
| 108 | + # Test with empty string cursor |
| 109 | + result4 = await client_session.list_prompts(cursor="") |
| 110 | + assert len(result4.prompts) >= 1 |
| 111 | + |
| 112 | + |
| 113 | +async def test_list_resource_templates_cursor_parameter(): |
| 114 | + """Test that the cursor parameter is accepted for list_resource_templates. |
| 115 | +
|
| 116 | + Note: FastMCP doesn't currently implement pagination, so this test |
| 117 | + only verifies that the cursor parameter is accepted by the client. |
| 118 | + """ |
| 119 | + server = FastMCP("test") |
| 120 | + |
| 121 | + # Create a test resource template |
| 122 | + @server.resource("resource://test/{name}") |
| 123 | + async def test_template(name: str) -> str: |
| 124 | + """Test resource template""" |
| 125 | + return f"Data for {name}" |
| 126 | + |
| 127 | + async with create_session(server._mcp_server) as client_session: |
| 128 | + # Test without cursor parameter (omitted) |
| 129 | + result1 = await client_session.list_resource_templates() |
| 130 | + assert len(result1.resourceTemplates) >= 1 |
| 131 | + |
| 132 | + # Test with cursor=None |
| 133 | + result2 = await client_session.list_resource_templates(cursor=None) |
| 134 | + assert len(result2.resourceTemplates) >= 1 |
| 135 | + |
| 136 | + # Test with cursor as string |
| 137 | + result3 = await client_session.list_resource_templates(cursor="some_cursor") |
| 138 | + assert len(result3.resourceTemplates) >= 1 |
| 139 | + |
| 140 | + # Test with empty string cursor |
| 141 | + result4 = await client_session.list_resource_templates(cursor="") |
| 142 | + assert len(result4.resourceTemplates) >= 1 |
0 commit comments