Challenge
- Building search from scratch for each new dataset leaves every server built differently, and none of them maintainable
- Keyword search alone misses the right passage when you ask in words the source never uses
Approach
- Search, embedding and MCP replies live in one shared template; a generator script stamps out the skeleton, and only the ingest step is written per dataset
- Every query hits both SQLite full-text search (FTS5) and bge meaning vectors, and the rankings are fused. Servers talk over stdio
Outcome
- More than twenty search servers have come from the same scaffold, and all of them are updated and checked the same way
- Finding the right passage with a paraphrase the source never uses is an acceptance test before a server goes live
The author keeps many very different collections: lecture transcripts, appliance manuals, patent documents, tax papers. To ask Claude "where was that discussed?", each collection needed its own search server (MCP).
So indexing, embedding, search and MCP replies were bundled into one template. A new collection gets its skeleton from a generator script, and only one ingest file is rewritten. Indexing, embedding, live testing and registration follow the same steps every time.
The full workflow
| Task | Who | Inputs | Outputs |
|---|---|---|---|
| 1. Open task | Main session | — | Task issue |
| 2. Scaffold | Generatornew_mcp.py | Task issue, Refers to Template | Skeleton |
| 3. Write ingest | Main session | Skeleton, Source data | Ingest code |
| 4. Build index | Ingest scriptingest.py | Ingest code | Text index |
| 5. Embed | Embed scriptembed.py | Text index | Vectors |
| 6. Register | Generatornew_mcp.py | Vectors | Registration |
| 7. stdio test | New search MCPmcp_server.py | Registration, Refers to Quality gates | Live test |
| 8. Ledger & close | Main session | Live test, Task issue | Ledger |
8 steps · 4 tools · 1 loop · since 2026-08-15 · 23 servers generated · 63 commits
Stamp a skeleton from the template, write the one ingest file, build index and vectors, and enter a server in the ledger only after its replies have been seen to pass.
- The first and last steps are task tracking: open an issue before starting, write the result and close it at the end
- The only file Claude Code writes by hand is the ingest code in step 3; scripts run indexing, embedding and registration
- Step 7 decides: a question in words the source never uses must bring up the right passage, or it is back to step 3
- No person appears above the steps because, once asked, the skill carries it through; only the restart after registering is done by hand
Project folders involved (4)
This workflow does not live in one folder: it runs across projects.
- semantic-mcp-builder (template + servers)
- The core: template, generator, every generated server and the ledger
- ~/.claude/skills/mcp-semantic-builder
- The procedure, covering both new servers and maintenance
- ~/.claude.json
- User-level registration, so every project folder can search
- (private) data folders
- Lecture transcripts, manuals, tax papers and other data stay in their own projects and are read in place
Step 1 · Main session
Open tasksub-issue
Before any work, open a task whose completion can be judged.
- The title is written so that "done or not" can be decided
- The issue body automatically includes a command to come back to this session
- Only the issue counts as status; "done" said in a conversation does not
| Outputs | Task issue |
Step 2 · Generator
Scaffoldnew_mcp.py
Stamp out a new server skeleton from the template.
- The template is real, working code, not a mock-up
- If a server of that name exists, it refuses, so nobody's custom ingest gets overwritten
- The search tool's description (what is inside, when to use it) is set here
| Inputs | Task issue |
| Outputs | Skeleton |
| Refers to | Template |
Step 3 · Main session
Write ingestiter_docs()
Write the ingest code, the one file that changes per dataset.
- For each document it returns key, title, date, metadata, a source signature and the chunks, in a fixed shape
- The source may be a folder, another database or an API
- Zero documents means failure; no empty index is ever written
Claude CodeWriting this one file is the main session's job; it touches no other file
| Inputs | Skeleton, Source data |
| Outputs | Ingest code |
Step 4 · Ingest script
Build indexingest --rebuild
Build the full-text index.
- Text goes into SQLite full-text search split character by character, so Chinese and Japanese can be searched
- It reports "N ingested, M skipped" and stops with an error if N is zero
- On updates, documents whose source signature has not changed are skipped
| Inputs | Ingest code |
| Outputs | Text index |
Step 5 · Embed script
Embedembed --rebuild
Turn the text into meaning vectors.
- A locally run embedding model (768 dimensions) is used, so documents never leave the machine
- Whenever the index is rebuilt, the vectors are rebuilt too
- Jobs likely to exceed two minutes run in the background and are watched until done
Common misconceptionRebuilding the index without the vectors shifts their numbering, and search becomes quietly wrong
| Inputs | Text index |
| Outputs | Vectors |
Step 6 · Generator
Register--register
Register it as a user-level MCP server.
- It is registered per user, so every project folder can call it
- The settings file is backed up automatically before it is changed
- Claude Code must be restarted to pick it up
| Inputs | Vectors |
| Outputs | Registration |
Step 7 · New search MCP
stdio testJSON-RPC
Send three requests over stdio and read the JSON that comes back.
- Initialize, list tools and a real search must each return a reply
- Semantic search passes only if a question in words the source never uses finds the right passage
- In the first real case, two paraphrased questions both landed on the intended passage
Common misconceptionAn exit code of 0 is no proof the server works; look at the replies themselves
| Inputs | Registration |
| Outputs | Live test |
| Refers to | Quality gates |
Step 8 · Main session
Ledger & closeissue close
Add a ledger row, commit, then write the result and close the task.
- The ledger row records where the data is, what it holds and where it is registered
- Server code always goes into the repository; indexes, keys and credentials never do
- Before closing, the issue gets what was done, the acceptance test and the data size; leftovers become new issues
| Inputs | Live test, Task issue |
| Outputs | Ledger |
Loops and rework
- Paraphrase misses → step 3: Fix the ingest code, rebuild index and vectors, test again. In the first real case the author asked for a wider scope after testing, and the server was rebuilt and retested
Key points
Only one file changes. The ingest step just returns each document's key, title, date and chunks in a fixed shape; from there the template's real code handles indexing, search and replies. The generator refuses to run if a server of that name already exists, so nobody's custom ingest gets overwritten.
Decide up front how things are allowed to fail. If ingest finds zero documents it fails instead of writing an empty index, and rebuilding the index always means rebuilding the vectors, because text and vectors that drift out of step make search quietly wrong.
Check the replies, not the exit code. Initialize, list tools and run a real search over stdio, and look at the JSON that comes back. Then ask with words the source never uses: if the right passage comes up, the server passes as semantic search.