All Articles/strata-mcp
Open Source
September 2, 20267 min read

Building Strata MCP: AST-Driven Frontend Structural Analysis & Component Graph Engine for AI Coding Agents

Why plain text search and indiscriminate file reading fall short on modern single-file components, and how Strata partitions multi-language documents, remaps source coordinates, and serves bounded structural contracts with explicit static-analysis limits.

DS
Dimas SetoAuthor

Core Concepts

  • Plain text or regex searches match comments, string literals, and unrelated identifiers without modeling imports or template render sites.
  • Modern SFC formats (.vue, .astro, .svelte) combine markup templates, scripts, and styles in a single document, requiring block partitioning prior to AST analysis.
  • Strata partitions documents, analyzes script and template ASTs separately, and remaps block-relative positions back to exact line, column, and UTF-16 offsets on disk.
  • Every response includes scope, freshness hashes, and static-analysis limitations so agents treat findings as bounded static evidence rather than runtime proof.

When AI coding agents explore modern frontend codebases, plain text search lacks awareness of component boundaries, imports, and template/script separation, while reading entire files indiscriminately blends public interfaces with implementation details. Strata provides structured AST inspection and local graph indexing to bridge that gap.

1. Why Plain Text Search & Whole-File Dumping Fall Short

In AI-assisted software engineering workflows, two habits dominate codebase exploration: text/regex search (grep) and reading entire files into context. On modern frontend stacks (Vue, Nuxt, React, Next.js, Astro, and Svelte), both approaches encounter structural gaps:

  1. No Distinction Between Syntax Roles: Text matching flags component names inside comments, string literals, or shadowed local variables.
  2. Casing Polymorphism & Import Aliases: Components may be referenced in PascalCase or kebab-case, imported under aliases, or re-exported through barrel modules. Text search does not resolve these links.
  3. Multi-Language Single-File Documents: Files like .vue, .astro, and .svelte embed template markup alongside TypeScript or JavaScript logic. General AST parsers require document splitting before analyzing script blocks cleanly.
  4. Unselective Context Ingestion: Loading an entire multi-hundred-line component file just to verify its public props, emits, or reactive store usage mixes interface boundaries with unrelated implementation code.

2. How Strata Works: Partitioning, Remapping & Local Graph Indexing

Strata analyzes frontend source files through a deterministic static pipeline:

.vue / .astro / .svelte / .tsx / .ts file
   │
   ▼
[Document Partitioning]  ← Splits script blocks, template/JSX markup, and frontmatter
   │
   ├── Script / TS blocks ──► [ast-grep & Compiler API] ──► Declarations, state, outbound API calls
   │                                                               │
   ├── Template / JSX ──────► [Template / JSX AST] ───────► Rendered tags, props, slots, events
   │
   ▼
[Offset Remapping]       ← Translates block-relative positions back to disk coordinates
   │
   ▼
[Local SQLite Graph]     (.strata/graph.db) ← Indexed contracts, component edges, state & routes
   │
   ▼
[Bounded MCP Output]     ← Selective slices and structured metadata with explicit coverage notes
  • Document Partitioning: Framework parsers split .vue, .astro, and .svelte files into dedicated script and template regions prior to AST matching.
  • Coordinate Offset Remapping: Because isolated script parsers start at line 1 of the extracted block, Strata restores the original file's line, column, and UTF-16 offsets so returned coordinates match disk reality.
  • Selective Inspection (Map first, read selectively): Agents can map workspace files or a file's outline first, inspect public contracts, and then request only the specific symbol or line range required for an edit.

3. The Six Public MCP Tools

Strata exposes six focused tools through the Model Context Protocol (MCP):

MCP Tool Primary Role How It Helps
find_code Search & Inventory Inventories workspace files without reading bodies (action: "map"), executes ast-grep patterns and relational YAML rules, and analyzes static component/prop usage.
inspect_component Contracts & Source Slices Extracts component interfaces (props, emits, slots, models, state bindings, outbound API contracts), maps source regions, and slices targeted symbols or hash-bound ranges.
get_component_tree Hierarchy & Consumer Scope Traverses downward rendered component trees (with prop-drilling and context checks) or upward consumer candidates from leaf components to route entrypoints.
trace_state Reactive State Flow Classifies indexed store, context, and composable usages into static reader and mutator candidates across single or multi-hop chains.
audit_frontend Topology & Health Audits Extracts route manifests (routes), outbound HTTP calls (api-contracts), and static unused-code candidates (dead-components, dead-state).
generate_patch_plan Refactoring Proposals Produces reviewable, SHA-256 hash-bound edit proposals across static consumers when renaming or removing props, events, models, or slots without mutating disk files directly.

4. Practical Benefits & Static Analysis Boundaries

Benefits in Daily Engineering

  • Interface-First Understanding: Agents inspect component boundaries and dependency relationships before diving into implementation blocks.
  • Hash-Bound Source References: Retrieval references carry SHA-256 file hashes so stale coordinates caused by intermediate file edits are detected rather than silently reused.
  • Explicit Uncertainty Reporting: Static prop-omission analysis separates resolved static renders from indeterminate patterns such as dynamic prop spreading.

Explicit Boundaries

  • Static Observation Is Not Runtime Proof: Strata does not execute the frontend application. Route lists, unused-component candidates, and outbound API hints reflect static syntax within scanned files.
  • Index Precondition for Graph Queries: get_component_tree, trace_state, and audit_frontend(target: "dead-state" | "all") require an initialized .strata/graph.db via strata init.
  • Empty Matches Are Scope-Bounded: A zero-match result means no evidence was detected within the configured scope, exclusions, and traversal depth—not universal proof of runtime absence.

5. Installation & MCP Client Setup

Strata runs on the Bun runtime or as a standalone compiled binary.

Initialize a Workspace

# Install globally or run via bunx
bun add -g @dimassetoid/strata-mcp

# Build the local graph index (.strata/graph.db) and scaffold agent rules
strata init

Configure an MCP Client

{
  "mcpServers": {
    "strata": {
      "command": "bunx",
      "args": ["@dimassetoid/strata-mcp", "serve"]
    }
  }
}

Full tool documentation, storage contracts, and retrieval specifications are maintained at strata.dimasseto.id.

Closing Note

Strata gives AI coding agents structured, AST-backed visibility into modern frontend applications while keeping static analysis boundaries explicit. It is open source under the MIT license, with full documentation at strata.dimasseto.id.

Tags:
Model Context Protocol
Vue SFC
Astro Islands
React / Next.js
Svelte
ast-grep
SQLite WAL
AI Coding Agents