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
|
|
@ -2,6 +2,7 @@ from pydantic import BaseModel
|
|||
|
||||
from mcp import Client
|
||||
from mcp.server import MCPServer
|
||||
from mcp.server.mcpserver.exceptions import ToolError
|
||||
from mcp.types import TextContent
|
||||
|
||||
mcp = MCPServer("Bookshop")
|
||||
|
|
@ -17,7 +18,7 @@ class Book(BaseModel):
|
|||
def lookup_book(title: str) -> Book:
|
||||
"""Look up a book by its exact title."""
|
||||
if title != "Dune":
|
||||
raise ValueError(f"No book titled {title!r} in the catalog.")
|
||||
raise ToolError(f"No book titled {title!r} in the catalog.")
|
||||
return Book(title="Dune", author="Frank Herbert", year=1965)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue