Appearance
Specification: Unified Developer Tooling, Native MCP Server & Staged Guardrails
NOTE
Status: design proposal. Not necessarily implemented. Check the relevant README or ADR before relying on it; kernel concepts in the kernel specification take precedence. Neo4j, mentioned below, is retired (ADR-2245).
- Status: Ready for Implementation
- Requirement ID: PRD-SYS-049
- ADR Reference: ADR-2189
- Triage Label:
ready-for-agent
Problem Statement
In the Cadence Clinical high-assurance eClinical platform, engineering involves both human software engineers and autonomous AI coding agents operating across microservices, CDISC data pipelines, and strict GxP (21 CFR Part 11) compliance boundaries.
However, developer tooling currently exhibits critical friction points:
- Unstructured Agent Interoperability: Autonomous agents must invoke shell commands and parse unstructured Rich console output, leading to shell-escaping bugs, token waste, and heuristic parsing errors.
- Missing Local Pre-Commit Guardrails: Architectural violations (import ordering
I001, SQLAlchemy boolean comparisonsE712, secret exposures, and OpenAPI schema drift) are often discovered late in CI, causing avoidable PR roundtrips and developer friction. - Inconsistent Terminal Output: Command line interfaces lack visual document hierarchy, status card indicators, and actionable Next-Action CTAs, confusing developers during multi-service debugging.
- Manual Environment Recovery: Recovering from missing SQLite schemas, unindexed ADRs, or stale test databases requires disparate manual scripts.
Solution
Build a unified, four-pillar developer tooling architecture:
- Native Stdio MCP Server (
cadence mcp): Provide a Model Context Protocol endpoint directly within thecadenceCLI exposing 6 workflow-centric tools with parameter-level zoom control (summary,fields,dry_run). - Two-Tier Staged Pre-Commit Hook: Implement a fast, Python/UV-native git pre-commit pipeline executing sub-500ms staged file checks and PRD-SUB-001.5s repo assertions, auto-installed via
cadence doctor --auto-fix. - Centralized
TerminalDocumentBuilder: Standardize all human CLI output into authored terminal documents with narrative headings, status metric badges, column-aligned layouts, and contextual Next-Action CTAs, paired with strict NDJSON/JSON output in non-TTY contexts. - Deterministic Tooling Self-Healing: Provide safe, non-destructive automated remediation of environment drift, SQLite scratch databases, import ordering, code formatting, ADR indexing, and OpenAPI schema exports.
User Stories
- As an autonomous coding agent, I want to invoke
doctor_diagnosevia MCP stdio, so that I can verify Python 3.14 runtime, port bindings, and database readiness with structured JSON output and zero shell parsing. - As an autonomous coding agent, I want to run
run_sentinelsvia MCP with asummary=Trueparameter, so that I can inspect quality gate results without consuming excessive context tokens. - As an autonomous coding agent, I want to execute
run_fast_testsvia MCP, so that I can run the TDD red-green-refactor feedback loop in under 1 second. - As an autonomous coding agent, I want to call
seed_clinical_scenariovia MCP with scenario name parameters, so that I can provision reproducible graph and relational test states without running shell scripts. - As an autonomous coding agent, I want to invoke
sync_gxp_compliancewithdry_run=True, so that I can test whether my changes introduced RTM or IQ/OQ/PQ doc drift before committing. - As an autonomous coding agent, I want to invoke
introspect_service_contracts, so that I can discover machine-readable OpenAPI specifications and cross-app routes at runtime. - As a human software engineer, I want the git pre-commit hook to run staged formatting and linting in sub-500ms, so that committing code never breaks my flow state.
- As a human software engineer, I want the pre-commit hook to automatically catch and fix Ruff formatting and import sorting violations on staged files, so that I never fail CI on
I001or style rules. - As a human software engineer, I want the pre-commit hook to reject bare SQLAlchemy boolean equality checks (
E712) before commits are created, so that GxP-critical SQL queries remain safe. - As a human software engineer, I want the pre-commit hook to run a secret scan across staged hunks, so that API credentials or JWT private keys are never committed.
- As a human software engineer, I want
uv run cadence doctor --auto-fixto automatically install the git pre-commit hook into.git/hooks/, so that onboarding new clones requires zero manual hook setup. - As a human software engineer, I want
cadence doctorto output an authored terminal document with status cards and aligned columns, so that I can immediately see which ports, databases, or tools need attention. - As a human software engineer, I want
cadence checkto display a Next-Action CTA pointing touv run cadence fix --allwhenever format or lint errors occur, so that I know the exact remediation command immediately. - As a human software engineer, I want
cadence fix --allto format code, sort imports, re-index ADRs, and export OpenAPI schemas in one atomic command, so that all repository metadata stays synchronized. - As a CI/CD pipeline, I want
cadence check --jsonto emit clean, parseable JSON error arrays, so that automated quality gates integrate seamlessly with GitHub Actions and status checks. - As a compliance auditor, I want all developer tool actions to enforce and preserve 21 CFR Part 11 audit trails and non-destructive historical retention across database operations.
Implementation Decisions
1. Native Stdio MCP Server Module
- Module Boundary: Built inside the CLI package under an isolated MCP submodule.
- Protocol: Standard JSON-RPC 2.0 over
sys.stdin/sys.stdout. - Tool Catalog (6 Workflow-Centric Tools):
doctor_diagnose(auto_heal: bool = False, summary: bool = True): Runs system diagnostics, reports port allocations, Python 3.14+ compatibility, and database initialization.run_sentinels(gate: str | None = None, parallel: bool = True, summary: bool = True): Executes architecture sentinels and quality gates.run_fast_tests(subsystem: str | None = None, summary: bool = True): Executes sub-second fast unit tests.seed_clinical_scenario(tier: str = "standard", scenario: str = "default", dry_run: bool = False): Seeds multi-engine test data.sync_gxp_compliance(dry_run: bool = False): Verifies and syncs RTM and IQ/OQ/PQ docs.introspect_service_contracts(service: str | None = None): Provides OpenAPI and service boundary schemas.
- Response Zoom Envelope: Every tool response encapsulates a standardized envelope:json
{ "status": "success | error", "summary": "Concise 1-line narrative summary", "metrics": { "duration_ms": 120, "passed": 10, "failed": 0 }, "details": {}, "cta": "Suggested next command" }
2. Two-Tier Staged Pre-Commit Hook Module
- Stage 1 (Staged Hunks Only, Target <500ms):
- Extract staged
.pyand documentation paths usinggit diff --cached --name-only --diff-filter=ACM. - Execute
ruff check --fixandruff formatexclusively against staged Python files. - Execute
clean_secrets_baseline.pyandvalidate_path_patterns.pyon staged files. - Automatically re-stage fixed files if safe formatting mutations occurred.
- Extract staged
- Stage 2 (Repository Scope Invariant Assertions, Target <1.5s):
- Execute
validate_imports.pyto enforce zero sibling DB imports across microservice boundaries. - Execute fast unit test suite (
pytest -m "not integration").
- Execute
- Auto-Installation: Embedded into
.git/hooks/pre-commitas a lightweight shell wrapper delegating touv run python scripts/pre_commit.py.
3. Centralized TerminalDocument Builder Module
- Encapsulation: Implemented in
packages/cli/formatting.pyas a fluent document renderer. - Visual Sections:
- Narrative Header: Bold colored title + muted subtitle.
- Status Card Row: Boxed metrics (e.g.
10 Passed,0 Failed,1.2s Duration). - Column-Aligned Content: Tabular or key-value aligned data with styled labels and dimmed metadata.
- Clickable File Links: Proper
file://link generation. - Contextual Next-Action CTA: Distinctive footer banner providing exact follow-up commands.
- TTY Detection: When
not sys.stdout.isatty()or--jsonis supplied, bypass Rich console layout and stream NDJSON/JSON.
4. Deterministic Self-Healing Engine
- Safe Auto-Fixes:
- Auto-create and initialize missing SQLite schema files.
- Install
.git/hooks/pre-commitif missing or outdated. - Auto-sort imports and format Python source code.
- Auto-index ADR files under
docs/adr/index.md. - Auto-export FastAPI OpenAPI JSON schemas to
docs/openapi/.
- Guided CTAs: Output explicit shell instructions when external services (Neo4j, PostgreSQL Docker containers) or port conflicts require developer intervention.
Testing Decisions
What Makes a Good Test
- Tests must assert observable public behavior (CLI exit codes, stdout/stderr document structure, structured JSON payloads, git hook exit codes) rather than mocking internal helper variables.
- Zero network or external Docker dependencies for unit test execution.
Tested Surfaces
- CLI Commands (
packages/cli/src/Program.cs):- Assert
doctor,check,fix,test,mcpsubcommands withtyper.testing.CliRunner. - Validate both human-readable document output and
--jsonstructured parity.
- Assert
- MCP Server Protocol (
packages/cli/mcp/server.py):- Send JSON-RPC
initialize,tools/list, andtools/callpayloads to the stdio server handler. - Verify tool schema validity, parameter validation, and zoom envelope output.
- Send JSON-RPC
- Pre-Commit Runner (
tests/test_pre_commit.py):- Test staged file detection, formatting remediation, and repository invariant gate passing.
- Terminal Formatting (
packages/cli/tests/test_formatting.py):- Verify
TerminalDocumentlayout rendering, column alignment, and non-TTY JSON fallback.
- Verify
Prior Art
- CLI unit tests in
packages/cli/src/Program.cs. - Quality gate validation in
scripts/validate_path_patterns.pyandscripts/validate_imports.py.
Out of Scope
- Rewriting underlying microservice domain logic or REST API endpoints.
- Replacing Pytest with another testing engine.
- Adding third-party Node/npm global binaries into the Python root workflow.
Further Notes
- All code and test files must adhere to Python 3.14+ runtime invariants and strict typing.
- All new tests must include
@req:PRD-SYS-049docstrings for GxP traceability.