@@ -229,29 +229,27 @@ async def test_invalid_url_is_rejected_by_pydantic(web: FakeWeb, url: str) -> No
229229 assert web .requests == []
230230
231231
232- # KNOWN BUG #4988: call_tool ignores the tool name and runs fetch for any name; the fix changes this assertion.
233- async def test_call_tool_never_checks_the_tool_name (web : FakeWeb ) -> None :
234- # Characterizes call_tool ignoring `name`: an unknown tool name is not
235- # rejected, the SDK skips schema validation for it (the tool is not
236- # listed), and the URL is fetched as if `fetch` had been called.
232+ async def test_unknown_tool_name_is_rejected_without_fetching (web : FakeWeb ) -> None :
233+ # The SDK skips schema validation for a tool it has not listed, so the
234+ # name check in call_tool is what stops an unknown name from fetching.
237235 web .add (ROBOTS , plain ("" , status = 404 ))
238236 web .add (PAGE , plain ("fetched anyway" ))
239237 async with connect () as (session , _ ):
240238 result = await session .call_tool ("nope" , {"url" : PAGE })
241- assert wire (result )["isError" ] is False
242- assert text_of (result ). endswith ( "fetched anyway" )
243- assert web .urls () == [ROBOTS , PAGE ]
239+ assert wire (result )["isError" ] is True
240+ assert text_of (result ) == "Unknown tool: nope"
241+ assert web .requests == []
244242
245243
246- # KNOWN BUG #4988: call_tool ignores the tool name and runs fetch for any name; the fix changes this assertion.
247- async def test_unknown_tool_name_still_validates_through_pydantic (
244+ async def test_unknown_tool_name_is_rejected_before_argument_validation (
248245 web : FakeWeb ,
249246) -> None :
247+ # An unknown name is reported as such, not as a missing `url` argument.
250248 async with connect () as (session , _ ):
251249 result = await session .call_tool ("nope" , {})
252250 assert wire (result )["isError" ] is True
253- assert "url" in text_of (result )
254- assert "Field required" in text_of ( result )
251+ assert text_of (result ) == "Unknown tool: nope"
252+ assert web . requests == []
255253
256254
257255# --------------------------------------------------------------------------
@@ -796,13 +794,21 @@ async def test_get_prompt_without_url_is_a_jsonrpc_error(
796794 assert web .requests == []
797795
798796
799- # KNOWN BUG #4988: get_prompt ignores the prompt name and serves fetch for any name; the fix changes this assertion.
800- async def test_get_prompt_never_checks_the_prompt_name (web : FakeWeb ) -> None :
801- # Like call_tool, get_prompt ignores `name`.
797+ @pytest .mark .parametrize ("arguments" , [{"url" : PAGE }, None ])
798+ async def test_get_prompt_with_unknown_name_is_a_jsonrpc_error (
799+ web : FakeWeb , arguments : dict [str , str ] | None
800+ ) -> None :
801+ # The name is checked first, so an unknown prompt is reported as such
802+ # whether or not a URL was given, and nothing is fetched.
802803 web .add (PAGE , plain ("ok" ))
803804 async with connect () as (session , _ ):
804- result = await session .get_prompt ("nope" , {"url" : PAGE })
805- assert wire (result )["description" ] == f"Contents of { PAGE } "
805+ with pytest .raises (McpError ) as excinfo :
806+ await session .get_prompt ("nope" , arguments )
807+ assert wire (excinfo .value .error ) == {
808+ "code" : INVALID_PARAMS ,
809+ "message" : "Unknown prompt: nope" ,
810+ }
811+ assert web .requests == []
806812
807813
808814async def test_get_prompt_does_not_validate_the_url (
0 commit comments