github-vault-mcp
# github-vault-mcp
Local-first Model Context Protocol (MCP) server that indexes all public and private GitHub repositories of a user (`carvalhocaio` by default) into a local SQLite FTS5 knowledge base.
AI coding agents (Antigravity CLI, Claude Code CLI) can query your own repositories during planning and implementation to reuse established architectures, toolchains, CI gates, and domain patterns instead of reinventing them.
## Key Features
- **Local-First SQLite FTS5 Search**: Fast full-text search with safe query sanitization (handles hyphens like `karasu-eval`, slashes, colons, and boolean keywords without syntax errors).
- **BM25 Column Weighting**: Prioritizes matches in `repo_name` (`10.0`), `file_path` (`8.0`), `repo_description` (`5.0`), and `repo_topics` (`5.0`) over generic `content` (`1.0`), surfacing `README.md` and domain-named repositories first.
- **Incremental GitHub Sync & Pruning**: Compares each repository's `pushed_at` timestamp against the local database, skips unchanged repositories unless `--force` is passed, and automatically prunes repositories deleted on GitHub from `repositories`, `files`, and `files_fts`.
- **Automatic Background Sync**: On MCP server startup, checks `last_global_sync_at` and runs a non-blocking background sync if the configured `VAULT_AUTO_SYNC_HOURS` TTL has elapsed (protected by a SQLite WAL lock so concurrent clients do not collide).
- **Concurrent Blob Ingestion**: Fetches recursive git trees and downloads blobs concurrently with `httpx.AsyncClient` and `asyncio.Semaphore(10)`.
- **Zero-Friction Auth**: Resolves your token via `gh auth token` first, falling back to `GITHUB_TOKEN`.
- **Strict Noise Filtering**: Indexes only code, docs, and config files under 150 KB while excluding lockfiles and build/cache directories.
## Architecture Overview
```mermaid
flowchart LR
CLI["cli.py<br/>(stdio MCP or sync)"] --> MCP["interfaces/mcp/server.py<br/>(FastMCP tools & prompt)"]
CLI --> SyncSvc["application/sync_service.py"]
MCP --> SyncSvc
MCP --> Store["infrastructure/sqlite_store.py<br/>(SQLite + FTS5 BM25)"]
SyncSvc --> GH["infrastructure/github_client.py<br/>(gh CLI / GITHUB_TOKEN + httpx)"]
SyncSvc --> Store
SyncSvc --> Domain["domain/<br/>(models, filters, exceptions)"]
GH --> Domain
Store --> Domain
```
- `domain/`: Immutable Pydantic models, domain exceptions, and pure file-filtering rules.
- `infrastructure/`: GitHub REST client (`github_client.py`) and SQLite FTS5 persistence (`sqlite_store.py`).
- `application/`: Incremental `pushed_at` synchronization orchestrator (`sync_service.py`).
- `interfaces/mcp/`: `FastMCP` (`stdio`) server exposing 4 tools and 1 planning prompt (`server.py`).
## Installation & Initial Sync
### Prerequisites
- Python 3.12+
- [`uv`](https://docs.astral.sh/uv/)
- Authenticated GitHub CLI (`gh auth login`) or a `GITHUB_TOKEN` environment variable with `repo` read access
### Setup
```bash
cd /home/clancy/www/github-vault-mcp
uv sync
```
Run an initial repository index from your terminal (optional—the MCP server also triggers a background sync automatically on first startup):
```bash
uv run github-vault-mcp sync
```
To force a full re-index regardless of `pushed_at` timestamps:
```bash
uv run github-vault-mcp sync --force
```
## Registering with AI Coding Agents
### Antigravity (`agy`)
Add the server to your Antigravity MCP configuration (`~/.gemini/config/mcp_config.json` or project `.mcp.json`):
```json
{
"mcpServers": {
"github-vault": {
"command": "uv",
"args": [
"--directory",
"/home/clancy/www/github-vault-mcp",
"run",
"github-vault-mcp"
]
}
}
}
```
### Claude Code CLI
Register via CLI:
```bash
claude mcp add github-vault -- uv --directory /home/clancy/www/github-vault-mcp run github-vault-mcp
```
Or add directly to `~/.claude.json`:
```json
{
"mcpServers": {
"github-vault": {
"command": "uv",
"args": [
"--directory",
"/home/clancy/www/github-vault-mcp",
"run",
"github-vault-mcp"
]
}
}
}
```
## MCP Tools & Prompt Reference
| Primitive | Type | Parameters | Purpose |
| --- | --- | --- | --- |
| `search_my_repositories` | Tool | `query`, `repo_filter?`, `file_extension?`, `limit=8` | Weighted BM25 search across indexed repos, returning focused snippets |
| `get_project_blueprint` | Tool | `repo_name` | Returns metadata, file tree, full `README.md`, and key manifests (`pyproject.toml`, `package.json`, `Makefile`, `go.mod`, `Cargo.toml`, `Dockerfile`) |
| `read_repository_file` | Tool | `repo_name`, `file_path`, `start_line=1`, `end_line=200` | Reads a specific 1-based line range from an indexed file |
| `sync_repositories` | Tool | `force=False` | Runs incremental (or forced) GitHub sync and returns summary counts |
| `plan_with_personal_vault` | Prompt | `task_description` | Guides the agent to search your vault, inspect top blueprints, cross-reference Context7/docs, and synthesize an aligned plan |
## Indexing & Filtering Rules
- **Included Extensions**: `.py`, `.ts`, `.tsx`, `.js`, `.go`, `.rs`, `.md`, `.toml`, `.yaml`, `.yml`, `.json`, `.sql`, `.sh`
- **Included Exact Filenames**: `Makefile`, `Dockerfile`
- **Excluded Filenames**: `uv.lock`, `package-lock.json`, `pnpm-lock.yaml`, `yarn.lock`, `poetry.lock`, `.gitignore`, `.DS_Store`
- **Excluded Directories**: `.git/`, `.venv/`, `venv/`, `node_modules/`, `__pycache__/`, `dist/`, `build/`, `.pytest_cache/`, `.ruff_cache/`
- **Max File Size**: `150 KB` (`153,600` bytes) per file
## Environment Variables
| Variable | Default | Description |
| --- | --- | --- |
| `VAULT_DB_PATH` | `~/.local/share/github-vault-mcp/vault.db` | Local SQLite FTS5 database path |
| `GITHUB_TOKEN` | `None` | Fallback token when `gh auth token` is unavailable |
| `VAULT_GITHUB_USER` | `carvalhocaio` | Default GitHub owner handle |
| `VAULT_INCLUDE_FORKS` | `false` | Include forked repositories during sync |
| `VAULT_AUTO_SYNC_HOURS` | `6.0` | Hours before MCP startup triggers a background sync (`0` disables auto-sync) |
## Development
```bash
make sync # Install runtime and dev dependencies
make check # Run ruff check, ruff format --check, pyright, and pytest
make lint-fix # Auto-fix ruff lint issues
make format # Format codebase with ruff
make audit # Run pip-audit vulnerability check
make clean # Remove caches and build artifacts
```
## License
This project is licensed under the [MIT License](LICENSE).
TDQS
Scored across 4 tools
Each tool targets a distinct step in a clear pipeline: sync the vault, search it, get a repository-wide blueprint, then read a specific file range. The descriptions explicitly sequence the tools (search -> blueprint -> read_repository_file), so an agent can tell exactly which one to pick. No two tools appear interchangeable.
All four names follow a consistent verb_noun snake_case pattern (search_my_repositories, get_project_blueprint, read_repository_file, sync_repositories). The wording is predictable and self-documenting.
Four tools is a tight, well-scoped surface for a read-only local repository vault: one ingestion tool and three retrieval tools. Each tool earns its place with no filler or near-duplicates.
The lifecycle from indexing to targeted retrieval is fully covered, including incremental sync. The main gap is the absence of a list-repositories or directory-listing tool, meaning the agent must already know exact repo names and file paths, though search_my_repositories partly compensates.