Specmatic MCP Server
Exposes Specmatic's API contract testing, resiliency testing, and mocking capabilities to AI coding agents via natural language, enabling automated validation and simulation of API behaviors.
README
Specmatic MCP Server
A Model Context Protocol (MCP) server that exposes Specmatic's capabilities—including API Contract Testing, API Resiliency Testing, and API mocking—to AI coding agents.
What You Can Do
Interact with your AI coding agent using natural language to:
"Run contract tests against my API at https://api.example.com using this OpenAPI spec: [paste spec]"
"Start a mock server on port 9000 using this spec: [paste spec]"
"Run resiliency tests to check error handling with @products-api.yaml spec"
"Check for breaking changes in my API spec at /path/to/openapi.yaml compared to main branch"
"List all running mock servers"
"Stop the mock server on port 9000"
Available Tools
run_contract_test
Validates API implementations against OpenAPI specifications by running contract tests.
- Input: OpenAPI spec, API base URL, spec format (yaml/json)
- Output: Test results with pass/fail status and detailed failure information
- Use case: Ensure your API implementation matches the contract specification
run_resiliency_test
Tests API resilience by sending boundary condition and invalid requests.
- Input: OpenAPI spec, API base URL, spec format (yaml/json)
- Output: Enhanced testing results including edge case validation
- Use case: Verify proper error handling and API robustness
manage_mock_server
Complete mock server lifecycle management for frontend development.
- Subcommands:
start,stop,list - Features: Port management, multiple concurrent servers, automatic cleanup
- Use case: Generate mock APIs from OpenAPI specs for frontend development
backward_compatibility_check (npm package only)
Checks for breaking changes in OpenAPI specifications using git comparison.
- Input: OpenAPI spec file path, git branch comparison, repository directory
- Output: Backward compatibility analysis with breaking change detection
- Use case: Validate API changes don't break existing clients before deployment
- Prerequisite: Requires git version control - Specmatic compares current spec with previous version to identify changes
- Availability: Only available when using the npm package (not available in Docker due to git repository access requirements)
Prerequisites
- MCP-compatible coding environment (Claude Code, VSCode with MCP extension, Cursor, GitHub Copilot, etc.)
For npm package (recommended):
- Node.js stable (
nvm use stable) - Java Runtime Environment (JRE)
- Git (required for backward compatibility checking)
For Docker:
- Docker installed and running
Setup
npm Package (Recommended)
Claude Code
claude mcp add specmatic npx specmatic-mcp
VSCode
- Install the package globally (optional, for easier access):
npm install -g specmatic-mcp - Open your project in VS Code as a workspace
- Open Command Palette (
Ctrl+Shift+P/Cmd+Shift+P) →MCP: Add server - Choose transport protocol:
stdio - Enter command:
npx specmatic-mcp - Set server ID:
specmatic - Choose scope: Global or Workspace
Other MCP Clients
Add to your mcp.json configuration:
{
"servers": {
"specmatic": {
"command": "npx",
"args": ["specmatic-mcp"],
"env": {}
}
}
}
Docker Alternative
Claude Code
claude mcp add-json specmatic '{"command":"docker","args":["run","--rm","-i","--network=host","-v","'$(pwd)/reports':/app/reports","specmatic/specmatic-mcp:latest"],"env":{}}'
Note: If you encounter path resolution issues with $(pwd), replace it with your absolute project path:
claude mcp add-json specmatic '{"command":"docker","args":["run","--rm","-i","--network=host","-v","/path/to/your/project/reports:/app/reports","specmatic/specmatic-mcp:latest"],"env":{}}'
VSCode
-
Make sure Docker Desktop is running
-
Open your project in VS Code as a workspace (single-folder or multi-root as needed).
-
Open the Command Palette (
Ctrl+Shift+P/Cmd+Shift+P) and search forMCP: Add server, then press Enter -
Choose transport protocol as
stdio -
⚠️ CRITICAL: Enter the command to run the MCP server - YOU MUST REPLACE
<REPLACE_WITH_YOUR_PROJECT_PATH>with your actual project path:Template:
docker run --rm -i --network=host -v <REPLACE_WITH_YOUR_PROJECT_PATH>/reports:/app/reports specmatic/specmatic-mcp:latestExamples:
# macOS/Linux example: docker run --rm -i --network=host -v /Users/yourname/projects/my-api-project/reports:/app/reports specmatic/specmatic-mcp:latest # Windows example: docker run --rm -i --network=host -v C:\Users\yourname\projects\my-api-project\reports:/app/reports specmatic/specmatic-mcp:latest -
Set the server ID to
specmatic-mcp. -
Choose installation scope:
Global(available everywhere) orWorkspace(just this project). -
Verify the server: Make sure that Specmatic MCP is listed without errors in the MCP servers panel and then request your Copilot Agent to run contract tests, resiliency tests, or start a mock server in natural language.
Other MCP Clients (Docker)
For Cursor, GitHub Copilot, or other MCP clients, add to your mcp.json configuration:
⚠️ IMPORTANT: Replace <REPLACE_WITH_YOUR_PROJECT_PATH> with your actual project path.
{
"servers": {
"specmatic": {
"command": "docker",
"args": [
"run",
"--rm",
"-i",
"--network=host",
"-v",
"<REPLACE_WITH_YOUR_PROJECT_PATH>/reports:/app/reports",
"specmatic/specmatic-mcp:latest"
],
"env": {}
}
}
}
Path Examples:
- macOS/Linux:
/Users/yourname/projects/my-api-project/reports:/app/reports - Windows:
C:\Users\yourname\projects\my-api-project\reports:/app/reports
Important: Host Network Mode
The --network=host flag is required for:
- Testing localhost APIs: Allows the container to access APIs running on your host machine (e.g.,
http://localhost:3000) - Mock server access: Enables mock servers to be accessible from your host system for frontend development
- Port binding: Ensures mock servers on specific ports are reachable from outside the container
Security Note: Host networking gives the container access to your host's network interfaces. Only use this with trusted images.
Choosing the Right Method
Use npm package (recommended) for easier setup and faster performance.
Use Docker if you prefer not to install Node.js and Java locally on your system.
Tool Availability by Environment
npm Package:
- ✅ Contract Testing (
run_contract_test) - ✅ Resiliency Testing (
run_resiliency_test) - ✅ Mock Server Management (
manage_mock_server) - ✅ Backward Compatibility Check (
backward_compatibility_check)
Docker:
- ✅ Contract Testing (
run_contract_test) - ✅ Resiliency Testing (
run_resiliency_test) - ✅ Mock Server Management (
manage_mock_server) - ❌ Backward Compatibility Check (requires direct git repository access)
Reports and Output
npm Package:
- JUnit XML reports generated in
./reports/directory (relative to where you run the command) - Direct filesystem access for easy report analysis
- Reports persist after command completion
Docker:
- JUnit XML reports generated in volume-mounted
./reports/directory on host - Requires volume mounting:
-v "$(pwd)/reports:/app/reports" - Reports accessible on host filesystem
Both methods provide:
- Console output with immediate feedback and summaries
- Detailed test results and timing information in JUnit XML format
- Structured error reporting and stack traces
Usage Examples
Simply interact with your AI coding agent using natural language. The agent will call the appropriate MCP tools based on your requests. All detailed examples and output formats are available in the project's AGENTS.md file for reference. CLAUDE.md is kept as a thin wrapper for Claude Code compatibility.
🚀 Try the Complete Example
Explore a full-stack application built with Specmatic MCP as guard rails:
https://github.com/specmatic/specmatic-mcp-sample
This sample project demonstrates how to build an entire frontend and backend application using Specmatic MCP for contract testing, API mocking, and resiliency validation.
Support
For issues, questions, or feature requests, please open an issue on GitHub.
License
This project is licensed under the MIT License - see the LICENSE.md file for details.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。