66import json
77from pathlib import Path
88
9- import httpx
9+ import httpx2
1010import pytest
1111from pydantic import ValidationError
1212from starlette .applications import Starlette
@@ -39,20 +39,20 @@ def make_discovery_app(*entries: CatalogEntry, catalog_path: str | None = None)
3939
4040
4141async def test_fetch_server_card_from_url () -> None :
42- transport = httpx .ASGITransport (app = make_discovery_app ())
43- async with httpx .AsyncClient (transport = transport ) as client :
42+ transport = httpx2 .ASGITransport (app = make_discovery_app ())
43+ async with httpx2 .AsyncClient (transport = transport ) as client :
4444 card = await fetch_server_card (CARD_URL , http_client = client )
4545 assert card == CARD
4646
4747
4848async def test_fetch_server_card_with_default_client (monkeypatch : pytest .MonkeyPatch ) -> None :
4949 # Cover the branch that creates its own client, without touching the
5050 # network: bind the module's client factory to an in-memory ASGI transport.
51- transport = httpx .ASGITransport (app = make_discovery_app ())
51+ transport = httpx2 .ASGITransport (app = make_discovery_app ())
5252 monkeypatch .setattr (
5353 client_module ,
5454 "create_mcp_http_client" ,
55- functools .partial (httpx .AsyncClient , transport = transport , follow_redirects = True ),
55+ functools .partial (httpx2 .AsyncClient , transport = transport , follow_redirects = True ),
5656 )
5757 assert await fetch_server_card (CARD_URL ) == CARD
5858
@@ -62,43 +62,43 @@ async def bad(_request: object) -> JSONResponse:
6262 return JSONResponse ({"name" : "missing-required-fields" })
6363
6464 app = Starlette (routes = [Route (CARD_PATH , bad , methods = ["GET" ])])
65- transport = httpx .ASGITransport (app = app )
66- async with httpx .AsyncClient (transport = transport ) as client :
65+ transport = httpx2 .ASGITransport (app = app )
66+ async with httpx2 .AsyncClient (transport = transport ) as client :
6767 with pytest .raises (ValidationError ):
6868 await fetch_server_card (CARD_URL , http_client = client )
6969
7070
7171async def test_fetch_raises_for_http_error () -> None :
7272 app = Starlette (routes = []) # nothing at the card URL -> 404
73- transport = httpx .ASGITransport (app = app )
74- async with httpx .AsyncClient (transport = transport ) as client :
75- with pytest .raises (httpx .HTTPStatusError ):
73+ transport = httpx2 .ASGITransport (app = app )
74+ async with httpx2 .AsyncClient (transport = transport ) as client :
75+ with pytest .raises (httpx2 .HTTPStatusError ):
7676 await fetch_server_card (CARD_URL , http_client = client )
7777
7878
7979async def test_discover_server_cards_via_well_known_catalog () -> None :
80- transport = httpx .ASGITransport (app = make_discovery_app ())
81- async with httpx .AsyncClient (transport = transport ) as client :
80+ transport = httpx2 .ASGITransport (app = make_discovery_app ())
81+ async with httpx2 .AsyncClient (transport = transport ) as client :
8282 cards = await discover_server_cards ("https://example.com" , http_client = client )
8383 assert cards == [CARD ]
8484
8585
8686async def test_discover_server_cards_with_default_client (monkeypatch : pytest .MonkeyPatch ) -> None :
8787 # Cover the branch that creates its own client, without touching the
8888 # network: bind the module's client factory to an in-memory ASGI transport.
89- transport = httpx .ASGITransport (app = make_discovery_app ())
89+ transport = httpx2 .ASGITransport (app = make_discovery_app ())
9090 monkeypatch .setattr (
9191 client_module ,
9292 "create_mcp_http_client" ,
93- functools .partial (httpx .AsyncClient , transport = transport , follow_redirects = True ),
93+ functools .partial (httpx2 .AsyncClient , transport = transport , follow_redirects = True ),
9494 )
9595 assert await discover_server_cards ("https://example.com" ) == [CARD ]
9696
9797
9898async def test_discover_server_cards_resolves_relative_entry_url () -> None :
9999 entry = server_card_entry (CARD , CARD_PATH ) # relative to the catalog location
100- transport = httpx .ASGITransport (app = make_discovery_app (entry ))
101- async with httpx .AsyncClient (transport = transport ) as client :
100+ transport = httpx2 .ASGITransport (app = make_discovery_app (entry ))
101+ async with httpx2 .AsyncClient (transport = transport ) as client :
102102 cards = await discover_server_cards ("https://example.com/mcp" , http_client = client )
103103 assert cards == [CARD ]
104104
@@ -110,8 +110,8 @@ async def test_discover_server_cards_reads_inline_data_entries() -> None:
110110 media_type = "application/mcp-server-card+json" ,
111111 data = CARD .model_dump (mode = "json" , by_alias = True , exclude_none = True ),
112112 )
113- transport = httpx .ASGITransport (app = make_discovery_app (entry ))
114- async with httpx .AsyncClient (transport = transport ) as client :
113+ transport = httpx2 .ASGITransport (app = make_discovery_app (entry ))
114+ async with httpx2 .AsyncClient (transport = transport ) as client :
115115 cards = await discover_server_cards ("https://example.com" , http_client = client )
116116 assert cards == [CARD ]
117117
@@ -125,17 +125,17 @@ async def test_discover_server_cards_ignores_non_card_entries() -> None:
125125 url = "https://example.com/agent.json" ,
126126 )
127127 app = make_discovery_app (server_card_entry (CARD , CARD_URL ), other )
128- transport = httpx .ASGITransport (app = app )
129- async with httpx .AsyncClient (transport = transport ) as client :
128+ transport = httpx2 .ASGITransport (app = app )
129+ async with httpx2 .AsyncClient (transport = transport ) as client :
130130 cards = await discover_server_cards ("https://example.com" , http_client = client )
131131 assert cards == [CARD ]
132132
133133
134134async def test_discover_server_cards_rejects_non_http_card_url () -> None :
135135 """A hostile catalog must not steer the client to non-http(s) schemes."""
136136 entry = server_card_entry (CARD , CARD_URL ).model_copy (update = {"url" : "file:///etc/passwd" })
137- transport = httpx .ASGITransport (app = make_discovery_app (entry ))
138- async with httpx .AsyncClient (transport = transport ) as client :
137+ transport = httpx2 .ASGITransport (app = make_discovery_app (entry ))
138+ async with httpx2 .AsyncClient (transport = transport ) as client :
139139 with pytest .raises (ValueError , match = "non-http" ):
140140 await discover_server_cards ("https://example.com" , http_client = client )
141141
@@ -147,25 +147,25 @@ async def test_discover_server_cards_ignores_non_mcp_entries() -> None:
147147 media_type = "application/a2a-agent-card+json" ,
148148 url = "https://agents.example.com/researchAssistant" ,
149149 )
150- transport = httpx .ASGITransport (app = make_discovery_app (agent_entry , server_card_entry (CARD , CARD_URL )))
151- async with httpx .AsyncClient (transport = transport ) as client :
150+ transport = httpx2 .ASGITransport (app = make_discovery_app (agent_entry , server_card_entry (CARD , CARD_URL )))
151+ async with httpx2 .AsyncClient (transport = transport ) as client :
152152 cards = await discover_server_cards ("https://example.com" , http_client = client )
153153 assert cards == [CARD ]
154154
155155
156156async def test_discover_server_cards_falls_back_to_mcp_catalog_path () -> None :
157157 app = make_discovery_app (catalog_path = MCP_CATALOG_WELL_KNOWN_PATH ) # no /.well-known/ai-catalog.json
158- transport = httpx .ASGITransport (app = app )
159- async with httpx .AsyncClient (transport = transport ) as client :
158+ transport = httpx2 .ASGITransport (app = app )
159+ async with httpx2 .AsyncClient (transport = transport ) as client :
160160 cards = await discover_server_cards ("https://example.com" , http_client = client )
161161 assert cards == [CARD ]
162162
163163
164164async def test_discover_server_cards_raises_when_no_catalog_exists () -> None :
165165 app = Starlette (routes = []) # 404 on both well-known paths
166- transport = httpx .ASGITransport (app = app )
167- async with httpx .AsyncClient (transport = transport ) as client :
168- with pytest .raises (httpx .HTTPStatusError ):
166+ transport = httpx2 .ASGITransport (app = app )
167+ async with httpx2 .AsyncClient (transport = transport ) as client :
168+ with pytest .raises (httpx2 .HTTPStatusError ):
169169 await discover_server_cards ("https://example.com" , http_client = client )
170170
171171
@@ -174,9 +174,9 @@ async def error(_request: object) -> Response:
174174 return Response (status_code = 500 )
175175
176176 app = Starlette (routes = [Route ("/.well-known/ai-catalog.json" , error , methods = ["GET" ])])
177- transport = httpx .ASGITransport (app = app )
178- async with httpx .AsyncClient (transport = transport ) as client :
179- with pytest .raises (httpx .HTTPStatusError ) as excinfo :
177+ transport = httpx2 .ASGITransport (app = app )
178+ async with httpx2 .AsyncClient (transport = transport ) as client :
179+ with pytest .raises (httpx2 .HTTPStatusError ) as excinfo :
180180 await discover_server_cards ("https://example.com" , http_client = client )
181181 assert excinfo .value .response .status_code == 500
182182
0 commit comments