Skip to content

Deterministic MCP server for coordinating AI agents across software development lifecycles. SQLite graph traversal, Zod validation gates, RFC 6902 patching, and 100+ tests with <200ms p95 latency.

Notifications You must be signed in to change notification settings

BryceEWatson/ContextHub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ContextHub

TypeScript SQLite Zod MCP Vitest Latency

The context AI agents share - A deterministic MCP server that coordinates multiple AI agents across software development lifecycles.

Status: MVP Core Complete βœ…

Foundation + Validation + Traceability - Core MCP server with validation gates and graph traversal.

Features Implemented

πŸŽ‰ NEW: Validation & Quality Gates (work-006 through work-009)

  • βœ… 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

πŸŽ‰ NEW: Graph Traversal & Traceability (work-010 through work-011)

  • βœ… 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)

πŸŽ‰ NEW: MCP Integration (work-013)

  • βœ… 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

Database Schema (v1.2.0)

  • βœ… 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)

Constraints & Validation

  • βœ… 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

Performance

  • βœ… 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

Quick Start

# 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.ts

Database Statistics

After 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 βœ“

Project Structure

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

Test Coverage

Comprehensive test suite with 100+ tests across unit and integration layers:

Schema & Database (29 tests)

  • βœ… 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

Validation Layer (40+ tests) NEW

  • βœ… 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.)

Traceability Layer (35+ tests) NEW

  • βœ… 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)

Integration Tests (10+ tests) NEW

  • βœ… End-to-end workflows (Goal β†’ Feature β†’ WorkItem)
  • βœ… Validation + Traceability integration
  • βœ… Performance benchmarks (100 docs < 200ms, validation < 100ms)

Current Status & Next Steps

βœ… MVP CORE COMPLETE (work-001 through work-013)

  • βœ… 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

πŸ“Š Metrics Achieved

  • βœ… 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

πŸ“‹ Next Steps

  1. work-014-016: Enhanced MCP Features (Low Priority)
    • Additional MCP resources
    • Enhanced prompts
    • Structured logging improvements
  2. v1.2.0 Features: Knowledge Management (Medium Priority)
    • DecisionRecord workflows (work-017-019)
    • LessonLearned workflows (work-020-022)
    • Review workflows (work-023-025)

MCP Tools Available

ContextHub exposes the following tools via Model Context Protocol:

Document Management

  • docs/list - List documents with filtering (type, status, tags, pagination)
  • docs/get - Get specific document by ID
  • docs/create - Create new document with ETag
  • docs/update - Update document with optimistic locking
  • docs/patch - Apply RFC 6902 JSON Patch operations
  • docs/validate - NEW - Comprehensive validation (schema, gates, coverage)

Relationship Management

  • relations/create - Create typed relation (14 types supported)
  • relations/delete - Remove relation
  • relations/list - List relations (incoming/outgoing/both)

Traceability

  • trace/paths - NEW - Find paths between documents (forward/reverse/both)

Example Usage

// 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 }] }

Technology Stack

  • 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

License

MIT

About

Deterministic MCP server for coordinating AI agents across software development lifecycles. SQLite graph traversal, Zod validation gates, RFC 6902 patching, and 100+ tests with <200ms p95 latency.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published