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:
Max 2026-08-24 15:51:18 +01:00 • committed by GitHub
commit 56af44727b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -139,6 +139,19 @@ async def test_safe_join_serves_a_file_inside_the_base_directory(
assert content.text == "# Printer setup"
async def test_a_missing_manual_is_resource_not_found(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
"""tutorial002 and the closing tip: a path with no file behind it is `-32602` with the handler's message."""
monkeypatch.setattr(tutorial002, "DOCS_ROOT", tmp_path)
async with Client(tutorial002.mcp) as client:
with pytest.raises(MCPError) as exc:
await client.read_resource("manuals://printing/missing.md")
assert exc.value.error == ErrorData(
code=INVALID_PARAMS,
message="No manual at 'printing/missing.md'.",
data={"uri": "manuals://printing/missing.md"},
)
def test_safe_join_raises_when_the_resolved_path_escapes_the_base(tmp_path: Path) -> None:
"""tutorial002: a path that climbs out of `DOCS_ROOT` raises `PathEscapeError`."""
with pytest.raises(PathEscapeError):