|
14 | 14 | import anyio |
15 | 15 | import httpx2 |
16 | 16 | import pytest |
17 | | -from httpx_sse import aconnect_sse |
18 | 17 | from inline_snapshot import snapshot |
19 | 18 | from mcp_types import ( |
20 | 19 | CLIENT_CAPABILITIES_META_KEY, |
@@ -684,9 +683,9 @@ async def call_tool(ctx: ServerRequestContext, params: CallToolRequestParams) -> |
684 | 683 |
|
685 | 684 | server = Server("sentinel-name", on_list_tools=list_tools, on_call_tool=call_tool) |
686 | 685 |
|
687 | | - requests: list[httpx.Request] = [] |
| 686 | + requests: list[httpx2.Request] = [] |
688 | 687 |
|
689 | | - async def on_request(request: httpx.Request) -> None: |
| 688 | + async def on_request(request: httpx2.Request) -> None: |
690 | 689 | requests.append(request) |
691 | 690 |
|
692 | 691 | discover = DiscoverResult( |
@@ -717,9 +716,9 @@ async def test_sentinel_lookalike_argument_value_is_base64_wrapped_in_its_param_ |
717 | 716 |
|
718 | 717 | Spec-mandated by the sentinel-collision rule, the only encoding trigger: the value is otherwise header-safe ASCII. |
719 | 718 | """ |
720 | | - requests: list[httpx.Request] = [] |
| 719 | + requests: list[httpx2.Request] = [] |
721 | 720 |
|
722 | | - async def on_request(request: httpx.Request) -> None: |
| 721 | + async def on_request(request: httpx2.Request) -> None: |
723 | 722 | requests.append(request) |
724 | 723 |
|
725 | 724 | discover = DiscoverResult( |
@@ -757,9 +756,9 @@ async def test_null_and_absent_annotated_arguments_emit_no_param_headers_and_the |
757 | 756 | argument against its `Mcp-Param-*` header and would reject an orphan header for the null or |
758 | 757 | absent argument (a header matching no annotation is ignored). |
759 | 758 | """ |
760 | | - requests: list[httpx.Request] = [] |
| 759 | + requests: list[httpx2.Request] = [] |
761 | 760 |
|
762 | | - async def on_request(request: httpx.Request) -> None: |
| 761 | + async def on_request(request: httpx2.Request) -> None: |
763 | 762 | requests.append(request) |
764 | 763 |
|
765 | 764 | discover = DiscoverResult( |
@@ -971,11 +970,11 @@ async def call_tool(ctx: ServerRequestContext, params: CallToolRequestParams) -> |
971 | 970 | with anyio.fail_after(5): |
972 | 971 | async with ( |
973 | 972 | mounted_app(Server("modern", on_call_tool=call_tool)) as (http, _), |
974 | | - aconnect_sse( |
975 | | - http, "POST", "/mcp", json=body, headers=_modern_headers(method="tools/call", name="noisy") |
| 973 | + http.sse( |
| 974 | + "/mcp", method="POST", json=body, headers=_modern_headers(method="tools/call", name="noisy") |
976 | 975 | ) as source, |
977 | 976 | ): |
978 | | - events = [event async for event in source.aiter_sse()] |
| 977 | + events = [event async for event in source] |
979 | 978 |
|
980 | 979 | assert source.response.status_code == 200 |
981 | 980 | assert source.response.headers["content-type"].split(";", 1)[0] == "text/event-stream" |
@@ -1023,25 +1022,25 @@ async def call_tool(ctx: ServerRequestContext, params: CallToolRequestParams) -> |
1023 | 1022 |
|
1024 | 1023 | server = Server("scoped", on_call_tool=call_tool) |
1025 | 1024 |
|
1026 | | - emit_responses: list[httpx.Response] = [] |
| 1025 | + emit_responses: list[httpx2.Response] = [] |
1027 | 1026 | emit_frames: list[JSONRPCMessage] = [] |
1028 | | - quiet_responses: list[httpx.Response] = [] |
| 1027 | + quiet_responses: list[httpx2.Response] = [] |
1029 | 1028 |
|
1030 | | - async def post_emit(http: httpx.AsyncClient) -> None: |
| 1029 | + async def post_emit(http: httpx2.AsyncClient) -> None: |
1031 | 1030 | body = { |
1032 | 1031 | "jsonrpc": "2.0", |
1033 | 1032 | "id": 1, |
1034 | 1033 | "method": "tools/call", |
1035 | 1034 | "params": {"name": "emit", "arguments": {}, "_meta": _meta_envelope()}, |
1036 | 1035 | } |
1037 | | - async with aconnect_sse( |
1038 | | - http, "POST", "/mcp", json=body, headers=_modern_headers(method="tools/call", name="emit") |
| 1036 | + async with http.sse( |
| 1037 | + "/mcp", method="POST", json=body, headers=_modern_headers(method="tools/call", name="emit") |
1039 | 1038 | ) as source: |
1040 | | - events = [event async for event in source.aiter_sse()] |
| 1039 | + events = [event async for event in source] |
1041 | 1040 | emit_responses.append(source.response) |
1042 | 1041 | emit_frames.extend(parse_sse_messages(events)) |
1043 | 1042 |
|
1044 | | - async def post_quiet(http: httpx.AsyncClient) -> None: |
| 1043 | + async def post_quiet(http: httpx2.AsyncClient) -> None: |
1045 | 1044 | body = { |
1046 | 1045 | "jsonrpc": "2.0", |
1047 | 1046 | "id": 2, |
@@ -1111,12 +1110,12 @@ async def call_tool(ctx: ServerRequestContext, params: CallToolRequestParams) -> |
1111 | 1110 | with anyio.fail_after(5): |
1112 | 1111 | async with ( |
1113 | 1112 | mounted_app(Server("modern", on_call_tool=call_tool)) as (http, _), |
1114 | | - aconnect_sse( |
1115 | | - http, "POST", "/mcp", json=body, headers=_modern_headers(method="tools/call", name="noisy") |
| 1113 | + http.sse( |
| 1114 | + "/mcp", method="POST", json=body, headers=_modern_headers(method="tools/call", name="noisy") |
1116 | 1115 | ) as source, |
1117 | 1116 | ): |
1118 | 1117 | # Drained only so teardown is clean. |
1119 | | - async for _ in source.aiter_sse(): |
| 1118 | + async for _ in source: |
1120 | 1119 | pass |
1121 | 1120 |
|
1122 | 1121 | assert source.response.headers["x-accel-buffering"] == "no" |
@@ -1227,7 +1226,7 @@ async def test_modern_encoded_mcp_name_matching_the_body_after_decode_is_served( |
1227 | 1226 | """A sentinel-encoded ``Mcp-Name`` whose decoded value matches the body is served, not rejected. |
1228 | 1227 |
|
1229 | 1228 | Spec-mandated: the server decodes the header before validation -- a plain string comparison |
1230 | | - would have answered 400 HeaderMismatch. The typed client sends ASCII bare, hence raw httpx. |
| 1229 | + would have answered 400 HeaderMismatch. The typed client sends ASCII bare, hence raw httpx2. |
1231 | 1230 | """ |
1232 | 1231 | body = { |
1233 | 1232 | "jsonrpc": "2.0", |
@@ -1262,9 +1261,9 @@ async def get_prompt(ctx: ServerRequestContext, params: GetPromptRequestParams) |
1262 | 1261 |
|
1263 | 1262 | server = Server("sentinel-prompt", on_get_prompt=get_prompt) |
1264 | 1263 |
|
1265 | | - requests: list[httpx.Request] = [] |
| 1264 | + requests: list[httpx2.Request] = [] |
1266 | 1265 |
|
1267 | | - async def on_request(request: httpx.Request) -> None: |
| 1266 | + async def on_request(request: httpx2.Request) -> None: |
1268 | 1267 | requests.append(request) |
1269 | 1268 |
|
1270 | 1269 | discover = DiscoverResult( |
@@ -1324,11 +1323,11 @@ async def call_tool(ctx: ServerRequestContext, params: CallToolRequestParams) -> |
1324 | 1323 | } |
1325 | 1324 | with anyio.fail_after(5): |
1326 | 1325 | async with mounted_app(Server("modern", on_call_tool=call_tool)) as (http, _): |
1327 | | - async with aconnect_sse( |
1328 | | - http, "POST", "/mcp", json=body, headers=_modern_headers(method="tools/call", name="park") |
| 1326 | + async with http.sse( |
| 1327 | + "/mcp", method="POST", json=body, headers=_modern_headers(method="tools/call", name="park") |
1329 | 1328 | ) as source: |
1330 | 1329 | # Advanced once only: a full `async for` would wait for the close that is ours to perform. |
1331 | | - events = source.aiter_sse() |
| 1330 | + events = aiter(source) |
1332 | 1331 | first = await anext(events) |
1333 | 1332 | # Awaited while the app is still mounted: after mounted_app exits, the bridge's |
1334 | 1333 | # teardown cancellation would make this pass vacuously. |
@@ -1458,7 +1457,7 @@ async def test_modern_mcp_param_header_disagreeing_with_body_argument_is_rejecte |
1458 | 1457 |
|
1459 | 1458 | Spec-mandated: the server resolves the ``x-mcp-header`` annotation from the tool's advertised |
1460 | 1459 | ``inputSchema`` via its own tools/list handler and rejects the decoded-header/body disagreement |
1461 | | - before dispatch. Raw httpx because the HTTP status is a wire-only observable and the typed |
| 1460 | + before dispatch. Raw httpx2 because the HTTP status is a wire-only observable and the typed |
1462 | 1461 | client cannot emit a mismatching header by construction. |
1463 | 1462 | """ |
1464 | 1463 |
|
|
0 commit comments