Skip to main content
Glama
README.md
# `apishield-mcp` — Offline OpenAPI & JSON Payload Breaking-Change MCP Server, CLI & GitHub Action

[![z121245017-ai/apishield-mcp MCP server](https://glama.ai/mcp/servers/z121245017-ai/apishield-mcp/badges/score.svg)](https://glama.ai/mcp/servers/z121245017-ai/apishield-mcp)

Zero-dependency, 100% offline **Model Context Protocol (`MCP`) Server**, **CLI**, and **GitHub Action** enabling AI coding agents (Claude Desktop, Claude Code, Cursor, Windsurf, Antigravity) and pull-request CI pipelines to detect breaking API contract changes across **OpenAPI `3.0`/`3.1`**, **Swagger `2.0`**, and **raw Before/After JSON payload samples**.

Built on formal **contravariant request** and **covariant response** variance rules so subtle mobile/mini-program crash vectors (`nullable: false -> true` on responses, widened response enums breaking exhaustive decoders, narrowed request enums, `int64 -> string` wire-type shifts, added required headers, and removed `2xx` status codes) are caught before merge.

## MCP Tools Exposed (`stdio`)

| Tool | Purpose | Safety Annotations |
| :--- | :--- | :--- |
| `diff_openapi_breaking_changes` | Audits OpenAPI `3.0`/`3.1` & Swagger `2.0` specs (JSON or YAML) using contravariant request and covariant response rules (`nullable`, `enum`, `required`, status/auth changes) and recommends SemVer bumps. | `readOnlyHint: true`, `destructiveHint: false`, `idempotentHint: true`, `openWorldHint: false` |
| `diff_json_payload_samples` | Infers normalized JSON schemas from raw Before/After API response or request/response JSON samples and detects breaking field removals, nullability shifts, and type mutations. | `readOnlyHint: true`, `destructiveHint: false`, `idempotentHint: true`, `openWorldHint: false` |
| `generate_api_release_changelog` | Produces customer-facing Markdown changelogs alongside RFC 8594 `Deprecation`/`Sunset` header snippets and BFF adapter migration checklists. | `readOnlyHint: true`, `destructiveHint: false`, `idempotentHint: true`, `openWorldHint: false` |
| `validate_contract_backward_compat` | Boolean CI gate checking candidate specs or payload samples against mobile/mini-program backward-compatibility thresholds and minimum compatibility scores. | `readOnlyHint: true`, `destructiveHint: false`, `idempotentHint: true`, `openWorldHint: false` |

## Quick Start (MCP Client & Local CLI)

```bash
# Start MCP server over stdio (supports both NDJSON and Content-Length framing)
npx -y github:z121245017-ai/apishield-mcp

# List MCP tool schemas from terminal
npx -y github:z121245017-ai/apishield-mcp --list

# Diff two OpenAPI files directly from CLI (exits 2 when breaking hazards are found)
npx -y github:z121245017-ai/apishield-mcp --base ./openapi-v1.yaml --head ./openapi-v2.yaml --strict

# Invoke any MCP tool directly via --cli
npx -y github:z121245017-ai/apishield-mcp --cli diff_json_payload_samples '{"beforeJson":"{\"orderId\":\"A1\",\"couponTitle\":\"VIP\"}","afterJson":"{\"orderId\":\"A1\",\"couponTitle\":null}"}'
```

### Claude Desktop / Cursor / Windsurf / Antigravity Config

```json
{
  "mcpServers": {
    "apishield": {
      "command": "npx",
      "args": ["-y", "github:z121245017-ai/apishield-mcp"]
    }
  }
}
```

### Docker (`node:22-alpine`, non-root `USER node`)

```bash
docker build -t apishield-mcp .
docker run -i --rm apishield-mcp
```

## GitHub Action (`z121245017-ai/apishield-mcp@v1`)

Block breaking OpenAPI `3.0`/`3.1` and Swagger `2.0` changes in pull requests with inline `::error` workflow annotations and Markdown step summaries:

```yaml
name: OpenAPI Backward-Compatibility Gate

on:
  pull_request:
    paths:
      - 'api/**'
      - '**/*openapi*.yaml'
      - '**/*openapi*.json'

permissions:
  contents: read

jobs:
  apishield-gate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Audit OpenAPI changes against origin/main
        uses: z121245017-ai/apishield-mcp@v1
        with:
          paths: 'api'
          baseline-ref: 'origin/main'
          strict-mobile-gate: 'true'
```

You can also compare two explicit files (`base-file` and `head-file`) in CI:

```yaml
      - name: Compare v1 and candidate OpenAPI contracts
        uses: z121245017-ai/apishield-mcp@v1
        with:
          base-file: 'contracts/v1/openapi.yaml'
          head-file: 'contracts/candidate/openapi.yaml'
          strict-mobile-gate: 'true'
```

## Contravariant Request vs Covariant Response Rules

| Contract Direction | Safe (MINOR / PATCH) | Breaking (`MAJOR` + `::error`) |
| :--- | :--- | :--- |
| **Request (`CONTRAVARIANT`)** | Add optional param/field, relax `required -> optional`, widen request `enum`, allow `nullable: true` | Add required header/query/body field without default, narrow request `enum`, disallow `null`, incompatible type change |
| **Response (`COVARIANT`)** | Add new field, promote `optional -> required`, narrow response `enum`, tighten `nullable: true -> false` | Remove field, demote `required -> optional`, flip `nullable: false -> true`, widen response `enum` (`HIGH`), remove `2xx` status |
| **Endpoint & Auth** | Add new route or optional auth alternative | Remove path/HTTP method, add mandatory auth to public route, drop existing auth scheme |

## Verification

```bash
npm test
```

## License

MIT License — `0` external npm dependencies, `0` network calls, `100%` local deterministic execution.

TDQS

A3.6/5.0

Scored across 4 tools

Disambiguation4/5

The two diff tools are clearly separated by input type (OpenAPI/Swagger specs vs raw JSON payload samples), and the changelog tool is a distinct output-generation operation. The main overlap is between diff_openapi_breaking_changes and validate_contract_backward_compat, which both assess compatibility of OpenAPI specs; descriptions distinguish a detailed variance report from a boolean threshold gate, but an agent could still pick the wrong one for a quick check.

Naming Consistency5/5

All four names follow a consistent snake_case verb_object pattern (diff_*, generate_*, validate_*) with the domain object embedded. Prefixes map predictably to operation type, making the set easy to scan and reason about.

Tool Count4/5

Four tools is a tight, purposeful surface for a narrow API-contract-compatibility domain, and each tool covers a distinct stage (spec diff, payload diff, changelog, CI gate). It is on the lean side with no tooling for baseline/version management, but nothing feels redundant.

Completeness4/5

The set covers the core lifecycle: detect breaking changes in specs and payloads, gate CI, and communicate via changelog with deprecation headers and migration checklists. Minor gaps exist around baseline/snapshot storage and retrieval of specs to diff against, which agents must supply themselves.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues