MCP CI: testing MCP servers in continuous integration

Fail the build on breaking MCP schema changes, lint errors, and replay failures -- automatically, on every pull request.

Install: pip install mcp-testbench  |  PyPI: pypi.org/project/mcp-testbench

GitHub Action

The mcp-testbench repository is itself a GitHub Action:

name: mcp-testbench
on: [pull_request]

jobs:
  mcp-contract:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Lint the MCP server schema
        uses: mcp-testbench/mcp-testbench@v1
        with:
          mode: lint                      # check | lint | replay | snapshot
          server-command: "python my_server.py"

      - name: Fail on breaking schema changes
        uses: mcp-testbench/mcp-testbench@v1
        with:
          mode: check
          server-command: "python my_server.py"
          snapshot-path: mcp-snapshot.json

Inputs: server-command or url (exactly one), mode, snapshot-path, calls-file, python-version, mcp-testbench-version, and fail-on -- breaking (check mode), errors / warnings (lint mode), failures (replay mode), or never for report-only runs. The action installs mcp-testbench from PyPI, so there is nothing else to vendor.

pre-commit / prek hooks

The hooks test a live server (not files), so the server command is passed through args in your config:

# .pre-commit-config.yaml
repos:
  - repo: https://github.com/mcp-testbench/mcp-testbench
    rev: v0.4.0
    hooks:
      - id: mcp-testbench-lint
        args: [--, python, my_server.py]
      - id: mcp-testbench-check
        args: [mcp-snapshot.json, --, python, my_server.py]

prek reads the same hook definitions and config format -- no separate prek setup.

Exit codes are the gate

CommandExit 0Exit 1Exit 2
check / diffno breaking changesbreaking change foundprotocol / IO error
lintno errors (warnings allowed)lint errors, or any finding with --strictprotocol / IO error
replayall calls passedat least one call failedprotocol / IO error
snapshot / inspectsuccess--protocol / IO error

Any CI system that can run a shell command can gate on these -- the GitHub Action and hooks are conveniences, not requirements.

Badge

[![MCP contract](https://img.shields.io/badge/MCP%20contract-tested%20with%20mcp--testbench-green)](https://pypi.org/project/mcp-testbench/)