Skip to content

Commit 5d025a9

Browse files
Tapan Chughclaude
andcommitted
fix: Fix test failures after prefix filtering implementation
This commit fixes all test failures that occurred after implementing consistent prefix-based filtering across tools, prompts, and resources. Changes: - Add required URI fields to all Tool instances in tests - Update all list_tools handlers to accept request parameter - Fix client session to use ListRequestParams for all list methods - Update test handlers in streamable_http, SSE, and WS tests The tests were failing because: 1. Tool objects now require a URI field 2. Low-level server list_tools handlers expect a request parameter 3. Client session was using old RequestParams class names All tests now pass except for one unrelated connection error. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 6ed58df commit 5d025a9

14 files changed

+55
-21
lines changed

src/mcp/client/session.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ async def list_resources(self, prefix: str | None = None, cursor: str | None = N
225225
"""Send a resources/list request."""
226226
params = None
227227
if cursor is not None or prefix is not None:
228-
params = types.ListResourcesRequestParams(prefix=prefix, cursor=cursor)
228+
params = types.ListRequestParams(prefix=prefix, cursor=cursor)
229229
return await self.send_request(
230230
types.ClientRequest(
231231
types.ListResourcesRequest(
@@ -244,7 +244,7 @@ async def list_resource_templates(
244244
"""Send a resources/templates/list request."""
245245
params = None
246246
if cursor is not None or prefix is not None:
247-
params = types.ListResourceTemplatesRequestParams(prefix=prefix, cursor=cursor)
247+
params = types.ListRequestParams(prefix=prefix, cursor=cursor)
248248
return await self.send_request(
249249
types.ClientRequest(
250250
types.ListResourceTemplatesRequest(

src/mcp/server/fastmcp/prompts/manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def add_prompt(
4343
) -> Prompt:
4444
"""Add a prompt to the manager."""
4545
logger.debug(f"Adding prompt: {prompt.name} with URI: {prompt.uri}")
46-
46+
4747
# Check for duplicates
4848
existing = self._prompts.get(prompt.uri)
4949
if existing:

tests/client/test_output_schema_validation.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ async def test_tool_structured_output_client_side_validation_basemodel(self):
4242
}
4343

4444
@server.list_tools()
45-
async def list_tools():
45+
async def list_tools(request):
4646
return [
4747
Tool(
48+
uri="tool://get_user",
4849
name="get_user",
4950
description="Get user data",
5051
inputSchema={"type": "object"},
@@ -81,9 +82,10 @@ async def test_tool_structured_output_client_side_validation_primitive(self):
8182
}
8283

8384
@server.list_tools()
84-
async def list_tools():
85+
async def list_tools(request):
8586
return [
8687
Tool(
88+
uri="tool://calculate",
8789
name="calculate",
8890
description="Calculate something",
8991
inputSchema={"type": "object"},
@@ -112,9 +114,10 @@ async def test_tool_structured_output_client_side_validation_dict_typed(self):
112114
output_schema = {"type": "object", "additionalProperties": {"type": "integer"}, "title": "get_scores_Output"}
113115

114116
@server.list_tools()
115-
async def list_tools():
117+
async def list_tools(request):
116118
return [
117119
Tool(
120+
uri="tool://get_scores",
118121
name="get_scores",
119122
description="Get scores",
120123
inputSchema={"type": "object"},
@@ -147,9 +150,10 @@ async def test_tool_structured_output_client_side_validation_missing_required(se
147150
}
148151

149152
@server.list_tools()
150-
async def list_tools():
153+
async def list_tools(request):
151154
return [
152155
Tool(
156+
uri="tool://get_person",
153157
name="get_person",
154158
description="Get person data",
155159
inputSchema={"type": "object"},
@@ -175,7 +179,7 @@ async def test_tool_not_listed_warning(self, caplog):
175179
server = Server("test-server")
176180

177181
@server.list_tools()
178-
async def list_tools():
182+
async def list_tools(request):
179183
# Return empty list - tool is not listed
180184
return []
181185

tests/client/test_session_group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def hook(name, server_info):
5858
return f"{(server_info.name)}-{name}"
5959

6060
mcp_session_group = ClientSessionGroup(component_name_hook=hook)
61-
mcp_session_group._tools = {"server1-my_tool": types.Tool(name="my_tool", inputSchema={})}
61+
mcp_session_group._tools = {"server1-my_tool": types.Tool(uri="tool://my_tool", name="my_tool", inputSchema={})}
6262
mcp_session_group._tool_to_session = {"server1-my_tool": mock_session}
6363
text_content = types.TextContent(type="text", text="OK")
6464
mock_session.call_tool.return_value = types.CallToolResult(content=[text_content])

tests/issues/test_88_random_error.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,16 @@ async def test_notification_validation_error(tmp_path: Path):
3131
slow_request_lock = anyio.Event()
3232

3333
@server.list_tools()
34-
async def list_tools() -> list[types.Tool]:
34+
async def list_tools(request) -> list[types.Tool]:
3535
return [
3636
types.Tool(
37+
uri="tool://slow",
3738
name="slow",
3839
description="A slow tool",
3940
inputSchema={"type": "object"},
4041
),
4142
types.Tool(
43+
uri="tool://fast",
4244
name="fast",
4345
description="A fast tool",
4446
inputSchema={"type": "object"},

tests/server/test_cancel_handling.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ async def test_server_remains_functional_after_cancel():
3131
first_request_id = None
3232

3333
@server.list_tools()
34-
async def handle_list_tools() -> list[Tool]:
34+
async def handle_list_tools(request) -> list[Tool]:
3535
return [
3636
Tool(
37+
uri="tool://test_tool",
3738
name="test_tool",
3839
description="Tool for testing",
3940
inputSchema={},

tests/server/test_lowlevel_input_validation.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async def run_tool_test(
3535
server = Server("test")
3636

3737
@server.list_tools()
38-
async def list_tools():
38+
async def list_tools(request):
3939
return tools
4040

4141
@server.call_tool()
@@ -99,6 +99,7 @@ async def handle_messages():
9999
def create_add_tool() -> Tool:
100100
"""Create a standard 'add' tool for testing."""
101101
return Tool(
102+
uri="tool://add",
102103
name="add",
103104
description="Add two numbers",
104105
inputSchema={
@@ -189,6 +190,7 @@ async def test_cache_refresh_on_missing_tool():
189190
"""Test that tool cache is refreshed when tool is not found."""
190191
tools = [
191192
Tool(
193+
uri="tool://multiply",
192194
name="multiply",
193195
description="Multiply two numbers",
194196
inputSchema={
@@ -230,6 +232,7 @@ async def test_enum_constraint_validation():
230232
"""Test that enum constraints are validated."""
231233
tools = [
232234
Tool(
235+
uri="tool://greet",
233236
name="greet",
234237
description="Greet someone",
235238
inputSchema={
@@ -267,6 +270,7 @@ async def test_tool_not_in_list_logs_warning(caplog):
267270
"""Test that calling a tool not in list_tools logs a warning and skips validation."""
268271
tools = [
269272
Tool(
273+
uri="tool://add",
270274
name="add",
271275
description="Add two numbers",
272276
inputSchema={

tests/server/test_lowlevel_output_validation.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async def run_tool_test(
3535
server = Server("test")
3636

3737
@server.list_tools()
38-
async def list_tools():
38+
async def list_tools(request):
3939
return tools
4040

4141
@server.call_tool()
@@ -101,6 +101,7 @@ async def test_content_only_without_output_schema():
101101
"""Test returning content only when no outputSchema is defined."""
102102
tools = [
103103
Tool(
104+
uri="tool://echo",
104105
name="echo",
105106
description="Echo a message",
106107
inputSchema={
@@ -140,6 +141,7 @@ async def test_dict_only_without_output_schema():
140141
"""Test returning dict only when no outputSchema is defined."""
141142
tools = [
142143
Tool(
144+
uri="tool://get_info",
143145
name="get_info",
144146
description="Get structured information",
145147
inputSchema={
@@ -177,6 +179,7 @@ async def test_both_content_and_dict_without_output_schema():
177179
"""Test returning both content and dict when no outputSchema is defined."""
178180
tools = [
179181
Tool(
182+
uri="tool://process",
180183
name="process",
181184
description="Process data",
182185
inputSchema={
@@ -215,6 +218,7 @@ async def test_content_only_with_output_schema_error():
215218
"""Test error when outputSchema is defined but only content is returned."""
216219
tools = [
217220
Tool(
221+
uri="tool://structured_tool",
218222
name="structured_tool",
219223
description="Tool expecting structured output",
220224
inputSchema={
@@ -254,6 +258,7 @@ async def test_valid_dict_with_output_schema():
254258
"""Test valid dict output matching outputSchema."""
255259
tools = [
256260
Tool(
261+
uri="tool://calc",
257262
name="calc",
258263
description="Calculate result",
259264
inputSchema={
@@ -303,6 +308,7 @@ async def test_invalid_dict_with_output_schema():
303308
"""Test dict output that doesn't match outputSchema."""
304309
tools = [
305310
Tool(
311+
uri="tool://user_info",
306312
name="user_info",
307313
description="Get user information",
308314
inputSchema={
@@ -347,6 +353,7 @@ async def test_both_content_and_valid_dict_with_output_schema():
347353
"""Test returning both content and valid dict with outputSchema."""
348354
tools = [
349355
Tool(
356+
uri="tool://analyze",
350357
name="analyze",
351358
description="Analyze data",
352359
inputSchema={
@@ -394,6 +401,7 @@ async def test_output_schema_type_validation():
394401
"""Test outputSchema validates types correctly."""
395402
tools = [
396403
Tool(
404+
uri="tool://stats",
397405
name="stats",
398406
description="Get statistics",
399407
inputSchema={

tests/server/test_lowlevel_tool_annotations.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ async def test_lowlevel_server_tool_annotations():
2020

2121
# Create a tool with annotations
2222
@server.list_tools()
23-
async def list_tools():
23+
async def list_tools(request):
2424
return [
2525
Tool(
26+
uri="tool://echo",
2627
name="echo",
2728
description="Echo a message back",
2829
inputSchema={

tests/shared/test_progress_notifications.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ async def handle_progress(
7676

7777
# Register list tool handler
7878
@server.list_tools()
79-
async def handle_list_tools() -> list[types.Tool]:
79+
async def handle_list_tools(request) -> list[types.Tool]:
8080
return [
8181
types.Tool(
82+
uri="tool://test_tool",
8283
name="test_tool",
8384
description="A tool that sends progress notifications <o/",
8485
inputSchema={},

0 commit comments

Comments
 (0)