Replace httpx and httpx-sse with httpx2 (#2972)
Some checks failed
CI / checks (push) Has been cancelled
CI / all-green (push) Has been cancelled

Co-authored-by: Max Isbey <224885523+maxisbey@users.noreply.github.com>
This commit is contained in:
Marcelo Trylesinski 2026-07-14 18:05:08 +02:00 • committed by GitHub
commit 2713b53b12
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,7 +2,7 @@
from collections.abc import Generator
import httpx
import httpx2
from mcp.client import Client
from stories._harness import Target, run_client
@ -10,22 +10,22 @@ from stories._harness import Target, run_client
from .server import DEMO_TOKEN, REQUIRED_SCOPE
class StaticBearerAuth(httpx.Auth):
"""``httpx.Auth`` that attaches a fixed ``Authorization: Bearer <token>`` to every request."""
class StaticBearerAuth(httpx2.Auth):
"""``httpx2.Auth`` that attaches a fixed ``Authorization: Bearer <token>`` to every request."""
def __init__(self, token: str) -> None:
self.token = token
def auth_flow(self, request: httpx.Request) -> Generator[httpx.Request, httpx.Response, None]:
def auth_flow(self, request: httpx2.Request) -> Generator[httpx2.Request, httpx2.Response, None]:
request.headers["Authorization"] = f"Bearer {self.token}"
yield request
def build_auth(_http: httpx.AsyncClient) -> httpx.Auth:
"""The demo bearer token as an ``httpx.Auth``.
def build_auth(_http: httpx2.AsyncClient) -> httpx2.Auth:
"""The demo bearer token as an ``httpx2.Auth``.
``Client(url, auth=...)`` doesn't exist yet, so the harness threads this onto the underlying
``httpx.AsyncClient`` and the target ``main`` receives is already routed through it.
``httpx2.AsyncClient`` and the target ``main`` receives is already routed through it.
"""
return StaticBearerAuth(DEMO_TOKEN)