testing
Testing
The rules are in AGENTS.md under **Always test new
or modified code**: new behavior comes with tests, every TypeScript file clears
the per-file coverage gate, test at the protocol level where you can, and keep
expected error output off the console. This skill explains the harness each
server has, how to write a test with it, which command runs what, and how to
clear the per-file coverage gate.
Driving a running server by hand, with the Inspector or an LLM client, is
/client-smoke. It is evidence for a PR, not a substitute for a test.
Every server is tested in-process, and every file is gated. The four
TypeScript servers link a real Client to the server over an in-memory
transport (#4854); the three Python servers link a ClientSession to the real
serve() over in-memory streams (#4855). Both languages hold each file to a
per-file coverage floor, in CI and in npm run local:gate.
Where a test goes
| Server | Directory | File name | Runner |
| --- | --- | --- | --- |
| everything, filesystem, memory, sequentialthinking | src/<server>/__tests__/ | <subject>.test.ts | vitest, globals: true |
| fetch, git, time | src/<server>/tests/ | test_<subject>.py | pytest, with pytest-asyncio (asyncio_mode = "auto") |
| Root tooling | scripts/, beside the script | <name>.test.mjs | node --test |
Each vitest config includes only /__tests__//*.test.ts, so a test file
anywhere else in a workspace is never run and reports nothing. Shared test
helpers go in __tests__/ without the .test suffix, as each server's
connection harness does (__tests__/harness.ts in everything,
__tests__/helpers.ts in the other three).
What each server's tests do
| Server | How its tests reach the code |
| --- | --- |
| everything, filesystem, memory, sequentialthinking | An SDK Client connected to the server's createServer() over InMemoryTransport, in the vitest process, through the server's own harness, plus unit tests of helper modules such as lib.ts. everything drives its stdio, SSE and Streamable HTTP transports in-process too; the other three drive their http.ts in-process over a free loopback port, and have one thin spawn smoke of the built dist/index.js |
| fetch, git, time | A ClientSession linked in-process to the real serve() over in-memory streams (below), plus direct calls on the pure functions in server.py |
No TypeScript test uses an in-memory transport yet.
Choosing a harness for a new test
Ask what the test must prove.
- Logic (a path check, a graph operation, a timezone conversion): call the
function directly. That is what lib.ts and the functions in server.py are
for.
- What a client sees (a tool's result shape, its advertised schema, an
error result, a capability, a notification): drive the server through a
client. A handler called directly skips the SDK's input validation, output
schema validation and error mapping, which is where the wire-level bugs in
this repo have been.
Which client harness is available depends on the language.
TypeScript: in-process, over an in-memory transport
Each TypeScript server exports a createServer(…) factory and starts its
transport only from a guarded main(), so importing it starts nothing and a
test can link a real Client to a real server with no process and no build.
**Each server's __tests__/ has a harness that does the linking. Connect
through it**, never by calling createServer() and
InMemoryTransport.createLinkedPair() by hand: the harness also does the
per-session setup and teardown the server needs.
| Server | Factory | Harness | connect(…) takes |
| --- | --- | --- | --- |
| everything | createServer() in server/index.ts, returns { server, cleanup } | __tests__/harness.ts | { capabilities, setup, sessionId }, all optional |
| filesystem | createServer(allowedDirectories) in server.ts | __tests__/helpers.ts | the allowed directories, then { capabilities, listRoots } |
| memory | createServer(memoryFilePath) in index.ts | __tests__/helpers.ts | the graph file's path (makeTempGraph() makes one) |
| sequentialthinking | createServer() in index.ts | __tests__/helpers.ts | { disableThoughtLogging }, defaulting to "true" |
Each connect returns the client and a close(); call close() in
afterEach. The harnesses also export small result helpers (call,
textOf and the like); read the one you are using before adding another.
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import type { Client } from "@modelcontextprotocol/client";
import { connect, contentOf, textOf, type Session } from "./harness.js";
describe("echo, over the protocol", () => {
let session: Session;
let client: Client;
beforeEach(async () => {
session = await connect();
client = session.client;
});
afterEach(async () => {
await session.close();
});
it("returns the message", async () => {
const result = await client.callTool({
name: "echo",
arguments: { message: "hi" },
});
expect(textOf(contentOf(result)[0])).toBe("Echo: hi");
});
it("reports bad input as a tool error", async () => {
const result = await client.callTool({ name: "echo", arguments: {} });
expect(result.isError).toBe(true);
});
});What everything's harness does that a hand-rolled connection would miss:
- A session id per connection. Logging, subscriptions, roots and the
to
