| Filename | Latest commit message | Latest commit date |
|---|---|---|
Migrate all three clients + core + test-servers from
@modelcontextprotocol/sdk@1.29 to SDK v2 (2.0.0-beta.4), keeping behavior
identical against legacy (2025-11-25) servers. Foundation for the SDK V2 +
New Spec stack.
Packages
- Split @modelcontextprotocol/sdk -> @modelcontextprotocol/client (Client,
transports, OAuth, error taxonomy, protocol types) + core (Zod schemas);
stdio -> client/stdio, Ajv -> client/validators/ajv. Test-servers ->
@modelcontextprotocol/server (+ server-legacy/sse). Deterministic import
rewrite (schemas -> core, everything else -> client); the codemod misroutes
client code to /server so it was not used for path routing.
- new Client(..., { versionNegotiation: { mode: 'legacy' } }) — nothing
2026-era goes on the wire.
Runtime (core/mcp/inspectorClient.ts)
- Error taxonomy: McpError -> ProtocolError, ErrorCode -> ProtocolErrorCode;
RequestTimeout -> SdkError/SdkErrorCode.
- Handlers take method strings; task methods (tasks/*, notifications/tasks/*)
use the 3-arg custom form (excluded from v2's spec-method set).
- Legacy tasks kept working (per project requirement): requestor tasks re-
implemented over raw client.request + explicit deprecated schemas;
experimental.tasks.callToolStream replaced by a local pollTaskToolCall
async generator (with _progressHandlers revival so task-execution progress
still reaches the caller). Receiver (server-initiated) tasks: the v2 Client
validates a sampling/elicit handler result and rejects the legacy { task }
response with -32602 — installReceiverTaskResponseBypass swaps the wrapped
entry in the private _requestHandlers map for the task-augmented branch so
{ task } reaches the wire (fixes server-initiated sampling-via-task).
- Pagination: list verbs use raw client.request({method}, List*ResultSchema)
for single-page behavior (v2's client.listX() auto-aggregate all pages).
Web / auth / apps
- Rename local JsonSchemaType -> InspectorFormSchema + add toFormSchema()
structural narrowing at the SDK-schema -> form boundary.
- ext-apps still peers on SDK v1: one compat boundary with documented casts
(remove when ext-apps#702 lands a v2 peer).
- OAuth provider saveClientInformation reconciled with v2's
OAuthClientInformationContext; InvalidClientMetadataError re-homed as a
local class (server-legacy/auth is not browser-safe).
- vitest.shared.mts dedupes @modelcontextprotocol/client+core to one copy so
vi.mock intercepts the SUT's import.
Accepted v2 behavior changes (per #1624 / spec §9.2): unknown-tool call
rejects with -32602; cancellation is stream-abort (no guaranteed
notifications/cancelled frame); output-schema strictness restored via the
Inspector's own Ajv check on the default path.
npm run ci green: validate (web 3087 / cli 212 / tui 274 / launcher 5),
coverage (>=90 per-file, all clients), smoke (launcher/cli/web), storybook
(410).
Closes #1624
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
||
| .. | ||
| helpers | ||
| app-info.test.ts | ||
| cli.test.ts | ||
| cliOAuth.test.ts | ||
| e2e.test.ts | ||
| emit-result.test.ts | ||
| error-handler.test.ts | ||
| format-json.test.ts | ||
| headers.test.ts | ||
| metadata.test.ts | ||
| methods.test.ts | ||
| oauth-interactive.test.ts | ||
| oauth-runner.test.ts | ||
| programmatic-ergonomics.test.ts | ||
| README.md | ||
| stored-auth.test.ts | ||
| tools.test.ts | ||
CLI Tests
Running Tests
# Run all tests (pretest builds test-servers + the CLI binary)
npm test
# Run all tests under the per-file coverage gate
npm run test:coverage
# Run in watch mode (useful for test file changes)
npm run test:watch
# Run specific test file
npm run test:cli # cli.test.ts
npm run test:cli-tools # tools.test.ts
npm run test:cli-headers # headers.test.ts
npm run test:cli-metadata # metadata.test.ts
npx vitest run oauth-interactive.test.ts cliOAuth.test.ts # OAuth interactive smoke parity
How the CLI is exercised
Most tests run the CLI in-process: helpers/cli-runner.ts imports runCli()
from ../src/cli.ts and invokes it directly, capturing process.stdout/stderr
and mapping thrown errors to an exit code. This is what lets vitest's v8 coverage
instrument clients/cli/src (#1484). Because commander uses .exitOverride(),
a parse/usage error throws instead of calling process.exit and tearing down the
worker.
e2e.test.ts is the deliberately thin out-of-process layer: it spawns the
built build/index.js as a real subprocess to cover the shebang, the
index.ts isMain bootstrap, and the actual process.exit codes — the only
parts the in-process runner can't reach. (scripts/smoke-cli.mjs at the repo
root provides a further end-to-end check of the binary.)
Test Files
cli.test.ts- Basic CLI functionality: CLI mode, environment variables, config files, resources, prompts, logging, transport typestools.test.ts- Tool-related tests: Tool discovery, JSON argument parsing, error handling, promptsheaders.test.ts- Header parsing and validationmetadata.test.ts- Metadata functionality: General metadata, tool-specific metadata, parsing, merging, validationmethods.test.ts- Method/option-validation paths not covered elsewhere (resource templates, missing/invalid options, the--target separator)error-handler.test.ts- The binary'shandleErrorerror sink, exercised in-process withprocess.exitstubbedoauth-runner.test.ts- OAuth flag wiring (--client-config,--callback-url, CIMD overrides)cliOAuth.test.ts- Unit tests forcliOAuth.ts(step-up confirm, helper wiring, retry)oauth-interactive.test.ts- Integration smoke parity for CLI interactive OAuth: connect-time callback server + step-up y/N against composableTestServerHttp(auto-completes authorize URL programmatically; not a subprocess binary e2e)e2e.test.ts- Out-of-process spawn of the built binary (exit codes + boot; no OAuth)
Helpers
The helpers/ directory contains shared utilities:
cli-runner.ts- InvokesrunCli()in-process and captures stdout/stderr + exit codeassertions.ts- Custom assertion helpers for CLI output validationfixtures.ts- Test config/catalog file generators and temporary directory management
HTTP/SSE test servers (for transport tests) come from the
@modelcontextprotocol/inspector-test-server package (createTestServerHttp),
and the bundled stdio server is launched via getTestMcpServerCommand().
Notes
- Test files run in separate forked processes (
pool: 'forks'), so the in-process runner'sprocess.std*.writepatching never overlaps across files; tests within a file run sequentially - Config files use
crypto.randomUUID()for uniqueness - HTTP/SSE servers use dynamic port allocation to avoid conflicts
- Coverage is enforced per-file (lines ≥ 90, statements ≥ 85, functions ≥ 80,
branches ≥ 50).
src/index.ts(the binary bootstrap) is excluded because it only runs in the spawned binary, which coverage can't instrument - All tests use the built-in MCP test servers — no external/registry dependencies