2222from fastmcp .tools .tool import ToolResult
2323from mcp import McpError
2424from mcp .types import ErrorData
25- from mcp_proxy_for_aws .middleware .error_handling import ConnectionErrorMiddleware
25+ from mcp_proxy_for_aws .middleware .error_handling import ConnectionErrorMiddleware , _FailedToolResult
2626from typing import Optional
2727from unittest .mock import AsyncMock , Mock
2828
@@ -67,6 +67,7 @@ async def test_passes_through_on_success(self):
6767 result = await middleware .on_call_tool (context , call_next )
6868
6969 assert result is expected
70+ assert not isinstance (result , _FailedToolResult )
7071 call_next .assert_awaited_once_with (context )
7172
7273 @pytest .mark .asyncio
@@ -80,6 +81,8 @@ async def test_catches_exception_returns_error_result(self):
8081
8182 result = await middleware .on_call_tool (context , call_next )
8283
84+ assert isinstance (result , _FailedToolResult )
85+ assert result .to_mcp_result ().isError is True
8386 assert len (result .content ) == 1
8487 text = _get_text (result )
8588 assert 'Connection closed' in text
@@ -97,6 +100,8 @@ async def hang_forever(context: MiddlewareContext[mt.CallToolRequestParams]) ->
97100
98101 result = await middleware .on_call_tool (context , hang_forever )
99102
103+ assert isinstance (result , _FailedToolResult )
104+ assert result .to_mcp_result ().isError is True
100105 assert len (result .content ) == 1
101106 text = _get_text (result )
102107 assert 'slow_tool' in text
@@ -114,6 +119,7 @@ async def test_credential_error_suggests_profile(self):
114119
115120 result = await middleware .on_call_tool (context , call_next )
116121
122+ assert result .to_mcp_result ().isError is True
117123 text = _get_text (result )
118124 assert 'expired or invalid AWS credentials' in text
119125 assert '--profile' in text
@@ -127,6 +133,7 @@ async def test_non_credential_error_no_suggestion(self):
127133
128134 result = await middleware .on_call_tool (context , call_next )
129135
136+ assert result .to_mcp_result ().isError is True
130137 text = _get_text (result )
131138 assert '--profile' not in text
132139
0 commit comments