@@ -106,13 +106,11 @@ def __init__(
106
106
** self .headers ,
107
107
}
108
108
109
- async def _update_headers_with_session (
109
+ def _update_headers_with_session (
110
110
self , base_headers : dict [str , str ]
111
111
) -> dict [str , str ]:
112
- """Update headers with session ID."""
112
+ """Update headers with session ID if available ."""
113
113
headers = base_headers .copy ()
114
-
115
- # Add session ID if available
116
114
if self .session_id :
117
115
headers [MCP_SESSION_ID ] = self .session_id
118
116
return headers
@@ -189,7 +187,7 @@ async def handle_get_stream(
189
187
if not self .session_id :
190
188
return
191
189
192
- headers = await self ._update_headers_with_session (self .request_headers )
190
+ headers = self ._update_headers_with_session (self .request_headers )
193
191
194
192
async with aconnect_sse (
195
193
client ,
@@ -211,7 +209,7 @@ async def handle_get_stream(
211
209
212
210
async def _handle_resumption_request (self , ctx : RequestContext ) -> None :
213
211
"""Handle a resumption request using GET with SSE."""
214
- headers = await self ._update_headers_with_session (ctx .headers )
212
+ headers = self ._update_headers_with_session (ctx .headers )
215
213
if ctx .metadata and ctx .metadata .resumption_token :
216
214
headers [LAST_EVENT_ID ] = ctx .metadata .resumption_token
217
215
else :
@@ -246,7 +244,7 @@ async def _handle_resumption_request(self, ctx: RequestContext) -> None:
246
244
247
245
async def _handle_post_request (self , ctx : RequestContext ) -> None :
248
246
"""Handle a POST request with response processing."""
249
- headers = await self ._update_headers_with_session (ctx .headers )
247
+ headers = self ._update_headers_with_session (ctx .headers )
250
248
message = ctx .session_message .message
251
249
is_initialization = self ._is_initialization_request (message )
252
250
@@ -410,7 +408,7 @@ async def terminate_session(self, client: httpx.AsyncClient) -> None:
410
408
return
411
409
412
410
try :
413
- headers = await self ._update_headers_with_session (self .request_headers )
411
+ headers = self ._update_headers_with_session (self .request_headers )
414
412
response = await client .delete (self .url , headers = headers )
415
413
416
414
if response .status_code == 405 :
@@ -447,14 +445,6 @@ async def streamablehttp_client(
447
445
`sse_read_timeout` determines how long (in seconds) the client will wait for a new
448
446
event before disconnecting. All other HTTP operations are controlled by `timeout`.
449
447
450
- Args:
451
- url: StreamableHTTP endpoint URL
452
- headers: Optional HTTP headers
453
- timeout: HTTP request timeout
454
- sse_read_timeout: SSE read timeout
455
- terminate_on_close: Whether to terminate session on close
456
- auth: Optional HTTPX authentication handler
457
-
458
448
Yields:
459
449
Tuple containing:
460
450
- read_stream: Stream for reading messages from the server
0 commit comments