@@ -265,7 +265,8 @@ async def test_tool_exception_handling(self):
265265 assert len (result .content ) == 1
266266 content = result .content [0 ]
267267 assert isinstance (content , TextContent )
268- assert "Test error" in content .text
268+ assert content .text == "Error executing tool error_tool_fn: unexpected internal error"
269+ assert "Test error" not in content .text
269270 assert result .is_error is True
270271
271272 async def test_tool_error_handling (self ):
@@ -276,19 +277,21 @@ async def test_tool_error_handling(self):
276277 assert len (result .content ) == 1
277278 content = result .content [0 ]
278279 assert isinstance (content , TextContent )
279- assert "Test error" in content .text
280+ assert content .text == "Error executing tool error_tool_fn: unexpected internal error"
281+ assert "Test error" not in content .text
280282 assert result .is_error is True
281283
282284 async def test_tool_error_details (self ):
283- """Test that exception details are properly formatted in the response"""
285+ """Test that unexpected exception details are hidden in the response. """
284286 mcp = MCPServer ()
285287 mcp .add_tool (error_tool_fn )
286288 async with Client (mcp ) as client :
287289 result = await client .call_tool ("error_tool_fn" , {})
288290 content = result .content [0 ]
289291 assert isinstance (content , TextContent )
290292 assert isinstance (content .text , str )
291- assert "Test error" in content .text
293+ assert content .text == "Error executing tool error_tool_fn: unexpected internal error"
294+ assert "Test error" not in content .text
292295 assert result .is_error is True
293296
294297 async def test_tool_return_value_conversion (self ):
0 commit comments