StackBridge

StackBridge

Sub-1ms cross-stack AST contract layer and compiler verification engine mapping React/Next.js routes to FastAPI and SQLAlchemy models for AI coding agents.

Category
Visit Server

README

<div align="center">

๐ŸŒ‰ StackBridge-MCP

Sub-1ms Cross-Stack AST Contract & Verification Layer for AI Coding Agents

PyPI version Python 3.10+ License: MIT CI Tests FastMCP Compatible

<p align="center"> <a href="#-quick-start">Quick Start</a> โ€ข <a href="#-client-configuration">Client Config</a> โ€ข <a href="#-real-world-benchmarks">Benchmarks</a> โ€ข <a href="#-architecture--mcp-tools">MCP Tools</a> โ€ข <a href="#-cli-reference">CLI Reference</a> โ€ข <a href="docs/architecture.md">Docs</a> </p>

</div>


๐Ÿ’ก Why StackBridge?

When AI coding agents (Cursor, Claude Code, Windsurf, Antigravity) edit backend models or API routes in full-stack codebases, backend unit tests frequently pass while the frontend silently breaks in production:

  1. An agent modifies an API parameter or Pydantic/SQLAlchemy field in backend/routes.py.
  2. Backend tests pass in isolation. Nothing warns the agent.
  3. The React/Next.js client calling that endpoint across the boundary fails with runtime errors.

StackBridge-MCP is an always-warm Model Context Protocol (MCP) server that parses full-stack AST relationships, discovers cross-stack blast radii in 0.75 ms, and verifies changes using baseline-diffed compiler checks with zero false positives.

React / Next.js Client            FastAPI Routes            SQLAlchemy ORM Models
   (TypeScript AST)      โ”€โ”€โ”€โ–บ    (Python AST)     โ”€โ”€โ”€โ–บ          (Schema AST)
  UserProfile.tsx              get_user_billing()              BillingAccount

โšก Key Highlights

  • ๐ŸŒฒ Tree-sitter AST Graph: Parses Next.js (fetch, Axios, React Query) โ†” FastAPI routes โ†” SQLAlchemy ORM models without heavy LSP sidecars or runtime imports.
  • โšก Sub-1ms Traversal: Persistent SQLite WAL database with recursive Common Table Expressions (0.75 ms traversal query latency).
  • ๐Ÿ“‰ 99.74% Prompt Token Reduction: Replaces massive multi-file code dumps with compact, mathematically precise AST contract slices.
  • ๐Ÿ›ก๏ธ Root-Cause Diagnostic Ranking: Graph-distance BFS ranks errors (๐Ÿ”ด PRIMARY ROOT CAUSE vs โš ๏ธ CASCADING BREAKAGE) and outputs immediate Git diff patches.
  • ๐Ÿงช Test Impact Selection: Isolates test suites impacted by a schema change and highlights untested blast-radius paths (0% coverage).
  • ๐ŸŒ Interactive Canvas: Built-in localhost tripartite visualizer (stackbridge ui) on http://127.0.0.1:3456.
  • ๐Ÿ”„ Continuous Intelligence: Background file watcher daemon (stackbridge watch) and living AGENTS.md context generator.

๐Ÿ“Š Real-World Benchmarks

Empirical performance measured on fastapi-realworld-example-app (44 files, 23 AST dependency nodes, 10 cross-boundary edges):

Benchmark Metric Raw Codebase Dump StackBridge Compact Slice Improvement / Latency
Context Window Size 19,705 tokens 51 tokens ๐Ÿ“‰ 99.74% Token Reduction
Blast Radius Traversal Full-repo search: ~150 ms SQLite Recursive CTE: 0.75 ms โšก 200x Faster Traversal
Compiler Verification Global linter: ~3,500 ms Baseline-Diffed Engine: 312 ms ๐Ÿ›ก๏ธ Zero False Positives
Automated Test Suite โ€” 56 / 56 tests passing โœ… 100% Passing

See full benchmark methodology in docs/benchmarks.md and REAL_WORLD_BENCHMARK.md.


๐Ÿš€ Quick Start

Option 1: Zero-Install Execution (Recommended via uvx)

