test(mcp): pin /graphql to honouring the local default token - #59
Merged
Conversation
Behaviour is already correct: graphql_endpoint's resolve_token call already falls back to mcp.default_token when a request has no headers. But nothing exercised graphql_endpoint itself — the existing tests only covered the pure resolve_token() function. If a future edit made that call site headers-only (e.g. for a headers-only mcp subcommand), every existing test would still pass while GraphiQL silently broke: a browser cannot attach the x-fastmail-token header, so the IDE would have no way to authenticate. Adds a regression test that calls graphql_endpoint directly with a FastmailMcp built with a fake default token, empty headers, and a non-introspection query, pre-seeding the client cache so the resolver's network attempt hits a refusing loopback address instead of the real Fastmail API. Also adds a one-line comment at the call site pinning the invariant for future reviewers. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SWusZmJbmiuciJYJs78V4P
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.
Summary
The behaviour here is already correct — this PR only pins it with a test, it does not change any credential resolution logic.
graphql_endpoint(src/mcp/mod.rs:314-352) already callsresolve_token(Some(&headers), mcp.default_token.as_deref()), the same central resolver the/mcpgraphqltool uses, so a request with nox-fastmail-tokenheader correctly falls back to the local config/env token.The gap: nothing exercised
graphql_endpointitself. The existing tests (src/mcp/mod.rs:452-506) only covered the pureresolve_token()function. Issue #56 is a guardrail for the planned migration to a headers-onlymcpsubcommand — if that's implemented by passingNoneinstead ofmcp.default_token.as_deref()at that call site, every existing test still passes, but GraphiQL breaks: a browser cannot attach the token header, so the IDE becomes unusable, which is the one thing--graphql/--graphiqlexist for.What changed
graphql_falls_back_to_local_config_when_no_headers: builds aFastmailMcpdirectly (notFastmailMcp::http(), so it never touches the developer's real config) with a fake default token, pre-seeds the client cache with a client pointed athttp://127.0.0.1:1(so the resolver's JMAP call fails fast/hermetically instead of hitting the live API), callsgraphql_endpointwith empty headers and a real field selection ({ session { status } }, not introspection), and asserts the response does not contain "No Fastmail token available".No behaviour change, no version bump, no changelog — test-only.
Proof the test actually guards something
Temporarily changed the :330 call site to pass
Noneinstead ofmcp.default_token.as_deref(), re-ran the new test, and it failed:Reverted, and
cargo testwas green again (174 passed).Test plan
cargo test— 174 passed, 0 failedcargo clippy --all-targets --all-features -- -D warnings— cleancargo fmt --all— no changes neededgit diff origin/main --stat— onlysrc/mcp/mod.rstouchedCloses #56
🤖 Generated with Claude Code
https://claude.ai/code/session_01SWusZmJbmiuciJYJs78V4P