How to test an MCP server in CI
A layered CI setup for an MCP server: in-process tests, the official conformance suite, Inspector CLI checks with real exit codes, a tool-list contract diff, and a load gate.
How to test an MCP server in CI
Most MCP servers are tested by clicking in Inspector and then connecting Claude. That finds the first bug and none after it. A CI job should catch three kinds of regression: the server stops speaking the protocol correctly, a tool changes in a way that breaks clients, and a tool call starts failing or slowing down. Each has a cheap, deterministic check.
Model behavior, meaning whether a model picks your tool, is a fourth kind and is not deterministic. Keep it out of the blocking path. We say how at the end.
Layer 1: test the handlers in-process
Fast tests belong at the bottom. The TypeScript SDK v2 testing guide describes an HTTP-style test with no socket:
- Put server construction in a
createServer()factory. - Wrap it with
createMcpHandler(createServer). - Give
StreamableHTTPClientTransportthe handler'sfetchas itsfetchoption, wrapping each call innew Request(url, init). The URL is never dialed. - Create a
Client, connect, and call tools withclient.callTool({ name, arguments }). - Assert on
result.structuredContent. A handler error comes back as a normal result withisError: true, and so does input that fails schema validation, so there is nothing to catch. - In
afterEach, callclient.close(), thenhandler.close().
This runs the same handler you deploy. The guide notes that the in-memory transport pair covers the 2025-era protocol only, so use handler.fetch for 2026-07-28 coverage. Check the page for exact imports, since the v2 package names differ from 1.x (@modelcontextprotocol/server and @modelcontextprotocol/client). If you are on the 1.x SDK, spin up your HTTP app on a free port in the test and use the SDK's client against it.
Test the failure paths too. Anthropic's review criteria say generic errors such as "Internal Server Error" with no detail fail review, and that inputs should be validated with actionable messages. A test that sends a bad argument and asserts the message names the argument is cheap insurance.
Layer 2: run the official conformance suite
The MCP conformance repository runs protocol scenarios against a server URL:
npx @modelcontextprotocol/conformance server --url http://localhost:3000/mcp
Useful flags from its README: --scenario runs one scenario, --suite picks active (the default), all, draft or pending, and --requirements <revision> runs exactly what a spec revision requires. Results land in results/server-<scenario>-<timestamp>/checks.json.
If you cannot pass everything yet, record known failures in a baseline file so CI blocks only regressions:
# conformance-baseline.yml
server:
- tools-call-with-progress
npx @modelcontextprotocol/conformance server --url http://localhost:3000/mcp --expected-failures ./conformance-baseline.yml
With a baseline, a failure that is listed exits 0, a failure that is not listed exits 1, and a listed scenario that now passes also exits 1 so you remove the stale entry. The repo also ships a composite GitHub Action. Start your server first, then:
- uses: modelcontextprotocol/conformance@v0.1.11
with:
mode: server
url: http://localhost:3001/mcp
expected-failures: ./conformance-baseline.yml
The README showed v0.1.11 when we read it. Pin to whatever tag is current. The package is young (we saw 0.1.x on npm), so expect the scenario list to change between releases.
Layer 3: Inspector CLI checks with real exit codes
The Inspector's CLI client runs one request, prints the result and exits, with stable exit codes. It requires Node.js 22.23.4+, 24.22.1+, or 26.12.1+ per the Inspector docs.
| Exit code | Meaning |
|---|---|
| 0 | Success |
| 3 | Server requires authentication |
| 4 | Server unreachable (DNS, refused, timeout) |
| 5 | tools/call returned isError: true, or the tool was not found |
| 6 | --strict found an error-level tool-schema portability problem |
| 10 | A --load run breached a threshold or baseline |
| 11 | The server answered HTTP 429 |
A smoke test for the tool list and one safe call:
set -euo pipefail
URL=https://preview.example.com/mcp
# the tool exists, and its schemas are portable across clients
npx @modelcontextprotocol/inspector --cli "$URL" --transport http --method tools/list --strict --format json \
| jq -e '.result.tools | map(.name) | index("search")' > /dev/null
# a read-only call succeeds (exit 5 if the tool returns isError)
npx @modelcontextprotocol/inspector --cli "$URL" --transport http \
--method tools/call --tool-name search --tool-arg query=test --format json > /dev/null
For servers behind OAuth, CI cannot complete a browser flow. The CLI docs say to pass --stored-auth-only, which fails fast with exit 3 instead of waiting on a callback. Use a test account, never a real customer's. For a header-token server, pass --header. See MCP OAuth for Claude and ChatGPT for what a correct 401 looks like.
Layer 4: a tool-list contract
Clients cache what your server told them. Renaming a tool, removing one, or adding a required parameter breaks callers. Save the tool list as a file in the repo and fail the build when it drifts without the file changing:
npx @modelcontextprotocol/inspector --cli "$URL" --transport http --method tools/list --format json \
| jq -S '.result.tools | sort_by(.name)' > tools.live.json
diff -u tools.snapshot.json tools.live.json
Sorting and jq -S make the diff stable. The 2026-07-28 spec says servers SHOULD return tools/list in a deterministic order, which helps client caches and prompt caching, so make that true in your server too. A snapshot update then becomes a deliberate commit that a reviewer sees. Treat removed tools, renamed tools and new required parameters as breaking.
Layer 5: a load gate
A single call passing says nothing about p99. The Inspector's load mode calls a tool repeatedly and exits 10 on a breach:
npx @modelcontextprotocol/inspector --cli "$URL" --transport http \
--method tools/call --tool-name search --tool-arg 'query=term-{{seq}}' \
--load --load-requests 200 --load-concurrency 5 --load-max-p99 1500 --load-max-error-rate 0.01
Vary arguments with the {{seq}} and {{rand:min-max}} placeholders, which work only in --load runs. The docs warn that a server that caches identical requests looks far faster under one fixed argument than under real traffic. Run this against a preview deployment, not production, and use a budget loose enough that shared runners do not flake.
Putting it together
Run layers 1 and 2 on every pull request against a locally started server. Run layers 3 to 5 against the preview URL after deploy. Keep secrets out of logs and out of the repo.
The non-deterministic layer, whether a model chooses the right tool from your descriptions, is best run on a schedule or as a non-blocking check with several trials per prompt, since single runs flap. Shipyard has a GitHub Action that runs a scan, diffs the live tools against a saved baseline and comments on the pull request, and a selection gate for that fourth kind. Everything above works without it.
Check your server
Run the free scan at /scan for a quick read on the public side of your server before you wire up CI.
Check your server against these rules
Scan runs the checks from this guide against a live URL and lists each failing rule with its fix.