svelte-index-mcp Svelte Themes

Svelte Index Mcp

mcp for indexing Svelte 5 code for AI assisted development

Svelte Index MCP

An MCP (Model Context Protocol) server that indexes Svelte 5 and SvelteKit projects, providing rich code intelligence for AI assistants.

Features

  • Full Svelte 5 Support: Parses <script>, <script module>, template, and <style> blocks. Automatically detects Svelte version from package.json; rejects Svelte 4 and earlier with a clear error.
  • SvelteKit Route Detection: Automatically discovers pages, layouts, error pages, and server routes
  • Rune Extraction: Identifies $state, $derived, $effect, $props, $bindable, $inspect, $host, $snippet, and $render usage
  • Symbol Indexing: Functions, variables, imports, exports, props, snippets, effects, and derived values
  • Fuzzy Symbol Search: Search symbols by wildcard pattern (*Button* matches MyButton, ButtonRow, etc.) with optional kind filtering
  • Dead Code Detection: Find exported symbols that are never imported by other files
  • Component Analysis: Props, slots, snippets, generics, and context usage
  • Relationship Tracking: Import chains, component usage, and symbol references
  • Incremental Indexing: Content-hash based skip for unchanged files

Installation

From Source

git clone <repository>
cd svelte-index-mcp
cargo build --release
# Binary is at target/release/svelte-index-mcp

Install to PATH

cp target/release/svelte-index-mcp ~/.local/bin/
# or
cargo install --path .

CLI Usage

Index a Project

# Index current directory
svelte-index-mcp index

# Index specific path
svelte-index-mcp index ./my-svelte-project

# Force full re-index
svelte-index-mcp index . --force

# Verbose output
svelte-index-mcp index . --verbose

Output:

Indexing project at "my-project"
Found 42 Svelte files to index
Indexed 42 files, 156 symbols, 12 components

Start MCP Server

# Use default database (.svelte-index.db)
svelte-index-mcp serve

# Use custom database path
svelte-index-mcp serve --db-path /path/to/index.db

The server communicates via JSON-RPC over stdin/stdout, compatible with MCP clients like Claude Desktop, Cursor, and others.

What Gets Indexed

Files

File Kind Detected By Examples
page +page.svelte src/routes/about/+page.svelte
layout +layout.svelte src/routes/+layout.svelte
error +error.svelte src/routes/+error.svelte
server +server.ts / +server.js src/routes/api/+server.ts
component .svelte files src/lib/Button.svelte
module Files in /lib/ src/lib/utils.ts

Symbols

Kind Description
function Function declarations
variable Variable declarations
rune Svelte 5 runes ($state, $derived, etc.)
component Component references in templates
import Import statements
export Export statements
prop $props() declarations
effect $effect() / $effect.pre()
derived $derived() / $derived.by()
snippet {#snippet} definitions

Routes (SvelteKit)

Routes are automatically extracted from the file path relative to src/routes/:

  • /src/routes/+page.svelte
  • /aboutsrc/routes/about/+page.svelte
  • /sverdle/how-to-playsrc/routes/sverdle/how-to-play/+page.svelte
  • Route parameters like [id] are detected and stored

MCP Tools

Code Intelligence

Tool Description
query_symbols Search symbols by name pattern. Returns file locations, kinds, and signatures.
search_symbols Search symbols by wildcard pattern. Use * as a wildcard (e.g., *Button* matches MyButton, ButtonRow). Optionally filter by kind (function, variable, rune, import).
get_symbol Get full details of a symbol by name and optional file path.
list_symbols List all symbols, optionally filtered by kind (function, variable, rune, etc.) or file.
get_component Get component details including props, slots, snippets, runes used, and generics.
list_components List all indexed components, optionally filtered by directory path.
find_dead_code Find exported symbols that are never imported by other files. Filter by path prefix and symbol kinds (function, variable).
Tool Description
find_usage Find all locations where a symbol is used.
find_imports List all imports for a given file.
trace Trace call/usage chains. Direction: inbound (who uses this) or outbound (what this uses).
find_context Find setContext/getContext usage. Filter by context key or direction (set/get).

Routes & Project

Tool Description
find_routes Find SvelteKit routes. Filter by path pattern. Returns path, kind, and parameters.
index Trigger re-indexing. Use force=true to reindex all files.
index_status Get indexing status: file count, last indexed time, project root.

Database Schema

The index is stored in a SQLite database (.svelte-index.db):

Tables

  • files — Indexed files with path, content hash, language, and file kind
  • symbols — Named symbols (functions, variables, runes, props, etc.)
  • components — Components referenced in templates (e.g., <Counter />)
  • props — Component prop definitions
  • relationships — Import/export and usage relationships between symbols
  • contextssetContext/getContext usage
  • routes — SvelteKit routes with path, kind, and parameters
  • index_meta — Project root path, last indexed timestamp, and detected Svelte version

Development

Build

cargo build

Run Tests

# All tests
cargo test

# Just integration tests
cargo test --test integration_tests

# With output
cargo test -- --nocapture

Lint

# Check for warnings (CI uses this)
cargo clippy --all-targets --all-features -- -D warnings

# Auto-fix
cargo clippy --all-targets --all-features --fix

# Format
cargo fmt

Project Structure

src/
  main.rs              # CLI entry point (index, serve commands)
  lib.rs               # Library exports
  indexer.rs           # Orchestrates: walk → parse → store in SQLite
  walker.rs            # Find .svelte files, detect project root, file kinds
  db/mod.rs            # SQLite schema, queries, and CRUD operations
  parser/
    svelte.rs         # Block separation: script/template/style
    typescript.rs     # JS/TS parsing: runes, functions, imports, exports
    template.rs       # Template AST: components, blocks, directives, snippets
  mcp/
    mod.rs            # MCP server entry
    server.rs         # JSON-RPC server setup
    handler.rs        # Tool dispatch and request handling
    tools.rs          # Tool definitions with JSON schemas

Documentation

  • docs/roadmap.md — Current development priorities and upcoming features

Architecture

Indexing Pipeline

  1. Walk (walker.rs) — Recursively find .svelte files (excludes node_modules and .svelte-kit)
  2. Parse (parser/) — Extract blocks, then parse TypeScript and template content
  3. Store (db/mod.rs) — Insert into SQLite with incremental hash-based updates

Parsing Pipeline

  1. Block separation — Split file into <script module>, <script>, template, <style>
  2. Script parsing — Extract runes, functions, imports, exports
  3. Template parsing — Find components, blocks ({#if}, {#each}, {#snippet}), directives (bind:, on:, use:, transition:)

License

[License information]

Top categories

Loading Svelte Themes