uvx stackbridge serve

Option 2: Pip Installation

pip install stackbridge
stackbridge serve

โš™๏ธ Client Configuration

Connect StackBridge to your AI pair programmer over standard JSON-RPC 2.0 stdio:

1. Cursor (.cursor/mcp.json)

{
  "mcpServers": {
    "stackbridge": {
      "command": "uvx",
      "args": ["stackbridge", "serve"]
    }
  }
}

2. Claude Desktop (claude_desktop_config.json)

{
  "mcpServers": {
    "stackbridge": {
      "command": "python",
      "args": ["-m", "stackbridge.main", "serve", "--transport", "stdio"]
    }
  }
}

๐Ÿค– MCP Tools Reference

StackBridge exposes high-ergonomics tools to coding agents:

Tool Name Arguments Description
trace_fullstack_path symbol_or_path: str Traces the full-stack dependency chain: Frontend component โž” API route โž” Database model.
get_route_contract route_path: str Extracts HTTP methods, status codes, response models, and linked frontend fetch callers with confidence scores.
verify_schema_change modified_files: dict Runs in-memory compiler checks across impacted files, ranking root causes and proposing diff patches.
get_stack_health repo_path: str Returns real-time full-stack boundary stats, node counts, edge counts, and breakage drift status.

๐Ÿ’ป CLI Reference

# Index a repository and export the dependency graph
stackbridge index --repo-path . --force

# Trace blast radius for a model or route
stackbridge trace --target BillingAccount

# Run pre-commit boundary verification guard
stackbridge guard --fail-on-error

# Launch interactive tripartite web visualizer
stackbridge ui --port 3456

# Start continuous background watcher daemon
stackbridge watch

# Generate living AGENTS.md boundary architecture guide
stackbridge init-agents

# Execute performance and token reduction benchmarks
stackbridge benchmark --runs 3 --output BENCHMARK.md

๐Ÿ“ Repository Structure

StackBridge-MCP/
โ”œโ”€โ”€ .github/
โ”‚   โ”œโ”€โ”€ workflows/ci.yml         # CI pipeline (Python 3.10-3.13 on Ubuntu/Windows/macOS)
โ”‚   โ”œโ”€โ”€ ISSUE_TEMPLATE/          # Bug report and feature request issue templates
โ”‚   โ””โ”€โ”€ PULL_REQUEST_TEMPLATE.md # Standard PR checklist
โ”œโ”€โ”€ docs/
โ”‚   โ”œโ”€โ”€ architecture.md          # Subsystem breakdown and Mermaid diagrams
โ”‚   โ”œโ”€โ”€ benchmarks.md            # Benchmark methodology and raw metrics
โ”‚   โ””โ”€โ”€ ast_extraction_spec.md   # Tree-sitter extractor grammar specifications
โ”œโ”€โ”€ stackbridge/
โ”‚   โ”œโ”€โ”€ core/                    # Unified StackGraph, SQLite CTE store, watcher, route matcher
โ”‚   โ”œโ”€โ”€ parsers/                 # Tree-sitter parsers (TS fetch, Python routes, SQLAlchemy)
โ”‚   โ”œโ”€โ”€ verifier/                # Baseline-diffed verifier, root-cause ranker, test impact selector
โ”‚   โ”œโ”€โ”€ mcp_server/              # FastMCP stdio server and JSON-RPC tools
โ”‚   โ”œโ”€โ”€ benchmarks/              # Benchmark runner and markdown report generator
โ”‚   โ””โ”€โ”€ ui/                      # Localhost tripartite interactive canvas
โ”œโ”€โ”€ tests/                       # 56 automated test suites (parsers, verifiers, MCP E2E, CTE)
โ”œโ”€โ”€ AGENTS.md                    # Living agent architecture guide
โ”œโ”€โ”€ CHANGELOG.md                 # Version release notes
โ”œโ”€โ”€ CONTRIBUTING.md              # Contribution and development guidelines
โ”œโ”€โ”€ LICENSE                      # MIT License
โ””โ”€โ”€ pyproject.toml               # Package metadata and tool configurations

๐Ÿ“„ License

This project is licensed under the MIT License.

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured