Repository navigation
test(e2e): cover MCP gateway auth headers and per-server max concurrency #33102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tin-berri
wants to merge
17
commits into
main
Choose a base branch
from
litellm_mcp_e2e_tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
5edc486
test(e2e): cover MCP gateway auth headers and per-server max concurrency
tin-berri d74cf13
fix(e2e): restore uv.lock exclude-newer anchor and gate proxy startup…
tin-berri 565a872
refactor(e2e): inline the concurrency burst in the test via a thread …
tin-berri 23dffc7
fix(e2e): use a plain union assignment instead of a PEP 695 type stat…
tin-berri ff3ef9d
refactor(e2e): keep the concurrency test self-contained with local tu…
tin-berri 9ff988d
refactor(e2e): split the mcp gateway suite into feature-scoped specs …
tin-berri d32974c
refactor(e2e): build wire headers and mint keys inline in the mcp tes…
tin-berri b1442d0
refactor(e2e): unroll the auth-header matrix into explicitly named pe…
tin-berri 1b42f65
test(e2e): cover the interactive authorization_code MCP OAuth flow en…
tin-berri c1e5ca7
test(e2e): run the official MCP conformance suite through the gateway…
tin-berri 6c0d405
refactor(e2e): scope the mcp suite to the core happy paths, keeping t…
tin-berri 9fb7271
refactor(e2e): name the interactive OAuth test as the list-and-call h…
tin-berri 9b144f1
test(e2e): run the list-and-call happy path through the interactive O…
tin-berri 5880135
test(e2e): assert the server record round-trips in the ingress reject…
tin-berri 4fba2f4
refactor(e2e): make the Authorization-header OAuth test a challenge-g…
tin-berri 644d1ec
test(e2e): a stored per-user token lets the key in Authorization list…
tin-berri b92b7cc
refactor(e2e): drop the unused conformance/prompts/resources foundation
tin-berri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| """In-process reverse proxy that stamps the LiteLLM key onto every request. | ||
|
|
||
| The official conformance suite's client offers no way to send custom headers, | ||
| but the gateway's MCP routes require the virtual key. This forwarder plays the | ||
| role of an MCP host's HTTP layer configured with the key header: it listens on | ||
| a loopback port, injects `x-litellm-api-key: Bearer <key>`, and relays | ||
| everything (including SSE streams, unbuffered) to the proxy under test. | ||
|
|
||
| Runs inside the pytest process on a background uvicorn thread; tests get the | ||
| local base URL from `serve()` and hand `{base}/{alias}/mcp` to the conformance | ||
| CLI as the server under test. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import socket | ||
| import threading | ||
| import time | ||
| from collections.abc import Generator | ||
| from contextlib import contextmanager | ||
| from typing import cast | ||
|
|
||
| import httpx | ||
| import uvicorn | ||
| from starlette.applications import Starlette | ||
| from starlette.background import BackgroundTask | ||
| from starlette.requests import Request | ||
| from starlette.responses import StreamingResponse | ||
| from starlette.routing import Route | ||
|
|
||
| from e2e_config import PROXY_BASE_URL, REQUEST_TIMEOUT | ||
|
|
||
| _HOP_BY_HOP_REQUEST_HEADERS = frozenset({"host", "content-length"}) | ||
| _HOP_BY_HOP_RESPONSE_HEADERS = frozenset({"content-length", "transfer-encoding", "content-encoding"}) | ||
|
|
||
|
|
||
| def _build_app(upstream: httpx.AsyncClient, litellm_key: str) -> Starlette: | ||
| async def forward(request: Request) -> StreamingResponse: | ||
| url = httpx.URL(path=request.url.path, query=request.url.query.encode()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no httpx, use the tests/e2e/claude.md |
||
| headers = { | ||
| name: value | ||
| for name, value in request.headers.items() | ||
| if name.lower() not in _HOP_BY_HOP_REQUEST_HEADERS | ||
| } | ||
| headers["x-litellm-api-key"] = f"Bearer {litellm_key}" | ||
| proxied = upstream.build_request(request.method, url, headers=headers, content=await request.body()) | ||
| response = await upstream.send(proxied, stream=True) | ||
| response_headers = { | ||
| name: value | ||
| for name, value in response.headers.items() | ||
| if name.lower() not in _HOP_BY_HOP_RESPONSE_HEADERS | ||
| } | ||
| return StreamingResponse( | ||
| response.aiter_raw(), | ||
| status_code=response.status_code, | ||
| headers=response_headers, | ||
| background=BackgroundTask(response.aclose), | ||
| ) | ||
|
|
||
| methods = ["GET", "POST", "DELETE", "PUT", "PATCH", "HEAD", "OPTIONS"] | ||
| return Starlette(routes=[Route("/{path:path}", forward, methods=methods)]) | ||
|
|
||
|
|
||
| def _free_loopback_port() -> int: | ||
| with socket.socket() as sock: | ||
| sock.bind(("127.0.0.1", 0)) | ||
| return cast("int", sock.getsockname()[1]) | ||
|
|
||
|
|
||
| @contextmanager | ||
| def serve(litellm_key: str) -> Generator[str]: | ||
| """Serve the forwarder for the block's duration; yields its base URL.""" | ||
| upstream = httpx.AsyncClient(base_url=PROXY_BASE_URL, timeout=httpx.Timeout(REQUEST_TIMEOUT)) | ||
| port = _free_loopback_port() | ||
| server = uvicorn.Server( | ||
| uvicorn.Config(_build_app(upstream, litellm_key), host="127.0.0.1", port=port, log_level="warning") | ||
| ) | ||
| thread = threading.Thread(target=server.run, daemon=True) | ||
| thread.start() | ||
| deadline = time.monotonic() + 15 | ||
| while not server.started: | ||
| assert time.monotonic() < deadline, "auth forwarder never started" | ||
| time.sleep(0.05) | ||
| try: | ||
| yield f"http://127.0.0.1:{port}" | ||
| finally: | ||
| server.should_exit = True | ||
| thread.join(timeout=10) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| """Fixtures for the mcp e2e suite. | ||
|
|
||
| The shared lifecycle (`resources`, `scoped_key`), the liveness gate, and the | ||
| `e2e` marker come from the parent tests/e2e/conftest.py; this adds the suite | ||
| client. The mcp SDK lives in the `e2e-dev` dependency group (like playwright | ||
| for management/), so its import is guarded to skip the suite rather than | ||
| error at collection when it is not installed. | ||
| """ | ||
|
|
||
| import pytest | ||
|
|
||
| pytest.importorskip("mcp", reason="mcp SDK not installed; run `uv sync --inexact --group e2e-dev`") | ||
|
|
||
| from mcp_client import McpClient, build_client # noqa: E402 # import must follow the importorskip guard above | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def client() -> McpClient: | ||
| return build_client() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dont need