Specmatic MCP Sample Project
March 18, 2026 Β· View on GitHub
This project demonstrates how to build a complete full-stack application from an OpenAPI specification using Specmatic MCP as intelligent guardrails, without requiring Specmatic as a project dependency.
π TL;DR - Get Started Quickly
claude mcp add specmatic npx specmatic-mcp
claude
Then tell Claude: "build the application" (use plan mode first, then auto accept)
And observe Claude build out the complete application!
π¬ Video Demo
This is the exact repository used in the demo above - try it yourself and see contract-driven development in action!
π¦ Specmatic MCP Resources
- π¦ NPM Package: specmatic-mcp - Easy NPM installation
- π³ Docker Image: specmatic/specmatic-mcp - Ready-to-use Docker image
- π Source Code: specmatic/specmatic-mcp-server - GitHub repository
Note: This project uses Claude Code for demo purposes, however you can use any coding agent of your choice and make necessary changes accordingly.
π― What This Demo Shows
Starting with just an OpenAPI specification (products_api.yaml), this project shows how you can:
- Build a complete Node.js/Express backend API using Specmatic MCP Contract and Resiliency Test as guard rails
- Create a React frontend application using Specmatic MCP Mock to isolate and build the Frontend independently
- Ensure frontend and backend stay in sync with the API specification in the process
π Quick Start
β‘ Just One Prompt - No Contract Drift!
For the absolute fastest start, see the TL;DR section above. For detailed setup with alternatives, follow the steps below.
β Prerequisites (Required)
Step 1: Install Claude Code (if not already installed):
Follow installation instructions at https://docs.anthropic.com/claude/docs/claude-code
Step 2: Add Specmatic MCP Server:
Option A: NPM Package (Recommended)
cd specmatic-mcp-sample
claude mcp add specmatic npx specmatic-mcp
Option B: Docker (requires Docker Desktop running)
cd specmatic-mcp-sample
claude mcp add-json specmatic '{"command":"docker","args":["run","--rm","-i","--network=host","-v","'$(pwd)':/app/reports","specmatic/specmatic-mcp:latest"],"env":{}}'
π For detailed installation options and troubleshooting, see the Specmatic MCP Server documentation
π― Usage (2 Simple Commands)
Step 3: Open this project in Claude Code:
claude
Step 4: Ask Claude to build the application:
Please build the complete application according to the OpenAPI specification
TIP: use plan mode to review the task list before proceeding
π Optional Reset
Reset the project to try again (optional - Claude Code command available):
/reset-sample-project
π That's it! Claude will automatically:
- β¨ Build complete Node.js/Express backend API
- β¨ Create React frontend application
- β¨ Validate implementations against the OpenAPI contract
- β¨ Provide mock servers for development
- β¨ Run contract and resiliency tests
- β¨ Ensure all components comply with the specification
π Project Structure
specmatic-mcp-sample/
βββ products_api.yaml # OpenAPI specification (the single source of truth)
βββ backend/ # Node.js/Express API implementation
β βββ CLAUDE.md # Backend development instructions
β βββ ...
βββ frontend/ # React frontend application
β βββ CLAUDE.md # Frontend development instructions
β βββ ...
βββ CLAUDE.md # Main project instructions
βββ README.md # This file
π― Key Benefits Demonstrated
Contract-First Development
- The OpenAPI specification serves as the single source of truth
- Both frontend and backend are built to conform to this contract
- Changes to the API require updating the specification first
Independent Development
- Frontend can be developed using Specmatic's mock server
- Backend can be developed and tested against the contract
- No need to coordinate development schedules
Automatic Validation
- Specmatic MCP automatically validates backend implementations
- Contract tests ensure API compliance
- Resiliency tests verify error handling
Zero Dependencies
- Specmatic runs as an MCP server through Docker
- No need to add Specmatic dependencies to your project
- Clean project structure with minimal tooling overhead
π§ How It Works
-
OpenAPI Specification: Defines the Products API with GET and POST endpoints for managing products
-
Specmatic MCP Integration:
- Provides contract testing capabilities
- Offers mock server functionality
- Validates implementations against the specification
- Runs resiliency tests for error scenarios
-
Claude Code Integration:
- Uses Specmatic MCP to guide development
- Automatically runs appropriate tests
- Ensures contract compliance throughout development
ποΈ Architecture Diagrams
Production Setup
βββββββββββββββββββ βββββββββββββββββββ
β β ββββββ HTTP Requests βββββββββββΊ β β
β Frontend β β Backend β
β (React App) β βββββββββββββββββββ β (Express API) β
β β βproducts_api.yamlβ β β
β Port: 4000 β β (OpenAPI Spec) β β Port: 3000 β
β β βββββββββββββββββββ β β
| | | |
β β βββββββ HTTP Responses βββββββββ β β
βββββββββββββββββββ βββββββββββββββββββ
Development Setup - Frontend
βββββββββββββββββββ βββββββββββββββββββ
β β β β
β Frontend β Mock Requests β Specmatic Mock β
β (React App) β βββββββββββββββββββΊ β Server β
β β β β
β Port: 4000 β β Port: 9001 β
βββββββββββββββββββ βββββββββββ¬ββββββββ
β
β Based on
β
βΌ
βββββββββββββββββββββββ
β β
β products_api.yaml β
β (OpenAPI Spec) β
β β
βββββββββββββββββββββββ
Development Setup - Backend
βββββββββββββββββββ βββββββββββββββββββ
β β β β
β Specmatic MCP β ββββΊ Contract ββββΊ β Backend β
β Tools β Testing β (Express API) β
β β β β
β (via Docker) β ββββΊ Resiliency ββββΊ β Port: 3000 β
βββββββββββ¬ββββββββ Testing βββββββββββββββββββ
β
β Validates against
β
βΌ
βββββββββββββββββββββββ
β β
β products_api.yaml β
β (OpenAPI Spec) β
β β
βββββββββββββββββββββββ
π¨ The Products API
The sample API includes:
- GET /products: Retrieve products filtered by type (book, food, gadget, other)
- POST /products: Create new products with validation
See products_api.yaml for the complete specification with examples and validation rules.
ποΈ Development Workflow
- Start with the OpenAPI specification
- Use Specmatic MCP mock for frontend development
- Implement backend according to the contract
- Run Specmatic MCP tests to verify compliance
- Both applications work together seamlessly
π Learn More
Ready to see contract-driven development in action? Just ask Claude to build the application!
