2026-07-28 Spec Refactor Part 1: TypeScript servers: extensive unit tests + per-file 90% coverage gate
Author: cliffhallCreated Sep 26, 2026Updated Sep 28, 2026
Labelsv2
Part of the 2026-07-28 Spec Refactor tracker #4857. This is the first step, and has no dependencies.
Goal
Before any SDK or spec changes, build an extensive vitest suite that pins down the current behavior of every TypeScript server (everything, filesystem, memory, sequentialthinking) on @modelcontextprotocol/[email protected]. The suite must pass the inspector's coverage quality gate from #4474.
This suite is the regression net for Part 3 (#4856). The SDK v2 migration is supposed to be transparent on the wire, and these tests are how we prove it. Existing tests may be deleted where the new suite covers them better.
Test design
- Test through the protocol, in-process.
- Connect an SDK
Clientto each server over an in-memory transport, and assert on what goes over the wire: tool, resource and prompt lists, call results, errors and notifications. - Refactor each server so it can be built in-process, e.g. with a
createServer()factory thatindex.tscalls. Today thefilesystemintegration tests spawn the compiled server as a child process, so V8 reportsindex.tsas 0% covered (see the baseline in #4474). The in-process approach fixes that. - Keep at most a thin spawn-based smoke test for the binary entry point.
- Connect an SDK
- Stay migration-proof. Tests should touch only the public client API and wire-level shapes, not SDK internals or handler-context objects. In Part 3, the codemod should be able to update these tests with import and type changes alone. Any assertion that has to change during Part 3 is a behavior change and must be justified in that PR.
- Coverage by server:
everything: every tool, resource (including templates), prompt and completion. Also:- logging simulation
- subscriptions and list-changed notifications
- roots, sampling and elicitation, driven by a test client that answers the server's requests
- the experimental tasks tools
- the stdio, SSE and Streamable HTTP transports
filesystem:- every tool
- path validation, including symlink, traversal and unicode edge cases
- allowed-directory and Roots handling
- structured content and tool annotations
memory: knowledge-graph CRUD, persistence (atomic save, file path), search, and resource behavior.sequentialthinking: input schema, and branching and revision logic.
Quality gate (from #4474, modeled on the inspector's v2/main AGENTS.md)
- Threshold: ≥ 90 per file on all four dimensions (lines, statements, functions, branches). Set it in each server's vitest config:
coverage: { provider: 'v8', thresholds: { perFile: true, lines: 90, statements: 90, functions: 90, branches: 90 } }. - Unreachable branches: don't lower the gate for code that genuinely can't be reached. Mark it with a justified inline ignore at the source instead:
/* v8 ignore next -- <reason> */. - Separate coverage command: coverage is its own deliberate command (
npm run coverageper server, and a rootnpm run coveragethat chains the workspaces). If #4864 lands first, it has already split each workspace'stestfromcoverage, so this issue adds the thresholds to the existingcoveragescript. It is not part of the fasttest/validateloop. - CI posture (amended): CI enforces the per-file coverage gate, in a parallel
coveragejob next to the fast tests, as the Inspector's CI now does (inspector#2159). Maintainers decided this on PR #4861 (the agentic software factory inception doc). The coverage command stays separate from the fasttest/validateloop locally. Wiring it into CI andlocal:gateis #4871, so this issue only has to provide the command.
Acceptance criteria
- Every TS server passes
npm run coverageat 90/90/90/90 per file, enforced by config. - Every ignore comment carries a reason.
- The suite passes on current
main(SDK v1) in CI. - Removed tests are listed in the PR with the reason. Each server can be its own PR.
Carried over from #4474, which this issue supersedes
- Root
npm run coveragescript that chains the per-workspace coverage runs. - Once both this issue and Part 2 (#4855) land, put the rule back into
AGENTS.md(created through the agentic software factory tracker #4858, starting with #4859) under "Always test new or modified code". Adapt the wording from the inspector's reference, and cover the per-file ≥ 90 threshold on all four dimensions, the rule that every ignore needs a reason, and thecoveragevsvalidatesplit. IfAGENTS.mddoesn't exist yet by then, add this rule to theAGENTS.mdsub-issue under #4858 instead. - Baseline for
filesystemfrom #4474, measured onmainat76d64c82(statements / branches / functions / lines):- all files: 45.9 / 51.8 / 40.3 / 45.3
index.ts: 0 across the board, because it only runs in spawned processeslib.ts: about 77 / 66 / 89 / 77
Source: modelcontextprotocol/servers