Repository navigation
test(mcp): integration tests for MCP re-authorization against an msw server - #2751
Open
mattzcarey wants to merge 5 commits into
Open
mattzcarey wants to merge 5 commits into
mattzcarey wants to merge 5 commits into
Conversation
|
Contributor
|
✅ agents import sizes: no significant changes ( |
agents
@cloudflare/ai-chat
@cloudflare/codemode
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
mattzcarey
force-pushed
the
test/mcp-reauth-integration
branch
from
October 27, 2026 20:30
ec0c579 to
5371aff
Compare
mattzcarey
force-pushed
the
test/mcp-reauth-integration
branch
from
October 27, 2026 22:41
5371aff to
19134e8
Compare
mattzcarey
force-pushed
the
test/mcp-reauth-integration
branch
from
October 27, 2026 23:14
19134e8 to
bca3790
Compare
mattzcarey
force-pushed
the
test/mcp-reauth-integration
branch
from
October 28, 2026 10:05
bca3790 to
8c35168
Compare
mattzcarey
force-pushed
the
test/mcp-reauth-integration
branch
from
October 29, 2026 18:58
8c35168 to
8269096
Compare
… server - an Agent with its default transport talks to an OAuth-protected MCP server (createMcpHandler behind a bearer check and a token endpoint that checks PKCE) served through msw; callbacks go through routeAgentRequest, jobs run on alarms, and the object restarts between steps - covers mid-session step-up, refused refreshes, the step-up round limit (alternating and Object-member scope sets), removal and re-registration races, durable reconnects, give-up, id migration and link expiry - the standalone MCPClientManager capability tests use the same server - drops the unit tests and injected-fetch tests this stack added
- core re-authorization flows also run against a server that only speaks 2025-11-25, so the client's fallback path is exercised - step-ups from readResource, getPrompt and an AI SDK tool's execute; a missing server; the browser's WebSocket view of a step-up - denied and forged callbacks, saved tokens on wake, the one-hour round window - removal racing a queued add, a queued callback, a late or failed code exchange; one server reconnecting while another serves - reconnects for a server down at add time, a reconnect that needs the user, removal cancelling jobs
…equests - an SSE MCP server in the msw harness; OAuth on its message endpoint and concurrent refreshes over SSE - concurrent refresh tests hold the token endpoint so a race can't hide behind timing - race tests wait until a request is held at the server instead of sleeping
…s keep retrying - a 403, an invalid_target refresh and a revoked static token (with and without an OAuth callback) stop after one attempt and stay failed across wakes - temporarily_unavailable from the authorization server keeps backing off and recovers
mattzcarey
force-pushed
the
test/mcp-reauth-integration
branch
from
October 29, 2026 19:28
8269096 to
b61ea07
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The MCP re-authorization stack is now tested end to end. In
src/tests/mcp/integration/, an Agent using its default transport talks to an OAuth-protected MCP server that msw serves inside the test isolate: a realcreateMcpHandlerendpoint behind a bearer check, plus an authorization server that registers clients and checks PKCE at the token endpoint. AGENTS.md now says to fake HTTP servers this way instead of mockingfetch.Stacked on #2663, part of the work on #2658. The stack's earlier tests gave the transport a hand-written
fetchand calledhandleCallbackRequest()directly, so the real transport, OAuth discovery and callback routing never ran. I removed those along with the pure unit tests the stack added. The new tests drive the agent the way production does:routeAgentRequestrunDurableObjectAlarmctx.abort(), because graceful eviction waits forever on the client's opensubscriptions/listenstreamWhat they cover:
callTool,readResource,getPromptand an AI SDK tool'sexecute, and what a connected browser is sent over the WebSocketconstructorand the one-hour window403, aninvalid_targetrefresh, a revoked static token) while a temporarily unavailable authorization server keeps being retriedclient-capability.test.tsruns the reconnect and expiry jobs against the same server for a standaloneMCPClientManager. Writing these turned up a bug where requests that got a401together each started their own OAuth flow; the fix is in #2660.pnpm run check, the full agents workers suite and the client conformance lanes pass. Run against main's MCP client, 39 of the 50 integration tests fail; the 11 that pass are baseline behaviour such as connecting through OAuth, a silent refresh and wake with saved tokens. With the round-limit review fixes reverted, the alternating-scope andconstructortests fail.