# Check tools in your tests

The checks come from the `is-mcp-ok` package, so an end-to-end test can run them on what your server returns. That includes each `tools/call` result, which the CLI never calls on its own.

```sh
pnpm add -D is-mcp-ok
```

The package has no runtime dependencies and runs in Node, the browser and a Cloudflare Worker.

## Every tool, every client

Connect with the MCP SDK, call each tool, and check the list and every result:

```ts [tests/e2e/mcp.spec.ts]
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
import { checkMcpClientLimits, checkMcpToolResult, formatMcpFindings } from "is-mcp-ok";
import { expect, test } from "vitest";
import { sampleArguments } from "./mcp-arguments";

test("every client gets every tool intact", async () => {
  const client = new Client({ name: "e2e", version: "1.0.0" });
  await client.connect(new StreamableHTTPClientTransport(new URL("http://localhost:3000/mcp")));
  const tools = [];
  let cursor: string | undefined;

  do {
    const page = await client.listTools(cursor === undefined ? undefined : { cursor });
    tools.push(...page.tools);
    for (const tool of page.tools) {
      const result = await client.callTool({
        name: tool.name,
        arguments: sampleArguments[tool.name],
      });
      expect(formatMcpFindings(checkMcpToolResult(result, { tool }))).toBe("");
    }
    cursor = page.nextCursor;
  } while (cursor !== undefined);

  expect(formatMcpFindings(checkMcpClientLimits({ tools }, { serverName: "shop" }))).toBe("");
});
```

Call each page's tools before listing the next page: `listTools` replaces the SDK's cached `outputSchema` validators. Keep the full list for the checks that depend on the total tool count.

## Readable failures

`formatMcpFindings` prints every finding at `warn` or `error` as text, the worst first, and an empty string when there is none. A failing test shows each finding's rule, tool, message and fix instead of a JSON diff:

```text
warn codex/structured-content-replaces-text search_orders at /structuredContent
  When Codex calls MCP tools directly (…), it sends the model only `structuredContent` as JSON, …
  fix: Put everything the model needs in `structuredContent`, or make the text content the same JSON.
  source: https://github.com/openai/codex/…
```

Fail on `warn`, not only on `error`. No check of an answer is an `error`, because the client still gets the answer, so a test that fails only on errors checks no answer at all. Pass `{ severity: "info" }` to print info too.

## Which function

| Function                                | Returns                                                                                           |
| --------------------------------------- | ------------------------------------------------------------------------------------------------- |
| `checkMcpToolList(list)`                | The [Diagnostic Codes](https://ismcpok.dev/docs/reference/mcp#diagnostic-codes), one per code and tool.              |
| `checkMcpClientLimits(list)`            | The client findings behind them, each with the client, the rule, a message, a fix and its source. |
| `checkMcpToolResult(result, { tool })`  | What each client does with one `tools/call` result.                                               |
| `checkMcpAnswer(call, { tool, tools })` | One entry of a report's `answers`: size, causes, advice and client findings.                      |
| `mcpReport(session)`                    | What `is-mcp-ok --json` prints, without `source` and `endpoint`.                                  |
| `fetchMcpToolList(url)`                 | `initialize` and every page of `tools/list` over Streamable HTTP.                                 |
| `mcpDocsUrl(code)`                      | The link to a code on [the reference page](https://ismcpok.dev/docs/reference/mcp).                                  |

Pass `clients: ["claude-code", "vscode"]` to check only the clients you support, and `codes` to `checkMcpToolList` to report only some codes. `formatMcpFindings` also takes what `checkMcpToolList` returns, one `checkMcpAnswer`, or a whole `mcpReport`.

<!-- vitehub-docs:section-links -->
## In this section

- [Introduction](https://ismcpok.dev/raw/docs/guide.md)
- [Installation](https://ismcpok.dev/raw/docs/guide/installation.md)
- [Check a server](https://ismcpok.dev/raw/docs/guide/servers.md)
- [Check answers](https://ismcpok.dev/raw/docs/guide/answers.md)
- [Token budget](https://ismcpok.dev/raw/docs/guide/budget.md)
- [Run in CI](https://ismcpok.dev/raw/docs/guide/ci.md)
- [Check tools in your tests](https://ismcpok.dev/raw/docs/guide/testing.md) (this page)
- [Coding agents](https://ismcpok.dev/raw/docs/guide/agents.md)

Next: [Coding agents](https://ismcpok.dev/raw/docs/guide/agents.md)

All pages: [llms.txt](https://ismcpok.dev/llms.txt)
