Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

test(mcp): attribute passthrough probe traffic to the caller instead of the whole peer log (#46020)

devin-ai-integration[bot]78b8d89afe8b
diff --git a/tests/integration/mcp/test_mcp_credentials.py b/tests/integration/mcp/test_mcp_credentials.py
index ee36581acdd..63f1b0024c0 100644
--- a/tests/integration/mcp/test_mcp_credentials.py
+++ b/tests/integration/mcp/test_mcp_credentials.py
@@ -631,16 +631,23 @@ def test_oauth_passthrough_probe_uses_server_token_without_admission_key(
with mcp_peer() as peer, gateway.scenario() as scenario:
alias: Final = "probe" + uuid.uuid4().hex[:8]
identity: Final = register_mcp(
- scenario, peer, alias, auth_type="none", oauth_passthrough=True, extra_headers=["Authorization"]
+ scenario,
+ peer,
+ alias,
+ auth_type="none",
+ oauth_passthrough=True,
+ extra_headers=["Authorization", "x-integration-caller"],
)
key: Final = scenario.key(object_permission={"mcp_servers": [identity]})
upstream_token: Final = "upstream-" + uuid.uuid4().hex
+ caller_trace: Final = "caller-" + uuid.uuid4().hex
caller: Final = McpCaller(
gateway,
key,
entry,
alias,
headers={
+ "x-integration-caller": caller_trace,
"Authorization": f"Bearer {upstream_token if forwarded_token else key}",
f"x-mcp-{alias}-authorization": "Bearer expired-token"
if forwarded_token
@@ -651,18 +658,28 @@ def test_oauth_passthrough_probe_uses_server_token_without_admission_key(
outcome: Final = caller.call(f"{alias}-add", ADD, identity if entry != "server_mcp" else None)
assert outcome.ok, outcome.raw
observed: Final = peer.drain()
+ forwarded: Final = f"Bearer {upstream_token}".encode()
probes: Final = tuple(
request
for request in observed
if TypeAdapter(dict[str, object]).validate_python(request["body"]).get("id") == "litellm-mcp-auth-probe"
)
assert probes, "expected an upstream initialize authentication probe"
- assert all(_header(probe, b"authorization") == f"Bearer {upstream_token}".encode() for probe in probes)
- assert len(tool_calls(observed)) == 1
- foreign: Final = tuple(
- request for request in observed if _header(request, b"authorization") != f"Bearer {upstream_token}".encode()
+ assert all(_header(probe, b"authorization") == forwarded for probe in probes)
+ callers_own: Final = tuple(
+ request for request in observed if _header(request, b"x-integration-caller") == caller_trace.encode()
)
+ assert len(tool_calls(observed)) == 1
+ assert len(tool_calls(callers_own)) == 1, "the tool call lost the caller's forwarded headers"
+ attributed: Final = probes + callers_own
+ foreign: Final = tuple(request for request in attributed if _header(request, b"authorization") != forwarded)
assert foreign == (), foreign
+ credentialed_background: Final = tuple(
+ request
+ for request in observed
+ if request not in attributed and _header(request, b"authorization") is not None
+ )
+ assert credentialed_background == (), credentialed_background
header_sets: Final = tuple(
TypeAdapter(dict[bytes, bytes]).validate_python(request["headers"]) for request in observed
)