|
5 | 5 |
|
6 | 6 | import httpx |
7 | 7 | import pytest |
| 8 | +from anyio import ClosedResourceError |
8 | 9 | from mcp import ClientSession, Tool as MCPTool |
9 | 10 | from mcp.types import CallToolResult, GetPromptResult, ListPromptsResult, ListToolsResult |
10 | 11 |
|
@@ -218,6 +219,15 @@ async def call_tool(self, tool_name, arguments, meta=None): |
218 | 219 | raise httpx.TimeoutException(self.message) |
219 | 220 |
|
220 | 221 |
|
| 222 | +class ClosedResourceSession: |
| 223 | + def __init__(self): |
| 224 | + self.call_tool_attempts = 0 |
| 225 | + |
| 226 | + async def call_tool(self, tool_name, arguments, meta=None): |
| 227 | + self.call_tool_attempts += 1 |
| 228 | + raise ClosedResourceError() |
| 229 | + |
| 230 | + |
221 | 231 | class IsolatedRetrySession: |
222 | 232 | def __init__(self): |
223 | 233 | self.call_tool_attempts = 0 |
@@ -304,6 +314,18 @@ async def test_streamable_http_retries_5xx_on_isolated_session(): |
304 | 314 | assert isolated_session.call_tool_attempts == 1 |
305 | 315 |
|
306 | 316 |
|
| 317 | +@pytest.mark.asyncio |
| 318 | +async def test_streamable_http_retries_closed_resource_on_isolated_session(): |
| 319 | + isolated_session = IsolatedRetrySession() |
| 320 | + server = DummyStreamableHttpServer(ClosedResourceSession(), isolated_session) |
| 321 | + server.max_retry_attempts = 1 |
| 322 | + |
| 323 | + result = await server.call_tool("tool", None) |
| 324 | + |
| 325 | + assert isinstance(result, CallToolResult) |
| 326 | + assert isolated_session.call_tool_attempts == 1 |
| 327 | + |
| 328 | + |
307 | 329 | @pytest.mark.asyncio |
308 | 330 | async def test_streamable_http_does_not_retry_4xx_on_isolated_session(): |
309 | 331 | isolated_session = IsolatedRetrySession() |
|
0 commit comments