https://github.com/specmatic/specmatic-mcp-sample
This project demonstrates how to build a complete full-stack application from an OpenAPI specification using **Specmatic MCP** as intelligent guardrails
https://github.com/specmatic/specmatic-mcp-sample
Last synced: 6 months ago
JSON representation
This project demonstrates how to build a complete full-stack application from an OpenAPI specification using **Specmatic MCP** as intelligent guardrails
- Host: GitHub
- URL: https://github.com/specmatic/specmatic-mcp-sample
- Owner: specmatic
- Created: 2025-08-25T12:14:19.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2025-09-05T15:37:37.000Z (11 months ago)
- Last Synced: 2025-09-18T13:52:09.987Z (11 months ago)
- Homepage:
- Size: 55.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Specmatic MCP Sample Project
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
```bash
claude mcp add specmatic npx specmatic-mcp
claude
```
Then tell Claude: `"build the application"` (use plan mode first, then autoaccept)
And observe Claude build out the complete application!
## π¬ Video Demo
[](https://www.youtube.com/watch?v=UgxxDtE5h_s)
**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](https://www.npmjs.com/package/specmatic-mcp) - Easy NPM installation
- π³ **Docker Image**: [specmatic/specmatic-mcp](https://hub.docker.com/repository/docker/specmatic/specmatic-mcp) - Ready-to-use Docker image
- π **Source Code**: [specmatic/specmatic-mcp-server](https://github.com/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](#-tldr---get-started-in-30-seconds) 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](https://docs.anthropic.com/claude/docs/claude-code)
**Step 2:** **Add Specmatic MCP Server**:
**Option A: NPM Package (Recommended)**
```bash
cd specmatic-mcp-sample
claude mcp add specmatic npx specmatic-mcp
```
**Option B: Docker** (requires Docker Desktop running)
```bash
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](https://github.com/specmatic/specmatic-mcp-server/blob/main/README.md)
### π― Usage (2 Simple Commands)
**Step 3:** **Open this project in Claude Code**:
```bash
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
1. **OpenAPI Specification**: Defines the Products API with GET and POST endpoints for managing products
2. **Specmatic MCP Integration**:
- Provides contract testing capabilities
- Offers mock server functionality
- Validates implementations against the specification
- Runs resiliency tests for error scenarios
3. **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
1. Start with the OpenAPI specification
2. Use Specmatic MCP mock for frontend development
3. Implement backend according to the contract
4. Run Specmatic MCP tests to verify compliance
5. Both applications work together seamlessly
## π Learn More
- [Specmatic Documentation](https://specmatic.io/)
- [Claude Code Documentation](https://docs.anthropic.com/claude/docs/claude-code)
- [Model Context Protocol (MCP)](https://modelcontextprotocol.io/)
---
**Ready to see contract-driven development in action? Just ask Claude to build the application!**