Skip to main content
Glama

docguard

npm version License: MIT

API documentation drift detector MCP server. Find where your docs lie — before your users do.

Problem

API docs drift from code constantly. A developer adds a route, forgets to update the OpenAPI spec. Another removes an endpoint but the docs still list it. Parameters change, status codes change — the spec becomes fiction.

docguard compares your OpenAPI spec against actual code routes and reports exactly what's out of sync. No live traffic needed, no LLM calls — pure static analysis.

Related MCP server: MCP-QA

Quick Start

As MCP Server

Works with any MCP-compatible client — Claude Code, Claude Desktop, Cursor, Windsurf, VS Code (Copilot), Continue.dev, Zed, Cline, and more.

{
  "mcpServers": {
    "docguard": {
      "command": "npx",
      "args": ["-y", "@mrzadexinho/docguard"]
    }
  }
}

As Library

import { parseSpec, extractRoutes, compareDrift, formatDriftReport } from '@mrzadexinho/docguard';
import { readFileSync } from 'fs';

// Parse your OpenAPI spec
const spec = parseSpec(readFileSync('openapi.yaml', 'utf-8'));

// Extract routes from code
const code = extractRoutes(readFileSync('src/routes.ts', 'utf-8'), 'src/routes.ts');

// Compare and report drift
const drift = compareDrift(spec.routes, code.routes);
console.log(formatDriftReport(drift));

MCP Tools

Tool

Description

check_drift

Compare OpenAPI spec against code routes. Reports undocumented routes, stale docs, and parameter mismatches

extract_routes

Scan a code file and extract API routes with methods, paths, and parameters

validate_spec

Validate OpenAPI spec for structure and completeness (missing operationIds, summaries, responses)

What It Detects

Drift Type

Severity

Description

Undocumented route

Error

Route exists in code but path is completely missing from spec

Undocumented method

Warning

Path exists in spec but this HTTP method isn't documented

Stale documentation

Error

Endpoint in spec but no matching route in code

Stale method

Warning

Path exists in code but this HTTP method was removed

Parameter mismatch

Warning

Path params differ between spec and code

Framework Support

Auto-detects and extracts routes from:

Framework

Patterns detected

Express

app.get(), router.post(), app.use('/prefix', router)

FastAPI

@app.get(), @router.post(), APIRouter(prefix=...)

Hono

app.get(), app.post(), .basePath()

Spec Support

  • OpenAPI 3.x (YAML and JSON)

  • Swagger 2.0 (JSON)

  • Path parameter extraction ({id} normalized to :id)

  • Base path from servers[0].url or basePath

Example Output

# API Documentation Drift Report

**8 spec routes, 10 code routes, 4 drift issue(s):**
- 2 route(s) in code but missing from spec
- 1 route(s) in spec but missing from code (stale docs)
- 1 parameter mismatch(es)

## Undocumented Routes (in code, not in spec)

[ERROR] GET /health exists in code but is completely missing from spec
  Code: src/routes.ts:12

[ERROR] POST /webhooks exists in code but is completely missing from spec
  Code: src/routes.ts:45

## Stale Documentation (in spec, not in code)

[ERROR] DELETE /users/:id documented in spec but not found in code (stale docs)
  Spec: operationId: deleteUser

## Parameter Mismatches

[WARNING] Path parameter mismatch on GET /users/:id
  Spec params: id
  Code params: userId

Architecture

docguard/
  src/
    spec/            # OpenAPI spec parsing
      types          # SpecRoute, SpecParam, SpecResponse
      parser         # Parse OpenAPI 3.x / Swagger 2.0
    routes/          # Code route extraction
      types          # CodeRoute, FrameworkType
      express        # Express route extractor
      fastapi        # FastAPI route extractor
      hono           # Hono route extractor
      detector       # Auto-detect framework, multi-file extraction
    drift/           # Drift detection engine
      types          # DriftFinding, DriftType, DriftSeverity
      comparator     # Compare spec vs code routes
      reporter       # Format drift report (markdown)
    mcp/             # MCP server layer
      tools/         # 3 MCP tools
  tests/             # 77 tests mirroring src/ structure

Prerequisites

  • Node.js >= 20.0.0

  • An OpenAPI spec file (YAML or JSON)

Development

git clone https://github.com/mrzadexinho/docguard.git
cd docguard
npm install
npm run build
npm test

License

MIT

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      A
      quality
      Not graded
      maintenance
      Static analysis engine that detects schema mismatches between data producers (like MCP servers) and consumers (like client code), preventing runtime errors by validating contracts at development time.
      11
      -
    • F
      license
      Not graded
      quality
      D
      maintenance
      An MCP server for the comprehensive analysis of Swagger 2.0 and OpenAPI 3.x contracts. It allows users to extract detailed information about endpoints, request/response schemas, parameters, and security configurations from API documentation.
      -
    • A
      license
      A
      quality
      D
      maintenance
      Parses Swagger 2.0 and OpenAPI 3.x specifications, exposing API endpoints, schemas, and authentication through MCP tools with local caching to reduce token usage.
      11
      15 npm
      1
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Cross-stack MCP server that scans frontend and backend code together, detects mismatches like phantom calls, dead endpoints, and field drift, and provides a full-stack health audit.
      1
      MIT