Skip to main content
Glama

MicroIndex MCP (v1.0-lite)

Local AST + Vector Code Index & Minimalist FastMCP Server for ~90%+ AI Token Savings.

Stop letting coding agents burn 10,000+ tokens grepping and reading entire files just to find one method. MicroIndex parses your codebase with Tree-sitter ASTs, embeds compact structural chunks locally into LanceDB, and pairs a 2-tool FastMCP server (search_code, get_code_chunk) with Agentic Governance rules.

Deep-Dive & Benchmarks: Read the full architectural breakdown, Mermaid diagrams, and pytest quality gates on my blog: Why I Banned AI Agents from Using Grep: AST Indexing, Governance Rules, and 90%+ Token Savings.

MicroIndex Benchmark Card

graph LR
    Indexer["src/indexer.py<br/>(Incremental CLI)"] -->|AST Chunking <= 1500 chars| TS["Tree-sitter<br/>.py / .ts / .tsx / .js / .php / .vue"]
    Indexer -->|Local or Cloud Embeddings| Emb["all-MiniLM-L6-v2 (384d)<br/>or Ollama / OpenAI / Gemini"]
    Indexer -->|Write Vectors| LDB[("<project>/.lancedb_data<br/>+ index_state.json")]
    Agent["AI IDE / CLI Agent<br/>(Claude Code, Cursor, Antigravity)"] -->|MCP stdio + PYTHONUNBUFFERED=1| Server["src/mcp_server.py<br/>(FastMCP: search_code, get_code_chunk)"]
    Server -->|Query Embed| Emb
    Server -->|INDEXER_DATA_DIR| LDB

For AI Agents: Auto-Setup Protocol

Want your AI coding assistant (Claude Code, Cursor, Antigravity, Codex, Gemini CLI) to set up microindex-mcp end-to-end — including indexing, MCP config, Agentic Governance rules, and post-commit git hooks?

Point your agent to templates/AI_SETUP_PROMPT.md (or paste the prompt inside it into your chat).


Related MCP server: Glancey

5-Minute Quickstart (For Humans)

# 1. Create .venv and install dependencies (uses uv automatically if available)
make setup

# 2. Index examples/polyglot-mini (PHP + Vue 3 + Python) and run benchmark
make bench

# 3. Run pytest quality gates (Hit@5, MRR, Token Savings, Latency, Incremental 0-reencode)
make test

Linux CPU-only by default: On Linux, make setup installs CPU-only PyTorch automatically (CUDA=0) to skip ~2.5 GB of CUDA wheels. Run make setup CUDA=1 if you want GPU/CUDA wheels.

Token-Saving Tip: Prefer running make setup, make bench, and initial make index on large repositories directly in your own terminal rather than through an AI agent — you'll see live progress bars and avoid burning agent context tokens on long install/indexing logs.


Benchmark Results (examples/polyglot-mini/)

Measured via make bench using tiktoken (o200k_base) against two baselines across 6 queries (semantic, symbol, cross_stack):

  1. Baseline 1 (Grep + Full-File): keyword grep across files, reading every matched file in full.

  2. Baseline 2 (rg + Targeted ±30L): rg -n search output (capped at 50 lines) + reading ±30-line targeted windows (up to 3 merged slices per file) across the top-5 ranked files.

Provider: local (all-MiniLM-L6-v2) | Files: 4 | AST Chunks: 44 | Queries: 6

Metric

Value

Hit@5 (MicroIndex)

1.00 (100.0%)

Hit@5 (rg + Targeted)

1.00 (100.0%)

MRR

1.0000

Avg Chunk Precision

0.30 (30.0%)

Latency (Avg / P50 / P95)

10.4 / 10.5 / 10.6 ms

Avg Tokens / Query (MicroIndex)

691.7 tok

Avg Tokens / Query (Grep + Full-File)

1691.2 tok

Avg Tokens / Query (rg + Targeted ±30L)

1913.3 tok

Total Tokens (AST vs Full / rg)

4150 vs 10147 / 11480 tok

Token Savings vs Grep + Full-File

59.10%

Token Savings vs rg + Targeted ±30L

63.85%

