DEV Community

Nerav Doshi
Nerav Doshi

Posted on Edited on Originally published at pipelineandprompts.com

Wired the Local MCP Server into Claude Code

Everything up to this point — building the Chroma index, chunking, querying — was done by hand, one Python command at a time. An MCP server is what turns that into an actual tool: a small program exposing specific capabilities to an AI client, so it can call your stuff directly instead of you running queries yourself every time. What I actually wanted to prove here wasn't that the server starts. It's that a real client can reach it and get something useful back.

The server is one small file, mcp_search_server.py, with one tool. The core of it:

import chromadb, ollama
from mcp.server.fastmcp import FastMCP

collection = chromadb.PersistentClient(path="./chroma_db").get_or_create_collection(name="today_i_ran_notes")
mcp = FastMCP("today-i-ran-notes")

@mcp.tool()
def search_notes(query: str, n_results: int = 3) -> str:
    """Search local notes and articles by meaning, not keyword match."""
    q = ollama.embeddings(model="nomic-embed-text", prompt=query)
    results = collection.query(query_embeddings=[q["embedding"]], n_results=n_results)
    ...  # formats each hit as [id] (distance) plus a 200-character snippet

if __name__ == "__main__":
    mcp.run()   # stdio at this point; Entry 14 moves it to SSE
Enter fullscreen mode Exit fullscreen mode

It runs from a virtualenv, because the system python3 didn't have the packages. If you're following along:

python3 -m venv ~/mcp-env
~/mcp-env/bin/pip install "mcp<2" chromadb ollama
Enter fullscreen mode Exit fullscreen mode

After a Connection closed error on my first attempt — Claude Code was launching a bare python3, which resolved to system Python outside the venv, missing every package the server needed — I re-registered it pointing straight at the venv's Python:

claude mcp remove today-i-ran-notes
claude mcp add today-i-ran-notes -- ~/mcp-env/bin/python3 mcp_search_server.py
claude mcp list
Enter fullscreen mode Exit fullscreen mode

I ran these from ~/Downloads. The script path is relative, and Claude Code registers MCP servers per project folder, so starting Claude Code somewhere else means registering it again.

Got a ✔ Connected back. Then, in an actual Claude Code session:

Use the today-i-ran-notes server to search for how to check pod status with oc

The tool got called — twice. Once for a broad search, then a follow-up pulling more detail from the closest match. Claude Code's own response is worth quoting in full, because it's a better result than a clean success would have been:

The search returned results, but none of them directly cover checking pod status with oc. The closest match is a note about building an "oc CLI Mentor" system prompt... but doesn't appear to include specific pod-status commands.

That's exactly right. Entry 02 is about building a constrained system prompt, not a list of pod-status commands — the tool didn't force a match that wasn't there. It said so, plainly, then answered the actual question from its own general knowledge and was clear about the difference between "your notes don't cover this" and "here's the answer anyway."

One more thing worth flagging so nobody gets confused reading this later: when I asked it to save the new commands for future reference, it saved them to Claude Code's own built-in memory feature — not to the Chroma index this whole arc has been building. Two separate systems, easy to mix up. The note lives in Claude Code's memory now, not in chroma_db.

So — the full loop actually works. A local embeddings pipeline, exposed as a real tool, correctly called by a real client, with honest reporting when the answer genuinely isn't in the index instead of a confident wrong guess. That last part is the result I actually care about here. A search tool that says "not in here" is worth a lot more than one that always returns something and leaves you to assume it's relevant.

Note (Nov 18, 2026): the Connection closed error mentioned above came from a first attempt that wasn't written up, not from an earlier entry.

Top comments (0)