lietzsche;stokes

updated 2026-11-26·5 min read

Deterministic CI Gate & Native MCP Server

Static AST boundary checks in CI/CD pipelines and the native Model Context Protocol (MCP) server for AI coding assistants.

Two things break polyglot backends in practice: four-minute Docker integration suites that developers skip on local commits, and an AI coding assistant editing a .sql migration with no idea a Rust stack buffer downstream only holds 200 slots.

Stokes runs both checks from the same parser and reachability core: a zero-container static CI gate (stokes verify --strict) and a native Model Context Protocol (MCP) server over stdio.

  1. Entrypoints (Developer CLI & AI Agents)

    Developers invoke stokes verify --strict on push/PR; AI coding agents connect to stokes mcp over JSON-RPC 2.0 stdio.

  2. Boundary Parsing & Graph Walk

    Stokes parses SQL, Protobuf, Python, and Rust boundary files (native Tree-sitter when present, Python regex fallback otherwise) to link upstream schemas to downstream buffers.

  3. Lockfile Digest Check

    Normalized boundary declarations are hashed with SHA-256 and checked against stokes.lock.

  4. Deterministic Outputs

    CLI emits Exit 0 (Verified), Exit 1 (Contract Violation), or Exit 2 (Missing Manifest); MCP returns stokes_boundary_graph, stokes_audit, and patch guidance.

Static AST CI Verification Gate

Because stokes verify --lockfile=stokes.lock --strict skips Docker containers, avoids booting databases, and never invokes rustc or mypy, a local gate finishes in a fraction of a second rather than minutes. Every check ends in one of five explicit exit codes:

Exit CodeSemantic StatusMeaning & Remediation
0VERIFIEDAll boundary bounds hold and stokes.lock digests match.
1CONTRACT_VIOLATIONColumn-vs-buffer overflow, wildcards, or float traps found. Merge blocked.
2INVALID_CONFIGURATIONMissing stokes.toml, malformed manifest, or missing/corrupted stokes.lock. Run stokes init or stokes scan.
3FATAL_INTERNAL_ERRORSystem I/O error or unhandled parsing fault.
130INTERRUPTEDReceived SIGINT (Ctrl+C) or timed out.
GitHub Actions Gate Workflow (.github/workflows/stokes-gate.yml)
name: Stokes Cross-Boundary CI Gate

on:
  pull_request:
    branches: [main, release-*]
  push:
    branches: [main]

jobs:
  boundary-audit:
    name: Boundary Verification
    runs-on: ubuntu-latest
    timeout-minutes: 2

    steps:
      - name: Checkout Source Code
        uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.13"

      - name: Install Stokes
        run: curl -fsSL https://trystokes.pages.dev/install.sh | sh

      - name: Execute Fast Gate
        run: |
          stokes verify --strict \
            --manifest=stokes.toml \
            --lockfile=stokes.lock \
            --format=github-annotations \
            --json-out=stokes-result.json

      - name: Check Artifact Conformance
        if: failure()
        run: |
          echo "::error::Stokes Boundary Verification Failed!"
          echo "::notice::Run 'stokes audit' locally to review synthesized diffs."
          exit 1

Native Model Context Protocol (MCP) Server

Standard LSP diagnostics stop at the file currently open in the editor. When an AI assistant proposes an upstream SQL migration, Stokes MCP checks the diff against downstream buffers before it touches disk:

  1. Agent Query

    Agent calls stokes_inspect_channel(channel_id="analytics_to_edge_l7") or stokes_verify_patch before committing an upstream schema change.

  2. Reachability Evaluation

    Stokes walks downstream consumers mapped to the channel.

  3. Capacity Check

    Detects a downstream edge proxy allocating a fixed 200-slot stack buffer.

  4. Rejection & Guidance

    On a proposed expansion to 202 columns, Stokes flags Risk = 202 / 200 = 1.01 > 1.0 and suggests expanding downstream capacity or using Dual-Zone partitioning.

  5. Patch Application

    The agent patches the downstream consumer or scopes the SQL query before committing.

JSON-RPC 2.0 stokes_verify_patch Request & Response
// Request
{
  "jsonrpc": "2.0",
  "id": "req-042",
  "method": "tools/call",
  "params": {
    "name": "stokes_verify_patch",
    "arguments": {
      "target_file": "migrations/001_bot_signals.sql",
      "patch_content": "--- a/migrations/001_bot_signals.sql\n+++ b/migrations/001_bot_signals.sql\n@@ -10,2 +10,4 @@\n+    ja4_transport_entropy Float32,\n+    device_trust_score Float32,\n"
    }
  }
}

// Response
{
  "jsonrpc": "2.0",
  "id": "req-042",
  "result": {
    "is_safe": false,
    "rule_id": "LINT-004",
    "risk_ratio": 1.01,
    "downstream_impacts": [
      {
        "channel_id": "analytics_to_edge_l7",
        "consumer_repo": "cloudflame-proxy",
        "consumer_file": "crates/cloudflame-proxy/src/engine/feature_ingest.rs",
        "buffer_capacity": 200,
        "new_cardinality": 202,
        "panic_reachable": true
      }
    ],
    "remediation_guidance": "Do not commit this SQL migration yet. Run stokes_remediate to synthesize Dual-Zone (128 + 72) partitioning or expand downstream capacity first."
  }
}

MCP Tools, Resources & Agent Setup

  • Exposed Tools: stokes_audit, stokes_boundary_graph, stokes_remediate, stokes_inspect_channel, stokes_verify_patch.
  • Exposed Resources: stokes://contracts, stokes://graph, stokes://lockfile.
Cursor, Claude Code, and IBM Bob 2.0 Configurations
// .cursor/mcp.json
{
  "mcpServers": {
    "stokes": {
      "command": "stokes",
      "args": ["mcp"],
      "env": {
        "STOKES_LOG_LEVEL": "info",
        "STOKES_STRICT": "1"
      }
    }
  }
}
// ~/.claude/config.json
{
  "mcpServers": {
    "stokes-boundary-engine": {
      "command": "stokes",
      "args": ["mcp"],
      "transport": "stdio"
    }
  }
}
# stokes/subagents/mcp_bridge.py
class BobStokesMCPBridge:
    def __init__(self, workspace: str) -> None:
        self.workspace = workspace
        self.engine = ReachabilityGraph()

    async def handle_agent_pre_commit(self, file_path: str, diff: str) -> dict:
        """Invoked by Bob 2.0 before writing patches to disk."""
        impact = self.engine.evaluate_diff_impact(file_path, diff)
        if impact.violates_invariant:
            return {
                "allow_write": False,
                "reason": impact.explanation,
                "required_action": "EXPAND_DOWNSTREAM_BUFFER_FIRST"
            }
        return {"allow_write": True}

Why Static Gate + MCP Beats Waiting on Full CI

FeatureLegacy CI LintingStatic Analyzer (SonarQube)Monorepo CI (Bazel)Stokes Gate + MCP
Execution CostFull toolchain per repoFull index buildDependency graph + buildsSingle-pass AST/regex scan (no Docker or rustc)
Cross-Language AnalysisNone (Siloed)Superficial rulesDependency graph onlyCross-boundary reachability
Buffer Capacity AwarenessNoneNoneNoneStack/Cache bound (emitted <= capacity)
AI Agent FeedbackPost-commit onlyPost-commit onlyPost-commit onlyPre-commit via MCP JSON-RPC
Schema LockfileNoneNoneNonestokes.lock (SHA-256 ASTs)

See MCP Protocol Specification and CLI Reference for complete JSON schemas and command flags.

Search wiki and portfolio

type to search across all entries.