|
4 | 4 |
|
5 | 5 | from typing import TYPE_CHECKING, Any |
6 | 6 |
|
7 | | -from mcp_types import InputRequiredResult |
| 7 | +from mcp_types import INVALID_PARAMS, InputRequiredResult |
8 | 8 |
|
9 | 9 | from mcp.server.mcpserver.prompts.base import Message, Prompt |
10 | 10 | from mcp.server.mcpserver.utilities.logging import get_logger |
| 11 | +from mcp.shared.exceptions import MCPError |
11 | 12 |
|
12 | 13 | if TYPE_CHECKING: |
13 | 14 | from mcp.server.context import LifespanContextT, RequestT |
@@ -59,9 +60,15 @@ async def render_prompt( |
59 | 60 | arguments: dict[str, Any] | None, |
60 | 61 | context: Context[LifespanContextT, RequestT], |
61 | 62 | ) -> list[Message] | InputRequiredResult: |
62 | | - """Render a prompt by name with arguments.""" |
| 63 | + """Render a prompt by name with arguments. |
| 64 | +
|
| 65 | + Raises: |
| 66 | + MCPError: If the prompt name is unknown or a required argument is missing, |
| 67 | + with code `INVALID_PARAMS`, or if the prompt function raises it. |
| 68 | + ValueError: If rendering fails. |
| 69 | + """ |
63 | 70 | prompt = self.get_prompt(name) |
64 | 71 | if not prompt: |
65 | | - raise ValueError(f"Unknown prompt: {name}") |
| 72 | + raise MCPError(code=INVALID_PARAMS, message=f"Unknown prompt: {name}") |
66 | 73 |
|
67 | 74 | return await prompt.render(arguments, context) |
0 commit comments