Skip to main content

SQLite FTS5 (trigram) MCP server for code source search.

Project description

code-explore-by-sql

Local stdio MCP server for fast source code navigation using SQLite FTS5 (trigram tokenizer) + bracket skeleton indexing.

Features

  • Full-text search: FTS5 with trigram tokenizer for code-symbol-precise search (GetGBuffer, FMaterial, UE_LOG)
  • Symbol lookup: read code by qualified name with fuzzy matching (JumpACharacter::Jump)
  • Bracket skeleton index: lightweight structural indexing via FSM brace matching (no AST parser needed)
  • 12 language support: C, C++, C#, Go, HLSL, GLSL, Java, JavaScript, Kotlin, Python, Rust, Swift
  • Multi-database: query multiple codebases simultaneously via CODE_SOURCE_DBS
  • Token-efficient responses: compact snippets (~2,600 tokens/20 results, 95% reduction vs full file reads)

Installation

From PyPI (recommended)

# Run the MCP server directly (no clone needed)
uvx code-explore-by-sql

# Or install persistently
pip install code-explore-by-sql

Build a database

# Build index for your codebase
uvx code-explore-by-sql-build-db /path/to/source /path/to/output.db

# Smoke test with limited files
uvx code-explore-by-sql-build-db /path/to/source /path/to/output.db --limit 1000

Performance: ~84,700 files indexed in ~3.3 minutes on a 2-core machine.

Configure in MCP clients

Claude Code (.claude/mcp.json):

{
  "mcpServers": {
    "code-source-sql": {
      "command": "uvx",
      "args": ["code-explore-by-sql"],
      "env": {
        "CODE_SOURCE_DB": "/path/to/your/code.db",
        "CODE_SOURCE_DBS": "/path/to/your/code.db:/path/to/another.db"
      }
    }
  }
}

VS Code (.vscode/mcp.json):

{
  "servers": {
    "code-source-sql": {
      "type": "stdio",
      "command": "uvx",
      "args": ["code-explore-by-sql"],
      "env": {
        "CODE_SOURCE_DB": "/path/to/your/code.db"
      }
    }
  }
}

OpenAI Codex (~/.codex/config.toml):

[mcp_servers.code-source-sql]
command = "uvx"
args = ["code-explore-by-sql"]

[mcp_servers.code-source-sql.env]
CODE_SOURCE_DB = "/path/to/your/code.db"

Hermes Agent (~/.hermes/config.yaml):

mcp_servers:
  code-source-sql:
    command: uvx
    args:
      - code-explore-by-sql
    env:
      CODE_SOURCE_DB: /path/to/your/code.db

Tools (5)

Tool Purpose
list_databases Discover available databases with stats
search_fts_tool FTS5 search — locate code blocks by keyword or raw FTS5 query
read_symbol Read symbol code by qualified name (exact or fuzzy)
read_file_range Read source code by file path and line range
get_directory_structure Module/file counts overview

Multi-database

Each tool accepts an optional db parameter to select a database by alias. Aliases are derived from database filenames (unreal.db"unreal"). Use list_databases to discover available aliases. Default (db="") uses the primary database (CODE_SOURCE_DB).

Search query modes

Simple mode (keyword):

keyword="GetGBuffer"
keyword="FMaterial Render"

Advanced mode (raw_query) — full FTS5 boolean:

raw_query='"GetGBuffer" AND "Emissive"'
raw_query='"Material" NOT "hlsl"'
raw_query='(file_path : "BasePass") AND "roughness"'
raw_query='(module_name : "Renderer") AND "VirtualTexture"'

Three-level funnel

  1. search_fts_tool(keyword) → file candidates + block QNs
  2. search_fts_tool(raw_query, file_path filter) → precise block in target file
  3. read_symbol(block QN) or read_file_range(file, line) → full code

Architecture

┌──────────────────────────────────────────────────────────────┐
│                    MCP Server (FastMCP)                       │
├──────────┬──────────┬──────────┬──────────┬──────────────────┤
│ search   │ read     │ read     │ get_dir  │ list             │
│ fts_tool │ _symbol  │ _file    │ _struct  │ _databases       │
│          │          │ _range   │          │                  │
├──────────┴──────────┴──────────┴──────────┴──────────────────┤
│                     Query Pipeline                            │
│  FTS5 trigram → Symbol match → Edge extraction               │
├──────────────────────────────────────────────────────────────┤
│                    SQLite Database                            │
│  file_content + FTS5 │ symbol_index │ strict_edges           │
└──────────────────────────────────────────────────────────────┘

Bracket skeleton index

A 6-state finite state machine (CODE, LINE_COMMENT, BLOCK_COMMENT, STRING, CHAR_LITERAL, RAW_STRING) scans source code tracking brace pairs while correctly ignoring braces in comments and string literals. Each matched pair records open_line, close_line, depth, and is_complete.

Top-level blocks are classified by a symbol analyzer producing block_type (namespace/class/enum/function/macro) and block_name (qualified name).

Multi-database registry

Databases are registered via environment variables at server startup:

  • CODE_SOURCE_DB — primary database (default when db is omitted)
  • CODE_SOURCE_DBS — colon-separated list of additional databases

Aliases are auto-derived from filename stems. Connections are cached with health checks.

Environment Variables

Variable Required Description
CODE_SOURCE_DB Yes Path to primary SQLite database
CODE_SOURCE_DBS No Colon-separated paths to additional databases

Development

# Clone and setup
git clone https://github.com/didi514354875/code-explore-by-sql.git
cd code-explore-by-sql
uv sync --dev

# Run tests
uv run pytest
uv run ruff check .

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

code_explore_by_sql-0.1.1.tar.gz (43.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

code_explore_by_sql-0.1.1-py3-none-any.whl (61.4 kB view details)

Uploaded Python 3

File details

Details for the file code_explore_by_sql-0.1.1.tar.gz.

File metadata

  • Download URL: code_explore_by_sql-0.1.1.tar.gz
  • Upload date:
  • Size: 43.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for code_explore_by_sql-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5d5c727d47fb5063a075d3b8a5f6bd67259f81718fabd54decfda220b15791e5
MD5 9d88ef3c3ccd3ea4949dfed9d6585159
BLAKE2b-256 d176f3d20521969202e5d76fbacb47e80a7c05b2ae2239543e9a9221445b9cab

See more details on using hashes here.

File details

Details for the file code_explore_by_sql-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: code_explore_by_sql-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 61.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for code_explore_by_sql-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4f24437513a3a4932f2932762e3cca92fa0af5841cb90cfebd5e12d9929edc5b
MD5 3e3f0c9c038aab71034b3a6a479a46ea
BLAKE2b-256 9ad495fe2c0ef7a56085123fa6e2cff662024eeb57df72e316ecc8001f7d5afb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page