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,6 +1,7 @@
|
|||
from pathlib import Path
|
||||
|
||||
from mcp.server import MCPServer
|
||||
from mcp.server.mcpserver.exceptions import ResourceNotFoundError
|
||||
from mcp.shared.path_security import safe_join
|
||||
|
||||
mcp = MCPServer("Bookshop")
|
||||
|
|
@ -11,4 +12,7 @@ DOCS_ROOT = Path("./manuals")
|
|||
@mcp.resource("manuals://{+path}")
|
||||
def read_manual(path: str) -> str:
|
||||
"""A staff manual page, served from a directory on disk."""
|
||||
return safe_join(DOCS_ROOT, path).read_text(encoding="utf-8")
|
||||
file = safe_join(DOCS_ROOT, path)
|
||||
if not file.is_file():
|
||||
raise ResourceNotFoundError(f"No manual at {path!r}.")
|
||||
return file.read_text(encoding="utf-8")
|
||||
|
|
|
|||
Loading…
Reference in a new issue