Semantic-search MCP builder workflow

Adds a semantic-search MCP for each local document set by editing a single file.

#MCP#semantic search#SQLite FTS5#vector search#scaffold
Semantic-search MCP scaffold

WorkflowSemantic-search MCP scaffold

Search & MCP Claude Code (user-level MCP)

A scaffold for building search servers Claude can query, one per kind of material: lecture transcripts, manuals, patents, mail. It combines full-text search with meaning vectors, and only the one ingest file changes per dataset.

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

TaskWhoInputsOutputs
1. Open taskMain session—Task issue
2. ScaffoldGeneratornew_mcp.pyTask issue, Refers to TemplateSkeleton
3. Write ingestMain sessionSkeleton, Source dataIngest code
4. Build indexIngest scriptingest.pyIngest codeText index
5. EmbedEmbed scriptembed.pyText indexVectors
6. RegisterGeneratornew_mcp.pyVectorsRegistration
7. stdio testNew search MCPmcp_server.pyRegistration, Refers to Quality gatesLive test
8. Ledger & closeMain sessionLive test, Task issueLedger
Semantic-search MCP scaffold

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
Open task

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
OutputsTask issue
Scaffold

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
InputsTask issue
OutputsSkeleton
Refers toTemplate
Write ingest

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

InputsSkeleton, Source data
OutputsIngest code
Build index

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
InputsIngest code
OutputsText index
Embed

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

InputsText index
OutputsVectors
Register

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
InputsVectors
OutputsRegistration
stdio test

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

InputsRegistration
OutputsLive test
Refers toQuality gates
Ledger & close

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
InputsLive test, Task issue
OutputsLedger

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.