|
1 | 1 | import base64 |
2 | 2 | from pathlib import Path |
3 | 3 | from typing import Any |
4 | | -from unittest.mock import patch |
| 4 | +from unittest.mock import AsyncMock, MagicMock, patch |
5 | 5 |
|
6 | 6 | import pytest |
7 | 7 | from inline_snapshot import snapshot |
|
10 | 10 | from starlette.routing import Mount, Route |
11 | 11 |
|
12 | 12 | from mcp.client import Client |
| 13 | +from mcp.server.context import ServerRequestContext |
| 14 | +from mcp.server.experimental.request_context import Experimental |
13 | 15 | from mcp.server.mcpserver import Context, MCPServer |
14 | 16 | from mcp.server.mcpserver.exceptions import ToolError |
15 | 17 | from mcp.server.mcpserver.prompts.base import Message, UserMessage |
@@ -1436,3 +1438,34 @@ def test_streamable_http_no_redirect() -> None: |
1436 | 1438 |
|
1437 | 1439 | # Verify path values |
1438 | 1440 | assert streamable_routes[0].path == "/mcp", "Streamable route path should be /mcp" |
| 1441 | + |
| 1442 | + |
| 1443 | +async def test_report_progress_passes_related_request_id(): |
| 1444 | + """Test that report_progress passes the request_id as related_request_id. |
| 1445 | +
|
| 1446 | + Without related_request_id, the streamable HTTP transport cannot route |
| 1447 | + progress notifications to the correct SSE stream, causing them to be |
| 1448 | + silently dropped. See #953 and #2001. |
| 1449 | + """ |
| 1450 | + mock_session = AsyncMock() |
| 1451 | + mock_session.send_progress_notification = AsyncMock() |
| 1452 | + |
| 1453 | + request_context = ServerRequestContext( |
| 1454 | + request_id="req-abc-123", |
| 1455 | + session=mock_session, |
| 1456 | + meta={"progress_token": "tok-1"}, |
| 1457 | + lifespan_context=None, |
| 1458 | + experimental=Experimental(), |
| 1459 | + ) |
| 1460 | + |
| 1461 | + ctx = Context(request_context=request_context, mcp_server=MagicMock()) |
| 1462 | + |
| 1463 | + await ctx.report_progress(50, 100, message="halfway") |
| 1464 | + |
| 1465 | + mock_session.send_progress_notification.assert_awaited_once_with( |
| 1466 | + progress_token="tok-1", |
| 1467 | + progress=50, |
| 1468 | + total=100, |
| 1469 | + message="halfway", |
| 1470 | + related_request_id="req-abc-123", |
| 1471 | + ) |
0 commit comments