feat(cli): --bearer / --header for auth-gated MCP endpoints - #27
Merged
Conversation
`mcp-contract-kit test` connected anonymously, so MCP servers whose transport requires auth returned HTTP 401 on connect and ran 0 suites. The header pipeline already existed end-to-end (runTests → createMCPClient → HttpTransport); it just wasn't reachable: the CLI had no flag, and runTestCommand dropped `headers` when building RunOptions. - config.ts: parse `--bearer <token>` (→ Authorization: Bearer) and repeatable `--header "Name: Value"`; document both in --help. - test.command.ts: forward `headers` into runTests. - tests: cover parsing (bearer, header trimming, repeats, colon-in-value, error). Closes #26.
…-RPC errors Make the conformance client work end-to-end against an MCP Streamable HTTP server (auth-gated or not). Previously, after `initialize` succeeded, every follow-up request failed and the suites couldn't run. - transport: send `Accept: application/json, text/event-stream` by default (servers answer HTTP 406 without it); normalize header names to lowercase so an explicit `--header Accept`/`--bearer` cleanly overrides defaults. - client: capture the server-assigned `Mcp-Session-Id` from the initialize response and echo it on all later requests (previously a throwaway id → 400). - transport: when a non-2xx response carries a valid JSON-RPC body (e.g. 400 "Invalid Request"), return it instead of throwing, so validators see the real JSON-RPC error. - validators(jsonrpc): per spec, allow a null id on Invalid Request (-32600) and Parse error (-32700) responses instead of flagging an id mismatch. Adds client tests (Accept default, session capture/echo, header override). Verified against the MediaLocker MCP gateway: protocol + security suites pass 0 critical. Bumps client minor (0.2.0), validators patch (0.1.2), cli patch (0.2.1).
…ring>
The root `tsc -p tsconfig.typecheck.json` (the CI Type Check job) includes test
files and is stricter than the per-package typecheck. The `extra` ternary
widened to `{ 'mcp-session-id'?: undefined }`, which isn't assignable to the
mock's `Record<string, string>` headers param. Annotate it explicitly. Test-only
change; the published dist is unaffected.
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.
Closes #26.
mcp-contract-kit testconnected anonymously, so MCP servers whose transport requires auth returnedHTTP 401and ran 0 suites. The header pipeline already existed end-to-end (runTests → createMCPClient → HttpTransport); it just wasn't reachable — no CLI flag, andrunTestCommanddroppedheaders.Changes
config.ts: parse--bearer <token>(→Authorization: Bearer) and repeatable--header "Name: Value"; documented in--help.test.command.ts: forwardheadersintorunTests.@reaatech/mcp-contract-climinor → 0.2.0.Verified
Build, typecheck, biome, and
vitestall green. End-to-end against the MediaLocker MCP gateway:--bearerresolves the 401 (the kit now authenticates and proceeds past the auth hook).