The context AI agents share - A deterministic MCP server that coordinates multiple AI agents across software development lifecycles.
Foundation + Validation + Traceability - Core MCP server with validation gates and graph traversal.
- β Zod Schema Validation - All 7 document types with draft/active variants (550 LOC)
- β
ReadyForDevelopment Gate - 3-condition quality gate for Features (340 LOC)
- G-MIN-AC: β₯1 acceptance criterion defined
- G-LINKED-GOAL: Supports relation to Goal exists
- G-MIN-WORKITEMS: β₯1 WorkItem implements Feature
- β Coverage Metrics - AC coverage calculation (acTotal, acLinkedWorkItems, acCoveragePercent) (330 LOC)
- β
docs/validate Tool - Comprehensive validation orchestrator (390 LOC)
- Schema validation (Zod)
- Cross-document validation
- Quality gate evaluation
- Coverage metrics
- Traceability info
- β
Recursive CTE Queries - Bidirectional graph traversal with <200ms p95 latency (360 LOC)
- Forward traversal (Goal β Feature β WorkItem)
- Reverse traversal (WorkItem β Feature β Goal)
- Cycle detection with maxDepth safety (hard limit: 20)
- Relation kind filtering
- β
trace/paths Tool - Path finding and impact analysis (410 LOC)
- Find all paths between documents
- Shortest path calculation
- Impact analysis (upstream/downstream dependencies)
- Orphan detection (unlinked Features/WorkItems)
- β docs/validate - Full document validation via MCP
- β trace/paths - Graph traversal via MCP
- β Performance Monitoring - Automatic logging for slow queries (>100ms)
- β Index Verification - Startup verification of required indexes
- β documents table with 7 document types (Goal, Feature, WorkItem, StatusUpdate, DecisionRecord, LessonLearned, Agent)
- β relations table with 14 typed edges (supports, implements, updates, evidence_for, depends_on, related_to, influences, supersedes, learned_from, applies_to, review_requested, review_approved, review_rejected, review_conditional)
- β Relation metadata support for review workflows
- β Foreign key constraints with CASCADE DELETE
- β JSON1 extension for content storage
- β Optimized indexes for query performance
- β Status-graded validation support (draft, ready, active, archived)
- β Type constraints: Goal, Feature, WorkItem, StatusUpdate, DecisionRecord, LessonLearned, Agent (7 types)
- β Status constraints: draft, ready, active, archived
- β Relation kind constraints: 14 v1.2.0 relation types
- β Relation metadata with JSON validation
- β Self-loop prevention (document cannot link to itself)
- β Duplicate relation prevention (UNIQUE constraint)
- β JSON validity checks on content fields
- β 4 indexes on documents table (project_type, status, updated, type_status)
- β 3 indexes on relations table (from, to, project)
- β WAL mode for better concurrency
- β 64MB cache size for optimal performance
# Install dependencies
npm install
# Build TypeScript
npm run build
# Initialize and seed database
npm run db:reset
# Run tests
npm test
# Verify database integrity
npx tsx src/db/verify.tsAfter seeding with contexthub.json (v1.2.0):
- 42 documents (1 Goal, 8 Features, 25 WorkItems, 4 Agents, 2 DecisionRecords, 2 LessonLearned)
- 44 relations (8 supports, 25 implements, 4 influences, 2 learned_from, 3 applies_to, 2 review workflow)
- 100% test coverage (29/29 tests passing)
- All constraints validated β
contexthub/
βββ src/
β βββ db/
β β βββ schema.sql # SQLite schema definition
β β βββ connection.ts # Database connection & setup
β β βββ seed.ts # Load contexthub.json data
β β βββ verify.ts # Database verification tool
β β βββ verify-indexes.ts # Index verification (NEW)
β β βββ operations.ts # CRUD operations
β β βββ patch.ts # JSON Patch (RFC 6902)
β β βββ relations.ts # Relation CRUD
β β βββ etag.ts # ETag generation
β βββ validation/ # NEW: Validation layer
β β βββ schemas.ts # Zod schemas (draft/active)
β β βββ gates.ts # Quality gates
β β βββ coverage.ts # Coverage metrics
β β βββ orchestrator.ts # docs/validate implementation
β βββ traceability/ # NEW: Traceability layer
β β βββ queries.ts # Recursive CTE queries
β β βββ paths.ts # trace/paths implementation
β βββ mcp/
β β βββ tools.ts # MCP tool handlers
β β βββ prompts.ts # MCP prompts
β β βββ resources.ts # MCP resources
β βββ index.ts # MCP server entry point
β βββ types.ts # TypeScript interfaces
βββ tests/
β βββ unit/ # NEW: Unit tests
β β βββ validation-schemas.test.ts
β β βββ validation-gates.test.ts
β β βββ validation-coverage.test.ts
β β βββ traceability-queries.test.ts
β βββ integration/
β βββ schema.test.ts
β βββ etag.test.ts
β βββ patch.test.ts
β βββ relations.test.ts
β βββ mcp-server.test.ts
β βββ validation-traceability.test.ts # NEW
βββ contexthub.json # Project specification
βββ package.json
Comprehensive test suite with 100+ tests across unit and integration layers:
- β Document type enforcement (all 7 v1.2.0 types)
- β Status constraint enforcement (draft, ready, active, archived)
- β JSON validity on content fields
- β Relation kind enforcement (all 14 v1.2.0 types)
- β Self-loop prevention, duplicate prevention
- β CASCADE DELETE on document removal
- β Index verification
- β Zod schema validation (all 7 document types)
- β Draft vs Active schema variants
- β Quality gates (ReadyForDevelopment)
- β Coverage metrics calculation
- β Cross-document validation
- β Edge cases (empty ACs, missing refs, etc.)
- β Recursive CTE traversal (forward/reverse/both)
- β maxDepth enforcement (DoS prevention)
- β Cycle detection
- β Relation kind filtering
- β Path finding (shortest path, path exists)
- β Performance benchmarks (<200ms for 100+ docs)
- β End-to-end workflows (Goal β Feature β WorkItem)
- β Validation + Traceability integration
- β Performance benchmarks (100 docs < 200ms, validation < 100ms)
- β SQLite schema v1.2.0 with 7 document types, 14 relation types
- β ETag concurrency control (optimistic locking)
- β JSON Patch (RFC 6902) for partial updates
- β Relations CRUD with typed validation
- β Validation Layer - Zod schemas, quality gates, coverage metrics
- β Traceability Layer - Recursive CTE, graph traversal, impact analysis
- β MCP Server - 10 tools (docs/, relations/, trace/paths, docs/validate)
- β Performance Optimizations - Index verification, query logging
- β Test Coverage - 100+ tests with performance benchmarks
- β 100% test passage - All unit and integration tests passing
- β <200ms p95 latency - Traceability queries meet KR-1 target
- β <100ms validation - Document validation meets performance target
- β DoS protection - Hard maxDepth=20 limit prevents infinite loops
- β 2179 LOC - Validation + Traceability layers
- work-014-016: Enhanced MCP Features (Low Priority)
- Additional MCP resources
- Enhanced prompts
- Structured logging improvements
- v1.2.0 Features: Knowledge Management (Medium Priority)
- DecisionRecord workflows (work-017-019)
- LessonLearned workflows (work-020-022)
- Review workflows (work-023-025)
ContextHub exposes the following tools via Model Context Protocol:
docs/list- List documents with filtering (type, status, tags, pagination)docs/get- Get specific document by IDdocs/create- Create new document with ETagdocs/update- Update document with optimistic lockingdocs/patch- Apply RFC 6902 JSON Patch operationsdocs/validate- NEW - Comprehensive validation (schema, gates, coverage)
relations/create- Create typed relation (14 types supported)relations/delete- Remove relationrelations/list- List relations (incoming/outgoing/both)
trace/paths- NEW - Find paths between documents (forward/reverse/both)
// Validate a Feature document
await client.callTool('docs/validate', {
projectId: 'my-project',
documentId: 'feat-123'
});
// Returns: { ok: true, gates: [{ passed: true, score: 1.0 }], coverage: { acCoveragePercent: 100 } }
// Trace from Goal to WorkItems
await client.callTool('trace/paths', {
fromId: 'goal-1',
direction: 'reverse', // Find implementers
maxDepth: 10
});
// Returns: { paths: [{ nodes: ['goal-1', 'feat-1', 'work-1'], relations: ['supports', 'implements'], length: 2 }] }- Runtime: Node.js 20 LTS
- Language: TypeScript 5.6+ (strict mode)
- Database: SQLite 3.45+ with JSON1 extension
- ORM: better-sqlite3
- Validation: Zod 3.23+
- MCP: @modelcontextprotocol/sdk 0.5+
- Testing: Vitest 2.1+
- Build: tsc
MIT