Your search tool should say no: building an MCP server for an unreliable caller
An agent with a search tool makes typos. It writes platfrom:hn instead of platform:hn, or it asks for a field that exists in one index and not the one it's querying. What happens next depends on the server. Many search engines drop the clause they can't read and answer the rest. The tool call succeeds, the agent gets a confident list of hits, and nothing tells it the hits answer a different question.
For a human at a search box that's a minor annoyance, because you look at the results and notice. An agent doesn't notice. It reasons over what came back.
I build CameoDB, a search database (full-text, key-value and documents in one Rust binary) with an MCP server built in. This post is about the design choices in that MCP surface, made with that caller in mind.
A wrong answer is worse than an error
Here is a real call to search_index with the typo from above, on an index of about 2,900 tech-community posts:
{"index": "marketing", "query": "platfrom:hn AND title:mcp", "limit": 2} The response is isError: true:
Query rejected: part of this query could not be interpreted and was dropped, so the results would not be the ones asked for. - unknown field 'platfrom' — the clause naming it was dropped, so this result set does not match what the query asked for Rewrite the query and retry. `describe_index` lists the fields this index actually has, with the operators each field's type supports. No hits. The agent is told what was wrong and which tool shows the real fields. With platform spelled right, the same call returns 72 hits.
The same rule covers a quieter trap: a field that only showed up in later writes, and so was never indexed. A search naming it is refused on the MCP surface rather than answered with nothing.
If the agent wants to check first, validate_query is a tool too. It returns the recognized and unknown fields, the clauses that would be discarded, and for each field its type and how it matches ("Words in any case, English stemmed: running finds runs"), all before anything runs.
Teach the schema instead of hoping
An agent arrives knowing nothing about your data. Whatever it does is bounded by what it can read from list_indexes and describe_index, so those carry as much as possible:
- the index and field
descriptionyou write, verbatim. The schema is the only place that says what the data is, and an index without descriptions asks the agent to guess from names. - each field's type, tokenizer, and whether it is searchable, sortable and returned.
- a
query_hintper type naming the operators that work on it, and atokenizer_hintsaying how matching behaves.
That's also what makes field projection usable. search_index takes a fields list, and an agent that has read describe_index can ask for three fields instead of whole documents. On one of our indexes that cut search-result tokens by 91–96%.
Read-only, and scoped by the key
The surface is six tools: list_indexes, describe_index, validate_query, search_index, search_across_indexes and get_catalog_stats. All six are reads and are annotated readOnlyHint: true. Ingestion happens through the HTTP API, outside the agent's reach.
An MCP client authenticates with the same bearer key as the REST API, and the key's capabilities and allowed_indexes apply unchanged. The tool catalogue itself is filtered to what the key may call, so the agent is never offered a tool it would be refused for.
Clients that can't set headers (claude.ai, ChatGPT, Claude Desktop connecting by URL) sign in with OAuth instead. The token they receive acts as the user's key with read only, on /mcp only.
Native means no sidecar
MCP is served on the same HTTP listener as the REST API: POST /mcp for Streamable HTTP, plus the older HTTP+SSE transport for clients that haven't moved. There is no separate MCP process to deploy, version and keep in sync with the database. When the schema changes, the tools describe the new schema. A node whose callers don't need MCP turns it off with enabled = false under [mcp].
Connecting Claude Code to a local node:
claude mcp add --transport http cameodb http://localhost:9480/mcp Setup for Claude Desktop, Cursor, Devin and the MCP Inspector is in the MCP client guide.
What it costs
Teaching has a price. I measured the tool catalogue the server returns from tools/list: about 27 KB, roughly 6,800 tokens, loaded once per session. Most of it is search_index (16 KB), because its description carries the query syntax reference: phrases, ranges, regex, IN lists and per-type operators. The alternative is an agent that guesses the syntax and retries, and every failed round trip also costs tokens and time. I'd still like that number smaller, and it's the next thing I'm looking at.
Try it
CameoDB is a single binary: downloads, source and docs on GitHub. The operator side of MCP (mounting, securing, shaping an index for agents) is in docs/MCP.md.
I'd like to hear how your agents fail with search tools. Silent wrong answers, retries, syntax guesses: what have you seen?