Note: examples/polyglot-mini only contains 4 small files (~90 lines each). On larger multi-hundred-file repositories, fixed top_k=5 AST retrieval typically reaches 92–99% token savings vs Full-File and 76–90% vs rg + Targeted ±30L.

Query ID

Category

Hit@5

rg Hit

RR

Prec

Latency

AST Tok

Full Tok

rg Tok

vs Full

vs rg

q1_semantic_webhook

semantic

PASS

PASS

1.00

0.40

10.5 ms

386

1145

1132

66.3%

65.9%

q2_semantic_budget

semantic

PASS

PASS

1.00

0.40

10.9 ms

882

2902

3063

69.6%

71.2%

q3_symbol_capture

symbol

PASS

PASS

1.00

0.20

10.4 ms

462

1145

670

59.6%

31.0%

q4_symbol_anomaly

symbol

PASS

PASS

1.00

0.20

10.5 ms

878

1124

898

21.9%

2.2%

q5_cross_stack_embeddings

cross_stack

PASS

PASS

1.00

0.20

9.9 ms

651

1778

2940

63.4%

77.9%

q6_cross_stack_telemetry

cross_stack

PASS

PASS

1.00

0.40

10.6 ms

891

2053

2777

56.6%

67.9%

Real-World Production Case Studies (v1.0-lite, Anonymized)

Tested on three private production codebases (plus microindex-mcp itself) using developer-style queries synthesized from recent git commits (local all-MiniLM-L6-v2 embeddings on CPU), comparing MicroIndex AST+Vector against both Grep + Full-File Read and rg -n + Targeted ±30L Read:

Codebase

Files / AST Chunks

Hit@5 (AST / rg)

MRR

Avg Latency

Tokens / Query (AST vs Full / rg)

Savings vs Full-File

Savings vs rg + Targeted

Monorepo A (PHP + Vue 3 + Python)

329 / 3,811

0.80 / 1.00

0.8000

15.9 ms

705.6 vs 60,666.7 / 7,332.3

98.84%

90.38%

Service B (PHP + Event-Driven)

92 / 410

0.80 / 0.70

0.7500

11.1 ms

539.5 vs 10,795.9 / 3,253.3

95.00%

83.42%

Service C (Python / AI Agent)

70 / 1,185

0.90 / 0.90

0.9000

24.6 ms

758.8 vs 41,980.0 / 5,610.2

98.19%

86.47%

microindex-mcp (Self-Hosted)

19 / 274

1.00 / 1.00

0.9167

10.8 ms

884.8 vs 11,399.5 / 3,751.4

92.24%

76.42%

Honest v1.0-lite Diagnostic (Why v2.0-hybrid Exists): Even with natural developer queries, ~10–20% of commit queries miss top-5 when pure dense all-MiniLM-L6-v2 embeddings encounter exact camelCase identifiers, dot-separated event names (chat.message.sent), or split methods that lost their parent class Scope header. That empirical ceiling is exactly what v2.0-hybrid (AST Scope/Calls passport + LanceDB BM25+Dense RRF) and v3.0-contextual (System-1 Cross-Encoder reranking) are designed to solve.

MicroIndex Benchmark Terminal Output


Install Once, Index Any Project (Own-Project Deployment)

You do not need to copy src/ into your repositories. Install microindex-mcp once in a shared folder and point it at any codebase using TARGET and INDEXER_DATA_DIR:

1. Index Your Repository

# Stores LanceDB + index_state.json inside /path/to/your-project/.lancedb_data
make -C /path/to/microindex-mcp index TARGET=/path/to/your-project

Add .lancedb_data/ to your project's .gitignore.

(Optional) Add a 2-line shortcut to your own project's Makefile:

index:
 /path/to/microindex-mcp/.venv/bin/python -u -m src.indexer --project "$(CURDIR)" --db-dir "$(CURDIR)/.lancedb_data"

Auto-Reindex on Git Commit (Git Hooks)

To keep .lancedb_data fresh automatically after every commit without blocking git commit, add an executable .git/hooks/post-commit hook in your target repository:

cat <<'EOF' > .git/hooks/post-commit
#!/usr/bin/env bash
PROJECT_ROOT="$(git rev-parse --show-toplevel)"
HF_HUB_OFFLINE=1 /path/to/microindex-mcp/.venv/bin/python -u -m src.indexer \
  --project "$PROJECT_ROOT" \
  --db-dir "$PROJECT_ROOT/.lancedb_data" >/dev/null 2>&1 &
EOF
chmod +x .git/hooks/post-commit

2. Connect the MCP Server to Your IDE / CLI Agent

Register a stdio MCP server pointing to the shared microindex-mcp .venv and set INDEXER_DATA_DIR to your project's .lancedb_data. See templates/mcp_config.example.json for ready-to-paste configs:

{
  "mcpServers": {
    "MicroIndex": {
      "command": "/path/to/microindex-mcp/.venv/bin/python",
      "args": ["-u", "/path/to/microindex-mcp/src/mcp_server.py"],
      "env": {
        "PYTHONUNBUFFERED": "1",
        "HF_HUB_OFFLINE": "1",
        "INDEXER_DATA_DIR": "/path/to/your-project/.lancedb_data"
      }
    }
  }
}

Tip for multiple repositories (avoiding MCP context bloat):

  • Centralized Single Global MCP (Recommended for Antigravity / Global Hosts): Register one MicroIndex server without INDEXER_DATA_DIR (see centralized_global_mcp_zero_bloat in templates/mcp_config.example.json), and let your agent pass project_dir="/path/to/active-repo" to search_code / get_code_chunk. If that repo isn't indexed yet, search_code automatically instructs the agent to ask you before running make index — zero extra tool schemas in your system prompt!

  • Project-scoped hosts (Claude Code .mcp.json, Cursor .cursor/mcp.json, VS Code .vscode/mcp.json) only load the server when that project is open.

  • Zero-MCP CLI mode (for tiny repos): skip MCP altogether and query any local .lancedb_data via CLI/Python whenever needed:

    /path/to/microindex-mcp/.venv/bin/python -c "from src.indexer import search_index; print(search_index('/path/to/your-project', 'your query', top_k=5))"

3. Benchmark Your Own Repository (Auto-Generated from Git History)

Want to measure Hit@5 and token savings on your own codebase in 60 seconds? benchmarks/generate_queries.py samples random non-merge commits and builds a query suite compatible with make bench:

# 1-command benchmark on any repository (auto-generates queries + indexes + saves report)
make bench-repo TARGET=/path/to/your-project COUNT=10

# Add SHARE=1 to also generate an anonymized report, LinkedIn/X post text, and a 1200x630 SVG card:
make bench-repo TARGET=/path/to/your-project COUNT=10 SHARE=1

# Or generate a share card from any existing benchmark JSON report:
make share REPORT=benchmarks/reports/.../local__all-MiniLM-L6-v2_....json

# Or synthesize natural-language queries with a local Ollama model:
make bench-repo TARGET=/path/to/your-project COUNT=10 GEN_PROVIDER=ollama GEN_MODEL=llama3.1:8b

Privacy Warning: Using cloud LLM providers (GEN_PROVIDER=openai or GEN_PROVIDER=gemini) sends sampled commit messages and diff snippets to that external API (an interactive confirmation prompt is shown before any request). For private/NDA repositories, use offline-template (default) or ollama.

4. End-to-End Task Benchmark (pass@1 + Session Tokens)

Measure real multi-file task completion (pass@1, total session tokens, peak context, turns, wall-clock time, and estimated USD) comparing rg + Targeted (±30L) against microindex-mcp across clean, isolated git worktree checkouts (covering 4 multi-file code tasks and 3 AST-blind-spot config/doc/schema tasks):

# Offline dry-run smoke test ($0 API cost)
make e2e-eval E2E_AGENT_PROVIDER=mock E2E_REPEATS=1

# Live evaluation with Gemini / OpenAI / Anthropic / Ollama
GEMINI_API_KEY=... make e2e-eval E2E_AGENT_PROVIDER=gemini

See docs/e2e-eval.md for all agent providers, E2E_* Makefile variables, CLI flags, and the custom task JSON schema.


AI & Embedding Providers

Embedding Providers (src/embeddings.py)

