Fig. 01 · Developer tools / Retrieval
Context
Compiler
The right repository context, in the hands of your AI agent.
§ 01
The problem
Coding agents are only as good as what they can see. Give them a whole repository and the useful parts drown; give them too little and they guess.
Context Compiler indexes a repository once, then answers an agent’s natural-language question with a small working set: file paths, excerpts, and the metadata that explains why each piece was selected.
§ 02
System drawing
Solid = per request · Dashed = prepared separately
- 01 · LocalMCP clientcalls search_codebase
- 02 · Localstdio bridgeforwards over HTTPS
- 03 · Next.js APIResolve accessbearer key → bound repo; invalid keys stop here
- 04 · FastAPIEmbed the queryGemini embeddings
- 05 · PostgresHybrid retrievalsemantic + lexical, ranked
- 06 · OutContext packpaths, excerpts, selection metadata
§ 03
How it came together
Scroll to step through · Mine = my work
A repository becomes an index
Repositories are scanned, chunked and embedded ahead of time, so search has something to search.
+ scan → chunk → embed+ store vectors in Postgres (pgvector)GitHubscanchunkembedindexAgents can ask through MCP
A local stdio bridge exposes search_codebase to any MCP client and forwards calls to the app over HTTPS.
+ src/mcp/server.ts — search_codebase tool+ bearer key → bound repositoryMCP clientbridgeAPIHybrid retrieval
Semantic and lexical candidates are combined and ranked, and every result carries the reason it was selected.
- semantic matches only+ semantic + lexical candidates, ranked+ selection metadata on each result- src/app/api/mcp/search/route.tsauth → repository scopelexical + semantic
- src/mcp/server.tstool invocationsemantic
- ai-backend/vector_store.pycandidate rankinglexical
No cold starts
The Python service moved to Fly.io so an agent’s first call is as fast as its tenth.
- Render (sleeps when idle)+ Fly.io, to remove cold startsNext.js · VercelFastAPI · Fly.ioPostgres · pgvector
§ 04
Decision log
- D-01
Combine semantic and lexical candidates
Code questions mix ideas (“where is access resolved?”) with exact names (authenticateMcpRequest). Ranking both kinds of match together catches what either misses alone. vector_store.py ↗
- D-02
Index once, query many times
Scanning, chunking and embedding run separately from search. A query hits an existing index, so a request never waits on a fresh clone. main.py ↗
- D-03
Fail visibly, never fake an answer
An invalid or revoked key stops at authentication. An empty search returns no matches. Neither outcome is dressed up as a generated answer. route.ts ↗
- D-04
Run the Python service on Fly.io
The FastAPI backend moved off Render to remove the cold-start delay an agent would otherwise feel on its first call.
§ 05
What I built
- Hybrid code retrievalai-backend/vector_store.py ↗
- Python search endpointai-backend/main.py ↗
- MCP tracing & result selectionsrc/lib/repository-retrieval.ts ↗
