33import pytest
44from inline_snapshot import snapshot
55from mcp_types import (
6+ INVALID_PARAMS ,
67 ErrorData ,
78 GetPromptResult ,
89 ListPromptsResult ,
@@ -78,8 +79,7 @@ def greet(name: str) -> str:
7879async def test_get_unknown_prompt_is_error (connect : Connect ) -> None :
7980 """Getting a prompt name that was never registered fails with a JSON-RPC error.
8081
81- The spec reserves -32602 for this case; the SDK reports code 0 (see the divergence note on
82- the requirement).
82+ The spec recommends `INVALID_PARAMS` for unknown prompt names.
8383 """
8484 mcp = MCPServer ("prompter" )
8585
@@ -92,16 +92,15 @@ def greet(name: str) -> str:
9292 with pytest .raises (MCPError ) as exc_info :
9393 await client .get_prompt ("nope" )
9494
95- assert exc_info .value .error == snapshot (ErrorData (code = 0 , message = "Unknown prompt: nope" ))
95+ assert exc_info .value .code == INVALID_PARAMS
96+ assert exc_info .value .error == snapshot (ErrorData (code = - 32602 , message = "Unknown prompt: nope" ))
9697
9798
9899@requirement ("prompts:get:missing-required-args" )
99100async def test_get_prompt_with_a_missing_required_argument_is_an_error (connect : Connect ) -> None :
100101 """Getting a prompt without one of its required arguments fails with a JSON-RPC error.
101102
102- The missing argument is detected before the prompt function is called, but the spec's -32602
103- Invalid params is reported as error code 0 with the bare exception text (see the divergence
104- note on the requirement).
103+ The spec recommends `INVALID_PARAMS`; validation rejects the call before the function runs.
105104 """
106105 mcp = MCPServer ("prompter" )
107106
@@ -114,7 +113,8 @@ def greet(name: str) -> str:
114113 with pytest .raises (MCPError ) as exc_info :
115114 await client .get_prompt ("greet" )
116115
117- assert exc_info .value .error == snapshot (ErrorData (code = 0 , message = "Missing required arguments: {'name'}" ))
116+ assert exc_info .value .code == INVALID_PARAMS
117+ assert exc_info .value .error == snapshot (ErrorData (code = - 32602 , message = "Missing required arguments: {'name'}" ))
118118
119119
120120@requirement ("mcpserver:prompt:args-validation" )
0 commit comments