Skip to content

Commit 0af917e

Browse files
committed
Clarify prompt errors and restore message assertions
1 parent 400e343 commit 0af917e

4 files changed

Lines changed: 6 additions & 1 deletion

File tree

‎docs/servers/prompts.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ That is the entire life of a prompt: listed by name, rendered on demand, dropped
6363
```
6464

6565
There is no tool-style error result to hand back to a model, because no model is in the loop:
66-
the call raises. You can distinguish invalid arguments from internal errors by the error code.
66+
the call raises. You can distinguish missing required arguments from internal errors by the error code.
6767

6868
### Try it
6969

‎src/mcp/server/mcpserver/server.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,7 @@ async def get_prompt(
13521352
Raises:
13531353
MCPError: If the prompt name is unknown or a required argument is missing,
13541354
with code `INVALID_PARAMS`, or if the prompt function raises it.
1355+
ValueError: If rendering fails.
13551356
"""
13561357
if context is None:
13571358
context = Context(mcp_server=self, subscriptions=self._subscriptions)

‎tests/server/mcpserver/prompts/test_manager.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
from inline_snapshot import snapshot
23
from mcp_types import INVALID_PARAMS, TextContent
34

45
from mcp import MCPError
@@ -110,3 +111,4 @@ def fn(name: str) -> str: # pragma: no cover
110111
with pytest.raises(MCPError) as exc_info:
111112
await manager.render_prompt("fn", None, Context())
112113
assert exc_info.value.code == INVALID_PARAMS
114+
assert exc_info.value.message == snapshot("Missing required arguments: {'name'}")

‎tests/server/mcpserver/test_server.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,7 @@ async def test_get_unknown_prompt(self):
15681568
with pytest.raises(MCPError) as exc_info:
15691569
await client.get_prompt("unknown")
15701570
assert exc_info.value.code == INVALID_PARAMS
1571+
assert exc_info.value.message == snapshot("Unknown prompt: unknown")
15711572

15721573
async def test_get_prompt_missing_args(self):
15731574
"""Test error when required arguments are missing."""
@@ -1580,6 +1581,7 @@ def prompt_fn(name: str) -> str: ... # pragma: no branch
15801581
with pytest.raises(MCPError) as exc_info:
15811582
await client.get_prompt("prompt_fn")
15821583
assert exc_info.value.code == INVALID_PARAMS
1584+
assert exc_info.value.message == snapshot("Missing required arguments: {'name'}")
15831585

15841586

15851587
async def test_resource_decorator_rfc6570_reserved_expansion():

0 commit comments

Comments
 (0)