25
25
26
26
import mcp .types as types
27
27
from mcp .client .session import ClientSession
28
- from mcp .client .streamable_http import streamablehttp_client
28
+ from mcp .client .streamable_http import HEADER_CAPTURE , streamablehttp_client
29
29
from mcp .server import Server
30
30
from mcp .server .streamable_http import (
31
31
MCP_SESSION_ID_HEADER ,
@@ -262,7 +262,7 @@ async def header_capture_wrapper(scope, receive, send):
262
262
263
263
# Return error response with headers in body
264
264
response = Response (
265
- "[TESTING_HEADER_CAPTURE]:" + json .dumps ({"headers" : headers }),
265
+ HEADER_CAPTURE + json .dumps ({"headers" : headers }),
266
266
status_code = 418 ,
267
267
)
268
268
await response (scope , receive , send )
@@ -279,7 +279,7 @@ async def header_capture_wrapper(scope, receive, send):
279
279
280
280
281
281
def _get_captured_headrs (str ) -> dict [str , str ]:
282
- return json .loads (str .split ("[TESTING_HEADER_CAPTURE]:" )[1 ])["headers" ]
282
+ return json .loads (str .split (HEADER_CAPTURE )[1 ])["headers" ]
283
283
284
284
285
285
def run_server (
@@ -356,21 +356,23 @@ def _start_basic_server(
356
356
357
357
# Wait for server to be running
358
358
max_attempts = 20
359
- for attempt in range (max_attempts ):
359
+ attempt = 0
360
+ while attempt < max_attempts :
360
361
try :
361
362
with socket .socket (socket .AF_INET , socket .SOCK_STREAM ) as s :
362
363
s .connect (("127.0.0.1" , basic_server_port ))
363
364
break
364
365
except ConnectionRefusedError :
365
366
time .sleep (0.1 )
367
+ attempt += 1
366
368
else :
367
369
raise RuntimeError (f"Server failed to start after { max_attempts } attempts" )
368
370
369
- try :
370
- yield
371
- finally :
372
- proc .kill ()
373
- proc .join (timeout = 2 )
371
+ yield
372
+
373
+ # Clean up
374
+ proc .kill ()
375
+ proc .join (timeout = 2 )
374
376
375
377
376
378
@pytest .fixture
0 commit comments