Log MCPServer handler exceptions by kind and keep crash details off the wire (#3314)
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
This commit is contained in:
parent
f1c40b062f
commit
56af44727b
1 changed files with 1427 additions and 310 deletions
|
|
@ -1,5 +1,5 @@
|
|||
from mcp.server import MCPServer
|
||||
from mcp.server.mcpserver.exceptions import ResourceNotFoundError
|
||||
from mcp.server.mcpserver.exceptions import ResourceNotFoundError, ToolError
|
||||
|
||||
mcp = MCPServer("Weather")
|
||||
|
||||
|
|
@ -10,7 +10,7 @@ FORECASTS = {"London": "Rain.", "Cairo": "Sun."}
|
|||
def forecast(city: str) -> str:
|
||||
"""Today's forecast for one city."""
|
||||
if city not in FORECASTS:
|
||||
raise ValueError(f"No forecast for {city!r}.")
|
||||
raise ToolError(f"No forecast for {city!r}.")
|
||||
return FORECASTS[city]
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue