OpenAPI Contract Guard MCP
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@OpenAPI Contract Guard MCPcompare specs/v1.yaml and specs/v2.yaml"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
OpenAPI Contract Guard MCP
一个可自建、只读的 OpenAPI 契约守卫 MCP。它让 AI 客户端能够校验 OpenAPI 文档、比较两个版本、识别破坏性变更,并生成结构化变更日志。
底层差异分析使用 oasdiff,MCP 服务基于 官方 Python SDK 实现。
能力
工具 | 作用 |
| 校验允许目录内的 OpenAPI 3.x 文档 |
| 输出两个契约版本的完整结构差异 |
| 定位可能破坏现有客户端的变更 |
| 生成按严重级别分类的 API 变更日志 |
Related MCP server: OpenAPI Specification Docs MCP Server
安全边界
全部工具只读,不修改接口文档。
本地文件只能来自
OPENAPI_GUARD_ALLOWED_ROOTS配置的目录。只接受本地文件,拒绝 URL 和其他 URI scheme。
校验和比较均拒绝外部
$ref,避免读取未授权文件或触发 SSRF。使用参数数组启动子进程,固定
shell=False,不拼接 shell 命令。单个契约文件上限为 20 MiB,单次标准输出和错误输出各上限约 1 MB。
环境要求
下载并解压 oasdiff 后,将可执行文件加入 PATH,或通过
OASDIFF_BIN 指定绝对路径。
本地运行
git clone https://github.com/xiaohuxi/openapi-contract-guard-mcp.git
cd openapi-contract-guard-mcp
uv sync
uv run openapi-contract-guard-mcp默认使用 MCP stdio transport,适合 Codex、Claude Code、Cursor 等本地 AI 客户端。
MCP 配置
{
"mcpServers": {
"openapi-contract-guard": {
"command": "uvx",
"args": [
"--from",
"git+https://github.com/xiaohuxi/openapi-contract-guard-mcp.git",
"openapi-contract-guard-mcp"
],
"env": {
"OPENAPI_GUARD_ALLOWED_ROOTS": "/absolute/path/to/your/api-project",
"OASDIFF_BIN": "/absolute/path/to/oasdiff"
}
}
}
}Windows 可用分号配置多个允许目录,Linux 和 macOS 使用冒号:
OPENAPI_GUARD_ALLOWED_ROOTS=D:\project-a;D:\project-b未配置时,允许目录默认为 MCP 进程的当前工作目录。
使用示例
可以直接向 AI 客户端提出:
“校验
openapi.yaml是否符合 OpenAPI 规范。”“比较
specs/v1.yaml和specs/v2.yaml,列出全部差异。”“检查新版本是否包含破坏性变更,并解释影响。”
“根据两个契约版本生成发布变更日志。”
仓库内的 examples/base.yaml 和 examples/revision.yaml 可用于快速验证。
开发与测试
uv sync --group dev
uv run pytest自动化测试覆盖本地路径边界、URL scheme、外部 $ref、OpenAPI 3.x
校验、三个差异工具、无 shell 子进程调用和 MCP 工具注册。真实联调示例
能够识别删除 GET /users 为破坏性变更。
配置项
环境变量 | 默认值 | 说明 |
| 当前工作目录 | 允许读取的本地根目录列表 |
|
|
|
License
Available Tools
4 toolscompare_specsC
Compare two OpenAPI documents and return the complete structural diff.
| Name | Required | Description | Default |
|---|---|---|---|
| base | Yes | ||
| revision | Yes | ||
| output_format | No | text |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
generate_changelogC
Generate a categorized changelog between two OpenAPI documents.
| Name | Required | Description | Default |
|---|---|---|---|
| base | Yes | ||
| revision | Yes | ||
| output_format | No | text |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
list_breaking_changesC
List changes in the revision that may break existing API clients.
| Name | Required | Description | Default |
|---|---|---|---|
| base | Yes | ||
| revision | Yes | ||
| output_format | No | text |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
validate_specA
Validate a local OpenAPI 3.x file without resolving external references.
| Name | Required | Description | Default |
|---|---|---|---|
| source | Yes |
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
4 tool updates
v0.1.0- First observed
compare_specs - First observed
generate_changelog - First observed
list_breaking_changes - First observed
validate_spec
TDQS
Scored across 4 tools
Each tool has a distinct purpose: validation, comparison, breaking changes, and changelog generation. No overlapping functionality.
All tool names follow the verb_noun pattern (validate_spec, compare_specs, list_breaking_changes, generate_changelog) with consistent snake_case.
Four tools is appropriate for the focused domain of OpenAPI specification analysis, covering key workflows without unnecessary clutter.
The set covers validation, comparison, breaking changes, and changelog generation, but missing features like linting or reference resolution validation.
Maintenance
Related MCP Connectors
Detect breaking changes, generate changelogs, diff, and validate OpenAPI specs.
Schema-aware API monitoring: diff OpenAPI specs for breaking changes, manage endpoints.
Deterministic validation for AI-generated artifacts: JSON Schema, OpenAPI response, SQL syntax.
Monitor MCP servers, API contracts and AI outputs for schema drift. Alerts on breaking changes.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to browse, read, compare, and validate OpenAPI contracts for providers and consumers.1MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to interact with OpenAPI documents for analysis, validation, and management through structured interfaces.530 npm3ISC
- AlicenseBqualityBmaintenanceLocal OpenAPI contract checks and breaking-change detection between spec versions for AI coding agents.281 npmMIT
- AlicenseAqualityFmaintenanceEnables coding agents to validate OpenAPI documents and JSON Schemas, validate data against a schema, and diff OpenAPI versions—including against a git ref—to classify breaking changes and suggest semver updates.3MIT