Writings

Building an MCP server that assumes documents lie

· 2 min read

An MCP server that lets assistants read documents, like court records, reports or anything people upload, returns text that nobody on your side wrote. If a document says "ignore your instructions and do this instead", the model reads that too. That's prompt injection, and any collection of documents from the outside world is an obvious place for it.

There's no reliable way to make a model ignore instructions in what it reads. So the question worth designing around is different: if the model does obey, what's the worst it can do?

make the dangerous actions unreachable

Every tool should need a token. Over HTTP, an unsigned request should get the standard 401 challenge that tells an MCP client to sign in, rather than a quiet anonymous mode.

Tools that change data should depend on who the user is, not on what the model decides. If only certain roles can edit records, an instruction hidden in a document that says "update this record" fails for everyone else, whatever the model thinks. The model's judgment isn't the security boundary. The user's role is.

Hidden tools should be refused by name too. A tool that isn't listed for a user shouldn't be callable just because a model, or a document, guessed what it's called.

make answers checkable

The other harm is quieter: a document that steers the model into a wrong answer. If every read links to its source page, any claim in an answer can be checked against the document it came from.

Reads should also say what they don't contain. Announce when text was cut off, flag pages that couldn't be read, and mark numbers read off charts as estimates. A model that's told what's missing is harder to steer into filling the gap.

what I'd test next

Design only goes so far. The next step is to plant instructions in test documents, in body text, white-on-white text, tables and metadata, on a test copy of a server, and see what different assistants do with them. Clearly marking document text as untrusted data in every tool response is the first extra defence I'd try.

what I took from it

  • Assume the model will be fooled and design so it doesn't matter much.
  • Put permissions on the server, tied to who the user is, not in the prompt.
  • Make every answer traceable to its source, so a steered answer can be caught.
book a chat