|
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, |
@@ -717,9 +716,9 @@ async def call_tool(ctx: ServerRequestContext, params: CallToolRequestParams) -> |
717 | 716 |
|
718 | 717 | server = Server("sentinel-name", on_list_tools=list_tools, on_call_tool=call_tool) |
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( |
@@ -750,9 +749,9 @@ async def test_sentinel_lookalike_argument_value_is_base64_wrapped_in_its_param_ |
750 | 749 |
|
751 | 750 | Spec-mandated by the sentinel-collision rule, the only encoding trigger: the value is otherwise header-safe ASCII. |
752 | 751 | """ |
753 | | - requests: list[httpx.Request] = [] |
| 752 | + requests: list[httpx2.Request] = [] |
754 | 753 |
|
755 | | - async def on_request(request: httpx.Request) -> None: |
| 754 | + async def on_request(request: httpx2.Request) -> None: |
756 | 755 | requests.append(request) |
757 | 756 |
|
758 | 757 | discover = DiscoverResult( |
@@ -790,9 +789,9 @@ async def test_null_and_absent_annotated_arguments_emit_no_param_headers_and_the |
790 | 789 | argument against its `Mcp-Param-*` header and would reject an orphan header for the null or |
791 | 790 | absent argument (a header matching no annotation is ignored). |
792 | 791 | """ |
793 | | - requests: list[httpx.Request] = [] |
| 792 | + requests: list[httpx2.Request] = [] |
794 | 793 |
|
795 | | - async def on_request(request: httpx.Request) -> None: |
| 794 | + async def on_request(request: httpx2.Request) -> None: |
796 | 795 | requests.append(request) |
797 | 796 |
|
798 | 797 | discover = DiscoverResult( |
@@ -1004,11 +1003,11 @@ async def call_tool(ctx: ServerRequestContext, params: CallToolRequestParams) -> |
1004 | 1003 | with anyio.fail_after(5): |
1005 | 1004 | async with ( |
1006 | 1005 | mounted_app(Server("modern", on_call_tool=call_tool)) as (http, _), |
1007 | | - aconnect_sse( |
1008 | | - http, "POST", "/mcp", json=body, headers=_modern_headers(method="tools/call", name="noisy") |
| 1006 | + http.sse( |
| 1007 | + "/mcp", method="POST", json=body, headers=_modern_headers(method="tools/call", name="noisy") |
1009 | 1008 | ) as source, |
1010 | 1009 | ): |
1011 | | - events = [event async for event in source.aiter_sse()] |
| 1010 | + events = [event async for event in source] |
1012 | 1011 |
|
1013 | 1012 | assert source.response.status_code == 200 |
1014 | 1013 | assert source.response.headers["content-type"].split(";", 1)[0] == "text/event-stream" |
@@ -1056,25 +1055,25 @@ async def call_tool(ctx: ServerRequestContext, params: CallToolRequestParams) -> |
1056 | 1055 |
|
1057 | 1056 | server = Server("scoped", on_call_tool=call_tool) |
1058 | 1057 |
|
1059 | | - emit_responses: list[httpx.Response] = [] |
| 1058 | + emit_responses: list[httpx2.Response] = [] |
1060 | 1059 | emit_frames: list[JSONRPCMessage] = [] |
1061 | | - quiet_responses: list[httpx.Response] = [] |
| 1060 | + quiet_responses: list[httpx2.Response] = [] |
1062 | 1061 |
|
1063 | | - async def post_emit(http: httpx.AsyncClient) -> None: |
| 1062 | + async def post_emit(http: httpx2.AsyncClient) -> None: |
1064 | 1063 | body = { |
1065 | 1064 | "jsonrpc": "2.0", |
1066 | 1065 | "id": 1, |
1067 | 1066 | "method": "tools/call", |
1068 | 1067 | "params": {"name": "emit", "arguments": {}, "_meta": _meta_envelope()}, |
1069 | 1068 | } |
1070 | | - async with aconnect_sse( |
1071 | | - http, "POST", "/mcp", json=body, headers=_modern_headers(method="tools/call", name="emit") |
| 1069 | + async with http.sse( |
| 1070 | + "/mcp", method="POST", json=body, headers=_modern_headers(method="tools/call", name="emit") |
1072 | 1071 | ) as source: |
1073 | | - events = [event async for event in source.aiter_sse()] |
| 1072 | + events = [event async for event in source] |
1074 | 1073 | emit_responses.append(source.response) |
1075 | 1074 | emit_frames.extend(parse_sse_messages(events)) |
1076 | 1075 |
|
1077 | | - async def post_quiet(http: httpx.AsyncClient) -> None: |
| 1076 | + async def post_quiet(http: httpx2.AsyncClient) -> None: |
1078 | 1077 | body = { |
1079 | 1078 | "jsonrpc": "2.0", |
1080 | 1079 | "id": 2, |
@@ -1144,12 +1143,12 @@ async def call_tool(ctx: ServerRequestContext, params: CallToolRequestParams) -> |
1144 | 1143 | with anyio.fail_after(5): |
1145 | 1144 | async with ( |
1146 | 1145 | mounted_app(Server("modern", on_call_tool=call_tool)) as (http, _), |
1147 | | - aconnect_sse( |
1148 | | - http, "POST", "/mcp", json=body, headers=_modern_headers(method="tools/call", name="noisy") |
| 1146 | + http.sse( |
| 1147 | + "/mcp", method="POST", json=body, headers=_modern_headers(method="tools/call", name="noisy") |
1149 | 1148 | ) as source, |
1150 | 1149 | ): |
1151 | 1150 | # Drained only so teardown is clean. |
1152 | | - async for _ in source.aiter_sse(): |
| 1151 | + async for _ in source: |
1153 | 1152 | pass |
1154 | 1153 |
|
1155 | 1154 | assert source.response.headers["x-accel-buffering"] == "no" |
@@ -1260,7 +1259,7 @@ async def test_modern_encoded_mcp_name_matching_the_body_after_decode_is_served( |
1260 | 1259 | """A sentinel-encoded ``Mcp-Name`` whose decoded value matches the body is served, not rejected. |
1261 | 1260 |
|
1262 | 1261 | Spec-mandated: the server decodes the header before validation -- a plain string comparison |
1263 | | - would have answered 400 HeaderMismatch. The typed client sends ASCII bare, hence raw httpx. |
| 1262 | + would have answered 400 HeaderMismatch. The typed client sends ASCII bare, hence raw httpx2. |
1264 | 1263 | """ |
1265 | 1264 | body = { |
1266 | 1265 | "jsonrpc": "2.0", |
@@ -1295,9 +1294,9 @@ async def get_prompt(ctx: ServerRequestContext, params: GetPromptRequestParams) |
1295 | 1294 |
|
1296 | 1295 | server = Server("sentinel-prompt", on_get_prompt=get_prompt) |
1297 | 1296 |
|
1298 | | - requests: list[httpx.Request] = [] |
| 1297 | + requests: list[httpx2.Request] = [] |
1299 | 1298 |
|
1300 | | - async def on_request(request: httpx.Request) -> None: |
| 1299 | + async def on_request(request: httpx2.Request) -> None: |
1301 | 1300 | requests.append(request) |
1302 | 1301 |
|
1303 | 1302 | discover = DiscoverResult( |
@@ -1357,11 +1356,11 @@ async def call_tool(ctx: ServerRequestContext, params: CallToolRequestParams) -> |
1357 | 1356 | } |
1358 | 1357 | with anyio.fail_after(5): |
1359 | 1358 | async with mounted_app(Server("modern", on_call_tool=call_tool)) as (http, _): |
1360 | | - async with aconnect_sse( |
1361 | | - http, "POST", "/mcp", json=body, headers=_modern_headers(method="tools/call", name="park") |
| 1359 | + async with http.sse( |
| 1360 | + "/mcp", method="POST", json=body, headers=_modern_headers(method="tools/call", name="park") |
1362 | 1361 | ) as source: |
1363 | 1362 | # Advanced once only: a full `async for` would wait for the close that is ours to perform. |
1364 | | - events = source.aiter_sse() |
| 1363 | + events = aiter(source) |
1365 | 1364 | first = await anext(events) |
1366 | 1365 | # Awaited while the app is still mounted: after mounted_app exits, the bridge's |
1367 | 1366 | # teardown cancellation would make this pass vacuously. |
@@ -1491,7 +1490,7 @@ async def test_modern_mcp_param_header_disagreeing_with_body_argument_is_rejecte |
1491 | 1490 |
|
1492 | 1491 | Spec-mandated: the server resolves the ``x-mcp-header`` annotation from the tool's advertised |
1493 | 1492 | ``inputSchema`` via its own tools/list handler and rejects the decoded-header/body disagreement |
1494 | | - before dispatch. Raw httpx because the HTTP status is a wire-only observable and the typed |
| 1493 | + before dispatch. Raw httpx2 because the HTTP status is a wire-only observable and the typed |
1495 | 1494 | client cannot emit a mismatching header by construction. |
1496 | 1495 | """ |
1497 | 1496 |
|
|
0 commit comments