Spec Guard
A methodology and MCP server for agent-driven software development where humans write specs and agents implement code, enforced by six mechanical gates to ensure spec validity, contracts, tests, and review.
README
Spec Guard
Spec-first. Behavior-tested. Agent-safe.
Spec Guard is a methodology, workflow runner, and MCP server for agent-driven software development. The model is simple: humans write specs, agents write all code. Six mechanical gates enforce the boundary between human intent and agent execution.
Specs guide implementation, but tests validate running behavior and durable contracts — not prose.
The human's interface is a conversation. Describe what you want, answer a few questions, approve the spec. The agent handles gates, contracts, tests, and code. There are no files to fill out, no commands to learn, no dashboard to check — just a description of what you need and a chat window to deliver it in.
Three layers, one system
| Layer | What it is | Who uses it |
|---|---|---|
WORKFLOW.md + AGENTS.md |
Process flow document + compact agent instructions | Agents that load project files as context, or humans reviewing the process |
spec-guard run |
Interactive CLI that walks a spec through all 6 gates | Agents executing CLI commands |
| MCP server | Structured tool calls for all Spec Guard operations | MCP-compatible agents (Claude Code, Cursor, etc.) |
Each layer enforces the same 6 gates. Pick the one that fits your agent's capabilities — or use all three.
The 6 Gates
DISCOVER → [Gate 1] → CLASSIFY & CONTRACT → [Gate 2] → IMPLEMENTATION PLANNING → [Gate 3] → TEST FIRST → [Gate 4] → IMPLEMENT → [Gate 5] → REVIEW → [Gate 6]
| Gate | Check | How it's confirmed |
|---|---|---|
| 1 | Spec valid (required headings, content, classification) | spec-guard check — must exit 0 |
| 2 | Contracts present (API/UI inputs exist and are referenced) | spec-guard check --warnings |
| 3 | Implementation planning confirmed (required stack/layer decisions are recorded) | Agent suggests a context-appropriate stack/layer, human accepts or overrides it, then agent calls spec_guard_confirm_gate |
| 4 | Failure-first confirmed (test runs and fails for expected reason) | Agent runs tests, records failure, calls spec_guard_confirm_gate with evidence |
| 5 | Tests pass (no scope silently absorbed) | Agent runs tests until passing, calls spec_guard_confirm_gate |
| 6 | Review complete + cross-artifact analysis clean | spec-guard review then spec-guard analyze |
Quick start
npm install --save-dev @jpstone/spec-guard
# Initialize project
npx spec-guard init
# Author a spec (guided wizard)
npx spec-guard draft my-feature
# Orchestrated workflow (recommended)
npx spec-guard run my-feature
# Just validate
npx spec-guard check my-feature
# See all specs
npx spec-guard status
# Browse all .md artifacts locally (no GitHub push needed)
npx spec-guard serve
See the CLI Reference for all commands and flags.
Local markdown viewer
spec-guard serve starts a local HTTP server that renders all .md files in your repo as styled HTML. Navigate spec artifacts, contracts, and reviews in the browser with live reload — no GitHub push required.
npx spec-guard serve # opens http://localhost:7777
npx spec-guard serve --port 8080
The root page is your README.md (or .spec-guard/README.md as fallback). A sidebar lists every .md file in the repo. Edits to any .md file reload the browser automatically.
Wiring an agent to Spec Guard
Agents don't inherently know the Spec Guard workflow. Without it, they'll implement normally — no gates, no classification, no halt conditions. There are three ways to give an agent the operating contract:
MCP server (preferred) — Connect the MCP server and the agent receives structured guidance at each step via tool calls. No upfront loading required. spec_guard_workflow_next_step always tells the agent what to do next. Works with any MCP-compatible agent (Claude Code, Cursor, Copilot, etc.).
Project file context — spec-guard init puts AGENTS.md in the project root. Agents that automatically ingest project-level instruction files (Claude Code's CLAUDE.md pattern, Cursor rules, etc.) will pick it up without any manual step. Point the agent at the project and it reads the contract on its own.
Manual paste — For agents without MCP support or automatic file ingestion, paste the contents of AGENTS.md at the start of a session. The agent then operates under the full Spec Guard contract for that session.
WORKFLOW.md has the full phase-by-phase process flow. AGENTS.md is the compact operating contract an agent needs to execute it.
MCP Server
Exposes all Spec Guard operations as structured tools for MCP-compatible agents.
{
"mcpServers": {
"spec-guard": {
"command": "node",
"args": ["/path/to/spec-guard/mcp/server.js"]
}
}
}
Available tools
| Tool | What it does |
|---|---|
spec_guard_analyze |
Cross-artifact consistency check (spec ↔ contract ↔ review) |
spec_guard_check |
Validate a spec; returns diagnostics |
spec_guard_classify |
Get classification + test guidance |
spec_guard_confirm_gate |
Record gate 3/4/5/6 confirmation, with evidence required for Gate 4 |
spec_guard_create_artifact |
Create any artifact from a template |
spec_guard_draft_spec |
Turn interview answers into a valid spec (passes Gate 1) |
spec_guard_gate_status |
Status of all 6 gates for a spec |
spec_guard_initiative_questions |
Get question list for decomposing a broad app into feature slices |
spec_guard_interview_questions |
Get structured question list for AI-assisted spec authoring |
spec_guard_save_initiative |
Save initiative decomposition artifact; returns slice names for drafting |
spec_guard_status |
Overview of all specs |
spec_guard_suggest |
Check + return each diagnostic with a concrete fix instruction |
spec_guard_test_guidance |
Get test type and Gate 2 checklist for a classification |
spec_guard_validate_directory |
Check all specs in a directory |
spec_guard_workflow_next_step |
Given gates passed → what to do next |
spec_guard_workflow_next_step is the key tool for agents: call it after each action and it returns a structured next_action + instruction so the agent always knows what step comes next without reading docs.
See the MCP Setup guide for configuration and the MCP Tool Reference for full tool inputs, outputs, and examples.
What init creates
.spec-guard/
specs/
contracts/
blockers/
scope-discoveries/
reviews/
deviations/
discoveries/
runs/
AGENTS.md
WORKFLOW.md
.github/
workflows/
spec-guard.yml
What agents must never do
- Implement before Gates 1, 2, 3, and 4 pass — the spec must be valid, contracts must be present, required implementation planning must be confirmed, and a failing test must exist before any implementation begins
- Skip work classification
- Create documentation by default
- Test whether documentation files (specs, contracts, reviews, READMEs, help files, changelogs) exist or contain expected content, unless the document is explicitly the deliverable of an operational/document deliverable classification
- Invent UI — do not implement UI work until both a mockup/design direction and a component library reference are in the spec, or the human has explicitly confirmed each is not needed
- Assume a component library — if none is referenced, ask the human before proceeding
- Test private/undocumented internals instead of contract surfaces
- Silently absorb out-of-scope work
- Add unrequested features, optional enhancements, or opportunistic refactors
- Upgrade dependencies or change architecture unless the spec requires it
- Redesign UI beyond provided direction
- Implement nearby TODOs unless the spec requires them
- Propose unsolicited feature roadmaps after completing a task
- Treat "what's next?" as permission to invent features
- Perform discovery unless the human explicitly asks
- Implement discovery findings without separate authorization
- Skip Gate 4 (failure-first) without recording a concrete reason
- Close Gate 6 without running
spec-guard analyze
Examples
End-to-end walkthroughs showing Spec Guard in use with natural-language requests.
| Example | What it covers |
|---|---|
| Todo App | Building a new app with initiative decomposition, then adding a single feature with the standard spec flow |
Documentation
| Doc | What it covers |
|---|---|
| CLI Reference | All commands, flags, exit codes, diagnostic format |
| Glossary | Term definitions |
| MCP Setup | MCP server configuration for Claude Code, Cursor, and Windsurf |
| MCP Tool Reference | All MCP tools — inputs, outputs, and examples |
| Philosophy | Design philosophy, innovations, and problems Spec Guard solves |
| Quality Gates | Gate-by-gate breakdown and pass conditions |
| Quickstart | Minimum workflow, live validation, CI setup |
| Validation Rules | Every rule ID with severity and description |
| Work Classification | How to choose the right classification |
Development
npm test # 231 tests across check, run, MCP, CLI, discover, analyze, suggest, initiative, and implementation planning
npm run check:example # gate 1 smoke check
npm run run:example # gate 1+2 non-interactive check
License
MIT.
Spec Guard
This project uses Spec Guard
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。