Skip to content

Commit 08f5d13

Browse files
committed
test(streamable-http): fix coverage and typing on priming-race test
Mark the test helper's defensive raise no-cover, matching the module helper's convention, and give the request dicts concrete types so the dictionary unpacks resolve under pyright. Import the protocol version header from its defining module.
1 parent cf0fc1b commit 08f5d13

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

tests/shared/test_streamable_http.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from collections.abc import AsyncIterator
1212
from contextlib import asynccontextmanager
1313
from dataclasses import dataclass, field
14-
from typing import Any
14+
from typing import Any, cast
1515
from unittest.mock import MagicMock
1616
from urllib.parse import urlparse
1717

@@ -49,7 +49,6 @@
4949
from mcp.server import Server, ServerRequestContext
5050
from mcp.server.streamable_http import (
5151
GET_STREAM_KEY,
52-
MCP_PROTOCOL_VERSION_HEADER,
5352
MCP_SESSION_ID_HEADER,
5453
SESSION_ID_PATTERN,
5554
EventCallback,
@@ -63,6 +62,7 @@
6362
from mcp.server.transport_security import TransportSecuritySettings
6463
from mcp.shared._compat import resync_tracer
6564
from mcp.shared._context_streams import create_context_streams
65+
from mcp.shared.inbound import MCP_PROTOCOL_VERSION_HEADER
6666
from mcp.shared.message import ClientMessageMetadata, ServerMessageMetadata, SessionMessage
6767
from mcp.shared.session import RequestResponder
6868
from tests.interaction.transports import StreamingASGITransport
@@ -841,17 +841,18 @@ def first_message_sse_data(response: httpx.Response) -> dict[str, Any]:
841841
for line in response.text.splitlines():
842842
if line.startswith("data: ") and line.removeprefix("data: ").strip():
843843
return json.loads(line.removeprefix("data: "))
844-
raise ValueError("No message data event in SSE response")
844+
raise ValueError("No message data event in SSE response") # pragma: no cover
845845

846846
store = GatedEventStore()
847847
async with running_app(event_store=store) as app:
848848
async with make_client(app) as client:
849849
# Priming events are only minted for protocol >= 2025-11-25, so
850850
# negotiate the latest version rather than INIT_REQUEST's pinned one.
851-
init_request = {
852-
**INIT_REQUEST,
853-
"params": {**INIT_REQUEST["params"], "protocolVersion": types.LATEST_PROTOCOL_VERSION},
851+
init_params: dict[str, Any] = {
852+
**cast(dict[str, Any], INIT_REQUEST["params"]),
853+
"protocolVersion": types.LATEST_PROTOCOL_VERSION,
854854
}
855+
init_request: dict[str, Any] = {**INIT_REQUEST, "params": init_params}
855856
response = await client.post(
856857
"/mcp",
857858
headers={
@@ -867,7 +868,7 @@ def first_message_sse_data(response: httpx.Response) -> dict[str, Any]:
867868
MCP_SESSION_ID_HEADER: response.headers[MCP_SESSION_ID_HEADER],
868869
MCP_PROTOCOL_VERSION_HEADER: first_message_sse_data(response)["result"]["protocolVersion"],
869870
}
870-
call = {
871+
call: dict[str, Any] = {
871872
"jsonrpc": "2.0",
872873
"id": "gated-1",
873874
"method": "tools/call",

0 commit comments

Comments
 (0)