@@ -43,12 +43,8 @@ async def needs_sampling() -> str:
4343
4444
4545@pytest .mark .anyio
46- async def test_non_mcperror_exception_raised_from_a_tool_is_wrapped_as_an_is_error_result ():
47- """Unexpected tool exceptions become sanitized ``is_error`` results.
48-
49- The original exception is logged server-side rather than returned to the client.
50- Pins the other arm of the same branch.
51- """
46+ async def test_non_mcperror_exception_raised_from_a_tool_is_wrapped_as_an_is_error_result () -> None :
47+ """SDK-defined: unexpected tool exceptions become sanitized ``is_error`` results."""
5248 mcp = MCPServer (name = "srv" )
5349
5450 @mcp .tool ()
@@ -63,7 +59,8 @@ async def boom() -> str:
6359
6460
6561@pytest .mark .anyio
66- async def test_unexpected_tool_error_is_sanitized_and_logged (caplog : pytest .LogCaptureFixture ):
62+ async def test_unexpected_tool_error_is_sanitized_and_logged (caplog : pytest .LogCaptureFixture ) -> None :
63+ """SDK-defined: ``Tool.run`` logs exception details but exposes a stable message."""
6764 secret = "database password"
6865
6966 def boom () -> str :
@@ -81,11 +78,15 @@ def boom() -> str:
8178
8279
8380@pytest .mark .anyio
84- async def test_tool_error_is_re_raised_without_wrapping ():
81+ async def test_tool_error_is_re_raised_without_wrapping () -> None :
82+ """SDK-defined: an explicit ``ToolError`` remains actionable and is not wrapped."""
83+
8584 def fail () -> str :
8685 raise ToolError ("the requested record is unavailable" )
8786
8887 tool = Tool .from_function (fail )
8988
90- with pytest .raises (ToolError , match = "^the requested record is unavailable$" ) :
89+ with pytest .raises (ToolError ) as exc_info :
9190 await tool .run ({}, Context ())
91+
92+ assert str (exc_info .value ) == "the requested record is unavailable"
0 commit comments