Skip to content

Commit e4b7f8d

Browse files
committed
add headers
1 parent 178571b commit e4b7f8d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/mcp/client/streamable.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
from contextlib import asynccontextmanager
3+
from typing import Any
34

45
import anyio
56
import httpx
@@ -21,6 +22,7 @@
2122
@asynccontextmanager
2223
async def streamable_client(
2324
url: str,
25+
headers: dict[str, Any] | None = None,
2426
timeout: float = 5,
2527
):
2628
"""
@@ -45,7 +47,7 @@ async def handle_response(text: str) -> None:
4547
for item in items:
4648
await read_stream_writer.send(item)
4749

48-
headers: tuple[tuple[str, str], ...] = ()
50+
session_headers = headers.copy() if headers else {}
4951

5052
async with anyio.create_task_group() as tg:
5153
try:
@@ -92,7 +94,7 @@ async def post_writer():
9294
headers=(
9395
("accept", "application/json"),
9496
("accept", "text/event-stream"),
95-
*headers,
97+
*session_headers.items(),
9698
),
9799
)
98100
content_type = response.headers.get("content-type")
@@ -105,7 +107,7 @@ async def post_writer():
105107
response.raise_for_status()
106108
match response.headers.get("mcp-session-id"):
107109
case str() as session_id:
108-
headers = (("mcp-session-id", session_id),)
110+
session_headers["mcp-session-id"] = session_id
109111
case _:
110112
pass
111113

0 commit comments

Comments
 (0)