Skip to content

Commit 037098a

Browse files
committed
test: move related_request_id test to test_server.py
Move test_report_progress_passes_related_request_id from test_176_progress_token.py (which tests falsy progress tokens) to test_server.py where Context behavior tests belong.
1 parent e4f97e4 commit 037098a

File tree

2 files changed

+34
-28
lines changed

2 files changed

+34
-28
lines changed

tests/issues/test_176_progress_token.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -44,30 +44,3 @@ async def test_progress_token_zero_first_call():
4444
mock_session.send_progress_notification.assert_any_call(
4545
progress_token=0, progress=10.0, total=10.0, message=None, related_request_id="test-request"
4646
)
47-
48-
49-
async def test_report_progress_passes_related_request_id():
50-
"""Test that report_progress passes the request_id as related_request_id."""
51-
52-
mock_session = AsyncMock()
53-
mock_session.send_progress_notification = AsyncMock()
54-
55-
request_context = ServerRequestContext(
56-
request_id="req-abc-123",
57-
session=mock_session,
58-
meta={"progress_token": "tok-1"},
59-
lifespan_context=None,
60-
experimental=Experimental(),
61-
)
62-
63-
ctx = Context(request_context=request_context, mcp_server=MagicMock())
64-
65-
await ctx.report_progress(50, 100, message="halfway")
66-
67-
mock_session.send_progress_notification.assert_awaited_once_with(
68-
progress_token="tok-1",
69-
progress=50,
70-
total=100,
71-
message="halfway",
72-
related_request_id="req-abc-123",
73-
)

tests/server/mcpserver/test_server.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import base64
22
from pathlib import Path
33
from typing import Any
4-
from unittest.mock import patch
4+
from unittest.mock import AsyncMock, MagicMock, patch
55

66
import pytest
77
from inline_snapshot import snapshot
@@ -10,6 +10,8 @@
1010
from starlette.routing import Mount, Route
1111

1212
from mcp.client import Client
13+
from mcp.server.context import ServerRequestContext
14+
from mcp.server.experimental.request_context import Experimental
1315
from mcp.server.mcpserver import Context, MCPServer
1416
from mcp.server.mcpserver.exceptions import ToolError
1517
from mcp.server.mcpserver.prompts.base import Message, UserMessage
@@ -1415,3 +1417,34 @@ def test_streamable_http_no_redirect() -> None:
14151417

14161418
# Verify path values
14171419
assert streamable_routes[0].path == "/mcp", "Streamable route path should be /mcp"
1420+
1421+
1422+
async def test_report_progress_passes_related_request_id():
1423+
"""Test that report_progress passes the request_id as related_request_id.
1424+
1425+
Without related_request_id, the streamable HTTP transport cannot route
1426+
progress notifications to the correct SSE stream, causing them to be
1427+
silently dropped. See #953 and #2001.
1428+
"""
1429+
mock_session = AsyncMock()
1430+
mock_session.send_progress_notification = AsyncMock()
1431+
1432+
request_context = ServerRequestContext(
1433+
request_id="req-abc-123",
1434+
session=mock_session,
1435+
meta={"progress_token": "tok-1"},
1436+
lifespan_context=None,
1437+
experimental=Experimental(),
1438+
)
1439+
1440+
ctx = Context(request_context=request_context, mcp_server=MagicMock())
1441+
1442+
await ctx.report_progress(50, 100, message="halfway")
1443+
1444+
mock_session.send_progress_notification.assert_awaited_once_with(
1445+
progress_token="tok-1",
1446+
progress=50,
1447+
total=100,
1448+
message="halfway",
1449+
related_request_id="req-abc-123",
1450+
)

0 commit comments

Comments
 (0)