Switch providers anytime via CLI flags (--provider, --model) or environment variables (MICROINDEX_EMBEDDING_PROVIDER, MICROINDEX_EMBEDDING_MODEL). If you change providers, MicroIndex automatically detects the mismatch in index_state.json and rebuilds vectors cleanly.

Provider

Env / CLI Value

Default Model

Required Env Vars

Notes

Local (default)

local

all-MiniLM-L6-v2 (384d)

HF_HUB_OFFLINE=1 (optional)

100% free, private, works offline once cached

Ollama

ollama

nomic-embed-text

OLLAMA_BASE_URL (default http://localhost:11434)

Local GPU/CPU Ollama server

OpenAI / Compatible

openai

text-embedding-3-small

OPENAI_API_KEY, optional OPENAI_BASE_URL

Works with OpenAI, OpenRouter, LM Studio, vLLM

Google Gemini

gemini

gemini-embedding-2

GEMINI_API_KEY

Gemini Generative Language API

Example with Ollama:

make index TARGET=/path/to/your-project PROVIDER=ollama MODEL=nomic-embed-text

Supported AI Hosts (MCP Clients)

src/mcp_server.py uses standard FastMCP stdio and exposes 2 minimalist tools (search_code, get_code_chunk) to avoid tool-schema overhead across any MCP-compatible host:

  • Claude Code (.mcp.json)

  • Cursor (.cursor/mcp.json)

  • Google Antigravity (~/.gemini/antigravity/mcp_config.json)

  • VS Code Copilot / Windsurf (.vscode/mcp.json)

  • Codex CLI / Gemini CLI (global MCP config)


Setting Up Agent Rules & Skills

Indexing alone is only half the win — Agentic Governance forces your AI assistant to query the AST index before calling grep or read_file:

  • templates/AGENT_RULES.md — 7 strict rules banning blind full-file scans and noisy terminal floods.

  • templates/SKILL.md — 4-step context-preparation runbook (search_code → get_code_chunk → bounded start_line..end_line → edit & re-index).

  • docs/cli-output-compression.md — rtk (Rust Token Killer) + scripts/mi-run fallback to cut noisy terminal output by 70%+ (--full to bypass).

AI Client

Where to Copy AGENT_RULES.md

Where to Copy SKILL.md

Claude Code

Append to CLAUDE.md

.claude/skills/microindex-code-discovery/SKILL.md

Cursor

.cursor/rules/microindex.mdc

.cursor/skills/microindex-code-discovery/SKILL.md

Google Antigravity

.agent/rules/microindex.md (with trigger: always_on frontmatter) or GEMINI.md / AGENTS.md

.agent/skills/microindex-code-discovery/SKILL.md

VS Code Copilot

.github/copilot-instructions.md

.github/skills/microindex-code-discovery/SKILL.md

Codex / Gemini CLI

Append to AGENTS.md or GEMINI.md

~/.agents/skills/microindex-code-discovery/SKILL.md


Adding a New Language in 60 Seconds

Out of the box, MicroIndex supports Python (.py), TypeScript / JavaScript / TSX / JSX (.ts, .tsx, .js, .jsx, .mjs, .cjs), PHP (.php), and Vue 3 SFC (.vue, two-stage HTML + TypeScript parsing with exact line_offset).

Adding Go, Rust, Java, C#, Ruby, or Kotlin takes ~15 lines of Python:


How MicroIndex Compares (Architecture Matrix)

Different tools optimize for different parts of the AI coding workflow. Here is an honest architectural comparison:

Approach / Tool

Retrieval Mechanism

Index Cost & Latency

Privacy / Cost per Query

Best Fit / Trade-offs

microindex-mcp (This repo)

Local Tree-sitter AST + LanceDB Hybrid (BM25 FTS + Dense + RRF) + AGENT_RULES.md

Fast incremental CPU index; ~10–25 ms warm query

100% local, $0/query

Cross-stack (PHP ↔ Vue ↔ Python) retrieval & 76–90%+ token savings vs rg; requires initial index build

ast-grep (sg)

Indexless structural AST pattern matching

Zero index; fast CLI scan

100% local, $0/query

Exact syntactic refactors & pattern queries; no semantic/natural-language search

endean-eng/tokenme

Static declarative TOKENME.txt map (no MCP server)

Manual / generated static file

100% local, $0/query

Great for mixed repos (PDFs/schemas/docs); scales worse across thousands of methods

can1357/jegrep

Indexless on-the-fly search via System-1 LLM judge

Zero index; LLM-latency per query

Calls external/local LLM per search

Zero index maintenance; higher per-query cost/latency and sensitive to synonyms

code-review-graph

Static call-graph stored in SQLite

Local graph build

100% local, $0/query

Ideal for PR blast-radius analysis; blind to cross-stack HTTP/API boundaries

codemesh.cloud

Managed cloud code-graph SaaS

Cloud sync required

$5–$24/seat/mo; code leaves machine

Turnkey hosted team graph; requires uploading source code to third-party cloud


Roadmap

  • v1.0-lite (Current): Local Tree-sitter AST chunking + LanceDB dense vector search + AGENT_RULES.md.

  • v2.0-hybrid (Next): Deterministic Scope: AST headers + LanceDB Hybrid BM25/Dense search + safe config/env indexing with secret redaction.

  • v3.0-contextual: Two-stage retrieval with optional local cross-encoder reranking + SWE-bench-style pass@1 evaluation suite.

  • Community: Expanding src/languages/ (Go, Rust, Java, C#, Kotlin) and OSS benchmarks via benchmarks/fetch_oss_target.sh.


License & Attribution

Released under the MIT License.

  • Repository: github.com/ingvar-soloma/microindex-mcp

  • Author: Ihor Solomianyi (ingvarsoloma.dev | LinkedIn)

  • Open-Source Attribution: If microindex-mcp saves you tokens, speeds up your team, or inspires your own tooling, please keep a link back to the original repository and credit the author when sharing benchmarks or derivatives.


Need help rolling this out across a larger team or monorepo?

microindex-mcp is MIT-licensed and free to use. If you're running a multi-team monorepo and want help setting up shared CI base snapshots, custom language/DSL extractors, or automated token-budget gates in your CI/CD pipeline, feel free to reach out via ingvarsoloma.dev or LinkedIn.

Available Tools

2 tools
get_code_chunkGet Code ChunkC

Retrieve indexed AST chunks for a known file path instead of reading the whole file.

Inputs: file_path (required), node_type. Returns: result

search_codeSearch CodeB

Semantic AST code search. Always call this before reading files or running grep.

Inputs: query (required), top_k. Returns: result

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.3/5.0

    Scored across 2 tools

    Disambiguation4/5

    The two tools target different access patterns: search_code is query-driven semantic search, while get_code_chunk is path-driven retrieval of known files. Boundaries are mostly clear, though a caller may occasionally be unsure whether to use search_code results or fetch chunks directly for a file it already knows.

    Naming Consistency5/5

    Both names use a consistent snake_case verb_noun pattern (search_code, get_code_chunk). The verbs accurately reflect their actions with no stylistic mixing.

    Tool Count3/5

    Two tools is thin for a code-index server; the surface feels minimal and leaves no room for index management or inspection operations. It is focused but borderline under-scoped.

    Completeness3/5

    The read path is covered (find code, fetch chunks), but there are notable gaps: no indexing/refresh trigger, no index status or listing of indexed files/repos, and no symbol or metadata lookup. Agents can work around these only if the index is populated externally.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      C
      maintenance
      Indexes codebases and lets AI agents retrieve precise code snippets (functions, classes, routes) instead of reading entire files, reducing token usage and improving accuracy.
      18 npm
      7
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Adds semantic code search to AI coding agents, enabling natural language queries across entire codebases to retrieve relevant code chunks, saving tokens and providing deep context.
      6 npm
      1
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      Enables AI coding agents to retrieve only the specific code sections that answer their questions, drastically reducing context usage while running fully locally.
      1
      1
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI coding agents to search indexed local codebases through AST-aware chunks with BM25 retrieval and CPU reranking, returning whole functions, classes and types instead of arbitrary token windows. It also exposes file outlines, dependency impact radius, related-test mapping, index statistics and reindexing, so agents can navigate and assess blast radius before editing without reading entire files.
      1
      MIT