@@ -45,6 +45,7 @@ def sse_client() -> MCPSSEClient:
4545 """Create an SSE client for testing."""
4646 return MCPSSEClient (
4747 url = "http://localhost:8000" ,
48+ headers = {"Authorization" : "Bearer token" },
4849 tool_call_timeout = timedelta (seconds = 45 ),
4950 )
5051
@@ -253,11 +254,24 @@ def test_sse_client_properties(sse_client: MCPSSEClient):
253254 """MCPSSEClient properties return correct values."""
254255 assert sse_client .transport == "sse"
255256 assert sse_client .url == "http://localhost:8000"
257+ assert sse_client .headers == {"Authorization" : "Bearer token" }
256258 assert sse_client .tool_call_timeout == timedelta (seconds = 45 )
257259
258260 config = sse_client .server_config
259261 assert config ["transport" ] == "sse"
260262 assert config ["url" ] == "http://localhost:8000"
263+ assert config ["headers" ] == {"Authorization" : "Bearer token" }
264+
265+
266+ def test_sse_client_preserves_positional_timeout ():
267+ """The existing second positional argument remains the tool-call timeout."""
268+ client = MCPSSEClient (
269+ "http://localhost:8000" ,
270+ timedelta (seconds = 7 ),
271+ )
272+
273+ assert client .tool_call_timeout == timedelta (seconds = 7 )
274+ assert client .headers == {}
261275
262276
263277def test_streamable_http_client_properties (streamable_http_client : MCPStreamableHTTPClient ):
@@ -328,6 +342,35 @@ async def test_connect_context_manager(
328342 mock_client_session .initialize .assert_awaited_once ()
329343
330344
345+ @pytest .mark .asyncio
346+ async def test_sse_headers_passed_to_transport (
347+ mock_mcp_transport : tuple [MagicMock , MagicMock ],
348+ mock_client_session : AsyncMock ,
349+ ):
350+ """SSE clients forward custom headers to the transport."""
351+ client = create_mcp_client (
352+ "sse" ,
353+ url = "https://example.test/sse" ,
354+ headers = {"Authorization" : "Bearer token" },
355+ )
356+ mock_read , mock_write = mock_mcp_transport
357+
358+ with (
359+ patch ("nooa.mcp.client.sse_client" ) as mock_sse ,
360+ patch ("nooa.mcp.client.ClientSession" ) as mock_session_class ,
361+ ):
362+ mock_sse .return_value .__aenter__ .return_value = (mock_read , mock_write )
363+ mock_session_class .return_value .__aenter__ .return_value = mock_client_session
364+
365+ async with client .connect_to_server ():
366+ pass
367+
368+ mock_sse .assert_called_once_with (
369+ url = "https://example.test/sse" ,
370+ headers = {"Authorization" : "Bearer token" },
371+ )
372+
373+
331374@pytest .mark .asyncio
332375async def test_streamable_http_connect_context_manager (
333376 streamable_http_client : MCPStreamableHTTPClient ,
0 commit comments