fix: dual-era MCP server detection in doctor probe + 2026-07-28 header contract in mcp run - #404
Draft
rafa-thayto wants to merge 1 commit into
Draft
fix: dual-era MCP server detection in doctor probe + 2026-07-28 header contract in mcp run#404rafa-thayto wants to merge 1 commit into
rafa-thayto wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 76c64ae The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
…der contract in mcp run The doctor probe now implements the MCP 2026-07-28 backward-compatibility algorithm: modern server/discover first, inspecting a 400 body for recognized modern JSON-RPC errors before falling back to the legacy initialize handshake. clerk mcp run mirrors the body into the required request-metadata headers (MCP-Protocol-Version, Mcp-Method, Mcp-Name with Base64 sentinel encoding, and x-mcp-header parameter mirroring as Mcp-Param-*), and no longer treats a missing session id as a dead connection against stateless servers. Fixes AIE-1355
rafa-thayto
force-pushed
the
rafa-thayto/aie-1355-cli-mcp-dual-era
branch
from
July 31, 2026 20:26
c8d69f1 to
76c64ae
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.
Fixes AIE-1355
What
Implements MCP 2026-07-28 support in the CLI's hand-rolled MCP bridge (SDK remains a type-only import).
clerk doctorprobe (probe.ts)Implements the spec's backward-compatibility algorithm:
server/discoverfirst (per-request_meta+MCP-Protocol-Version/Mcp-Methodheaders).-32020HeaderMismatch,-32021MissingRequiredClientCapability,-32022UnsupportedProtocolVersion) proves a modern server and never falls back —-32021(capability-gated) counts as reachable, and-32022is retried once with an advertised supported version. Reserved MCP codes on non-400 statuses (proxy error pages) are not trusted and still fall back.initializehandshake, so legacy-only servers keep probing correctly.401/403at either stage still reads as "reachable, authentication required".clerk mcp runrelay (run.ts)Every relayed POST now carries the 2026-07-28 request-metadata headers, derived from the body so strict servers never reject with
HeaderMismatch(-32020):Mcp-Methodfrom the bodymethod.Mcp-Namefromparams.name/params.uriontools/call/resources/read/prompts/get, with Base64 sentinel encoding (=?base64?…?=) for non-header-safe values.MCP-Protocol-Versionfrom the request's own_metawhen a modern client declares it, else the legacy-negotiated version.Mcp-Param-*mirroring forx-mcp-headertool parameters, learned fromtools/listresponses; tools with spec-invalid annotations are excluded from forwardedtools/listresults (with a stderr warning), as the spec requires.Mcp-Session-Idyet" as "connection never worked" — 2026-07-28 servers are stateless and never mint one, so a scoped 401 mid-run no longer kills the bridge.Shared header/encoding/annotation logic lives in a new
headers.ts.How verified
bun run format,bun run lint,bun run typecheck,bun run test(2525 pass) all green locally.bun run test:e2e:opcould not run locally (no access to the "AI Enablement" 1Password vault from this machine); e2e does not touch the MCP code paths and runs in CI on this PR.Docs
commands/mcp/README.md— bridge header contract + dual-era reachability note.commands/doctor/README.md— MCP check description.patch.