{"id":49504114,"url":"https://github.com/chadbohannan/py-mcp-code-rag","last_synced_at":"2026-05-01T13:33:26.346Z","repository":{"id":349643978,"uuid":"1164985758","full_name":"chadbohannan/py-mcp-code-rag","owner":"chadbohannan","description":"Code oriented Retrieval Augmented Retrieval system using Semantic Surrogate Indexing","archived":false,"fork":false,"pushed_at":"2026-04-22T17:07:59.000Z","size":438,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-04-22T18:19:33.126Z","etag":null,"topics":["ai-agents","code-analysis","rag","tools"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chadbohannan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-02-23T17:46:09.000Z","updated_at":"2026-04-22T16:16:10.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/chadbohannan/py-mcp-code-rag","commit_stats":null,"previous_names":["chadbohannan/py-mcp-code-rag"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/chadbohannan/py-mcp-code-rag","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chadbohannan%2Fpy-mcp-code-rag","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chadbohannan%2Fpy-mcp-code-rag/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chadbohannan%2Fpy-mcp-code-rag/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chadbohannan%2Fpy-mcp-code-rag/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chadbohannan","download_url":"https://codeload.github.com/chadbohannan/py-mcp-code-rag/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chadbohannan%2Fpy-mcp-code-rag/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32499683,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"online","status_checked_at":"2026-05-01T02:00:05.856Z","response_time":64,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai-agents","code-analysis","rag","tools"],"created_at":"2026-05-01T13:33:22.614Z","updated_at":"2026-05-01T13:33:26.321Z","avatar_url":"https://github.com/chadbohannan.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# code-rag\n\nSemantic code search over local codebases, exposed as an [MCP](https://modelcontextprotocol.io/) stdio server. Designed for navigating complex, sprawling codebases — surfacing architectural intent rather than matching surface text.\n\n## How it works\n\nRaw source code embeds poorly against natural language queries. A developer asking \"how does authentication work?\" shares almost no embedding space with the code that implements it.\n\n**code-rag** uses Semantic Surrogate Indexing: files are parsed into language-aware units (functions, classes, methods, SQL, markdown sections), each unit is summarized by Claude, and the *summary* — not the raw source — is embedded. The raw source is stored alongside and returned on a match.\n\n```\nsource file → semantic parser → semantic units\n                                      │\n                              semantic summary\n                              (file path + unit type as context)\n                                      │\n                              fastembed → vector index\n                              raw source stored alongside, returned on match\n```\n\nThis means queries like \"how does token expiry work?\" match a summary like *\"Validates a JWT and checks clock skew against a configurable tolerance\"* — something raw source embedding cannot achieve.\n\n## Requirements\n\n- Python \u003e= 3.12\n- [uv](https://github.com/astral-sh/uv) package manager\n- [Ollama](https://ollama.com/) with gemma4:e2b\n\n## Quickstart\n\n```bash\n# Install dependencies\nmake install\n\n# Index a codebase\nmake index SRC=../my-project DB=./index.db\n\n# Start the MCP server\nmake serve DB=./index.db\n```\n\n## Installation\n\n```bash\ngit clone \u003crepo-url\u003e\ncd py-mcp-code-rag\nmake install\n```\n\n## Usage\n\n### CLI\n\n```\ncode-rag index [paths...] [options]    Build or update the index\ncode-rag serve [options]               Start the MCP server (stdio)\n```\n\n### Indexing\n\nIndex one or more directories. Incremental by default — only changed files are re-processed.\n\n```bash\n# Index the current directory\ncode-rag index .\n\n# Index specific directories into a single DB\ncode-rag index /path/to/backend /path/to/frontend\n\n# Use a custom database path\ncode-rag index --db myproject.db ../my-project\n\n# Rebuild embeddings after changing the embed model (preserves summaries)\ncode-rag index --reindex .\n\n# Use Ollama for summarization instead of Anthropic API\ncode-rag index --summarizer ollama --ollama-model gemma3 .\n```\n\n**Index options:**\n\n| Flag | Default | Description |\n|---|---|---|\n| `--reindex` | off | Rebuild vector table; preserves summaries for unchanged units |\n| `--embed-model MODEL` | `nomic-ai/nomic-embed-text-v1.5-Q` | Embedding model (fastembed) |\n| `--db PATH` | `./index.db` | Index file location |\n| `--summarizer {anthropic,ollama}` | `ollama` | Summarization backend |\n| `--ollama-model MODEL` | — | Ollama model name |\n| `--ollama-host HOST` | — | Ollama API host |\n\n### Serving\n\nStart the MCP stdio server. Read-only — no API key required.\n\n```bash\ncode-rag serve --db index.db\n```\n\n**Serve options:**\n\n| Flag | Default | Description |\n|---|---|---|\n| `--db PATH` | `./index.db` | Index file location |\n\n### Agent integration\n\nRegister code-rag with your agent of choice. Both commands accept `DB=` to point at a non-default index file.\n\n| Agent | Register | Unregister |\n|---|---|---|\n| Claude Code | `make add-claude-mcp` | `make remove-claude-mcp` |\n| pi-agent | `make add-pi-mcp` | `make remove-pi-mcp` |\n\n#### System prompt\n\nFor best results, include the following in your agent's system prompt or persona config:\n\n\u003e code-rag is a stdio RAG server for an index of code repositories indexed to accelerate design, debugging, and discovery of relevant code prior to the use of filesystem tools. Use code-rag for vague or exploratory queries about a codebase; start with `index_status` then discover relevant code using the search tool with natural language topic descriptions.\n\nFor agents that support per-project instruction files (e.g. `AGENTS.md` for Claude Code), place this text there so it applies automatically whenever you work in an indexed repo.\n\n## Make targets\n\nAll targets that operate on a source directory accept `SRC=` (defaults to `.`). Targets that use the index database accept `DB=` (defaults to `index.db`).\n\n| Target | Description | Example |\n|---|---|---|\n| `install` | Install all dependencies | `make install` |\n| `index` | Index a directory (incremental) | `make index SRC=../repo DB=my.db` |\n| `reindex` | Rebuild embeddings from scratch | `make reindex SRC=../repo` |\n| `serve` | Start MCP stdio server | `make serve DB=my.db` |\n| `test` | Run full test suite | `make test` |\n| `test-unit` | Run unit tests only | `make test-unit` |\n| `test-integration` | Run integration tests | `make test-integration` |\n| `lint` | Check code style | `make lint` |\n| `format` | Auto-format code | `make format` |\n| `add-claude-mcp` | Register with Claude Code | `make add-claude-mcp` |\n| `remove-claude-mcp` | Unregister from Claude Code | `make remove-claude-mcp` |\n| `add-pi-mcp` | Register with pi-agent | `make add-pi-mcp` |\n| `remove-pi-mcp` | Unregister from pi-agent | `make remove-pi-mcp` |\n| `clean` | Remove index.db and WAL files | `make clean` |\n\n## Supported file types\n\n| Extension | Parser | Unit boundaries |\n|---|---|---|\n| `.py` | stdlib `ast` | module-level function, class, method |\n| `.go` | tree-sitter (Go) | function, method, struct, interface |\n| `.c`, `.h` | tree-sitter (C) | function, struct, enum |\n| `.cc`, `.cpp`, `.cxx`, `.hh`, `.hpp`, `.hxx`, `.ino` | tree-sitter (C++) | function, method, class, struct, enum |\n| `.js`, `.jsx`, `.mjs`, `.cjs` | tree-sitter (JavaScript) | function, class, method, arrow function |\n| `.ts`, `.tsx`, `.mts`, `.cts` | tree-sitter (TypeScript) | function, class, method, interface, type, enum |\n| `.java` | tree-sitter (Java) | class, interface, enum, method, constructor |\n| `.tf` | HCL block splitter | resource, variable, output, module, data, locals, … |\n| `.tfvars` | document-level | whole file |\n| `.md`, `.mdx` | heading splitter | heading sections |\n| `.sql` | document-level | whole file (skipped if \u003e 4 KB) |\n\nBinary files are detected and skipped automatically. Unrecognized extensions are skipped silently.\n\n## MCP tools\n\n### `search`\n\n| Parameter | Type | Default | Description |\n|---|---|---|---|\n| `query` | `str` | required | Natural language question about the codebase |\n| `top_k` | `int` | `5` | Number of results (max 20) |\n\nReturns matching source units ranked by cosine similarity, each with file path, unit type/name, original source content, summary, and relevance score.\n\n### `index_status`\n\nNo parameters. Returns per-root statistics: file count, unit count, and last indexed timestamp.\n\n## Architecture\n\n- **Embeddings**: [fastembed](https://github.com/qdrant/fastembed) in-process via ONNX Runtime (`nomic-ai/nomic-embed-text-v1.5-Q`, 768-dim)\n- **Storage**: SQLite (WAL mode) + [sqlite-vec](https://github.com/asg017/sqlite-vec) — documents, metadata, and vectors in a single file\n- **Summarization**: Anthropic API (Claude Haiku) or Ollama, index-time only\n- **MCP transport**: stdio (default)\n\n## License\n\nSee [LICENSE](LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchadbohannan%2Fpy-mcp-code-rag","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchadbohannan%2Fpy-mcp-code-rag","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchadbohannan%2Fpy-mcp-code-rag/lists"}