Skip to content

Commit f897932

Browse files
Add pragma comments for coverage on anyio 4.12.0
1 parent d64d191 commit f897932

File tree

2 files changed

+10
-22
lines changed

2 files changed

+10
-22
lines changed

src/mcp/client/streamable_http.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
from typing_extensions import deprecated
2424

2525
from mcp.shared._httpx_utils import (
26-
MCP_DEFAULT_SSE_READ_TIMEOUT,
27-
MCP_DEFAULT_TIMEOUT,
2826
McpHttpClientFactory,
2927
create_mcp_http_client,
3028
)
@@ -79,7 +77,6 @@ class RequestContext:
7977
"""Context for a request operation."""
8078

8179
client: httpx.AsyncClient
82-
headers: dict[str, str]
8380
session_id: str | None
8481
session_message: SessionMessage
8582
metadata: ClientMessageMetadata | None
@@ -645,16 +642,7 @@ async def streamable_http_client(
645642
# Create default client with recommended MCP timeouts
646643
client = create_mcp_http_client()
647644

648-
# Extract configuration from the client to pass to transport
649-
headers_dict = dict(client.headers) if client.headers else None
650-
timeout = client.timeout.connect if (client.timeout and client.timeout.connect is not None) else MCP_DEFAULT_TIMEOUT
651-
sse_read_timeout = (
652-
client.timeout.read if (client.timeout and client.timeout.read is not None) else MCP_DEFAULT_SSE_READ_TIMEOUT
653-
)
654-
auth = client.auth
655-
656-
# Create transport with extracted configuration
657-
transport = StreamableHTTPTransport(url, headers_dict, timeout, sse_read_timeout, auth)
645+
transport = StreamableHTTPTransport(url)
658646

659647
async with anyio.create_task_group() as tg:
660648
try:

tests/shared/test_streamable_http.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,7 @@ async def test_streamable_http_client_session_termination(basic_server: None, ba
11721172
write_stream,
11731173
_,
11741174
):
1175-
async with ClientSession(read_stream, write_stream) as session:
1175+
async with ClientSession(read_stream, write_stream) as session: # pragma: no branch
11761176
# Attempt to make a request after termination
11771177
with pytest.raises( # pragma: no branch
11781178
McpError,
@@ -1239,7 +1239,7 @@ async def mock_delete(self: httpx.AsyncClient, *args: Any, **kwargs: Any) -> htt
12391239
write_stream,
12401240
_,
12411241
):
1242-
async with ClientSession(read_stream, write_stream) as session:
1242+
async with ClientSession(read_stream, write_stream) as session: # pragma: no branch
12431243
# Attempt to make a request after termination
12441244
with pytest.raises( # pragma: no branch
12451245
McpError,
@@ -1368,8 +1368,8 @@ async def run_tool():
13681368
# We should have received the remaining notifications
13691369
assert len(captured_notifications) == 1
13701370

1371-
assert isinstance(captured_notifications[0].root, types.LoggingMessageNotification)
1372-
assert captured_notifications[0].root.params.data == "Second notification after lock"
1371+
assert isinstance(captured_notifications[0].root, types.LoggingMessageNotification) # pragma: no cover
1372+
assert captured_notifications[0].root.params.data == "Second notification after lock" # pragma: no cover
13731373

13741374

13751375
@pytest.mark.anyio
@@ -1552,7 +1552,7 @@ async def test_streamablehttp_request_context_propagation(context_aware_server:
15521552
write_stream,
15531553
_,
15541554
):
1555-
async with ClientSession(read_stream, write_stream) as session:
1555+
async with ClientSession(read_stream, write_stream) as session: # pragma: no branch
15561556
result = await session.initialize()
15571557
assert isinstance(result, InitializeResult)
15581558
assert result.serverInfo.name == "ContextAwareServer"
@@ -1590,7 +1590,7 @@ async def test_streamablehttp_request_context_isolation(context_aware_server: No
15901590
write_stream,
15911591
_,
15921592
):
1593-
async with ClientSession(read_stream, write_stream) as session:
1593+
async with ClientSession(read_stream, write_stream) as session: # pragma: no branch
15941594
await session.initialize()
15951595

15961596
# Call the tool that echoes context
@@ -2305,7 +2305,7 @@ async def test_streamable_http_client_mcp_headers_override_defaults(
23052305
write_stream,
23062306
_,
23072307
):
2308-
async with ClientSession(read_stream, write_stream) as session:
2308+
async with ClientSession(read_stream, write_stream) as session: # pragma: no branch
23092309
await session.initialize()
23102310

23112311
# Use echo_headers tool to see what headers the server actually received
@@ -2340,7 +2340,7 @@ async def test_streamable_http_client_preserves_custom_with_mcp_headers(
23402340
write_stream,
23412341
_,
23422342
):
2343-
async with ClientSession(read_stream, write_stream) as session:
2343+
async with ClientSession(read_stream, write_stream) as session: # pragma: no branch
23442344
await session.initialize()
23452345

23462346
# Use echo_headers tool to verify both custom and MCP headers are present
@@ -2390,7 +2390,7 @@ async def test_streamablehttp_client_deprecation_warning(basic_server: None, bas
23902390
write_stream,
23912391
_,
23922392
):
2393-
async with ClientSession(read_stream, write_stream) as session:
2393+
async with ClientSession(read_stream, write_stream) as session: # pragma: no branch
23942394
await session.initialize()
23952395
tools = await session.list_tools()
23962396
assert len(tools.tools) > 0

0 commit comments

Comments
 (0)