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 (
Jump→ACharacter::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-source-sql-build-db /path/to/source /path/to/output.db
# Smoke test with limited files
uvx code-source-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
search_fts_tool(keyword)→ file candidates + block QNssearch_fts_tool(raw_query, file_path filter)→ precise block in target fileread_symbol(block QN)orread_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 whendbis 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file code_explore_by_sql-0.1.0.tar.gz.
File metadata
- Download URL: code_explore_by_sql-0.1.0.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2fcb3144cb3eee26db016cfe52b3e2919a90fef00a187b7359133e6b5704b997
|
|
| MD5 |
5c57719fa5f76b9c6cec3d0aeeaba424
|
|
| BLAKE2b-256 |
636acc5fc432a35e1260bf90b71b1ac7985cc9f4d3a3b7dafa9f261edc7af716
|
File details
Details for the file code_explore_by_sql-0.1.0-py3-none-any.whl.
File metadata
- Download URL: code_explore_by_sql-0.1.0-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81cd1a070dabc6f055fa3fc0ca2977e0f6651c974c3241867e2ba1193c6f3a23
|
|
| MD5 |
34de1c727e0a4b9a219c2b39e554280f
|
|
| BLAKE2b-256 |
2757ae5ce785103b79d71ff66b1957042d3218434099b0c5b4e2412759a5a533
|