Skip to content
All writing

MCP · Privacy · October 22, 2026 · 6 min

Keep PII out of the context window

Designing an MCP server for identity verification forced a rule I now apply everywhere: the model should be able to act on sensitive data without ever seeing it.

Speedmap is identity-verification infrastructure for Nigeria: NIN and BVN checks, face liveness and match, document OCR, business verification, sanctions screening. It is the kind of system that exists to handle the most sensitive data a person has. It also ships an MCP server, so that AI agents (any MCP client, a LangChain pipeline, an AI SDK app) can verify a person as a tool call.

Those two sentences should make you nervous. They made me nervous. The design that came out of that nervousness is a rule I now apply to every agent integration: the model must be able to act on sensitive data without ever seeing it.

The naive version

The obvious MCP tool is verify_identity(nin, first_name, last_name, dob). The agent collects those values from a conversation, calls the tool, gets back a match result and probably the government record, and continues.

Now trace where the data went. The NIN is in the agent's context window. It is in the provider's logs, subject to whatever retention that provider has. It is in your own trace store if you log tool calls (you should). It is potentially in the next tool call's arguments, because the model has it and models are helpful. And the response put the full record, photo, address, and phone, into the same place.

You have turned an LLM provider into a sub-processor of government identity data, and you did it by accident.

Reference, don't carry

The design Speedmap uses instead has three moves.

Capture happens outside the model. When an agent needs a person verified, the tool does not accept raw identifiers. It creates a verification session and returns a hosted capture link: a page in English, Pidgin, Hausa, Yoruba, or Igbo where the person enters their own details and consents. The model's job is to hand the link to the person and wait. It never sees the NIN.

The model sees references, not records. Every verification is addressed by an opaque session ID. The agent can check status, read a normalized outcome (matched, not matched, review needed), and read a small set of non-sensitive signals. It cannot pull the underlying record through the MCP surface at all. If a downstream human needs the record, that is a dashboard action with its own audit entry, not a tool result.

The result is a decision, not data. What the agent actually needs is a boolean and a reason code. Designing the tool to return exactly that, and nothing richer, removes the temptation to ask the model to "summarize the applicant" from a response full of fields it should not have.

The pattern generalizes far beyond identity. Any time a tool returns sensitive data to a model, ask whether the model needs the data or needs a decision made from the data. It is almost always the latter.

The cost of doing it right

There is a real cost. The naive tool is one call; the referenced version is a session, a link, a wait, and a status poll. Agents are worse at multi-step flows than single calls, and you have to design the tool descriptions carefully so the model understands it should hand the link over rather than try to fill the form itself.

I think the cost is worth it for two reasons.

First, consent. A person entering their own details on a page they can read in their own language, with a consent checkbox, is a legally and ethically different act than a chatbot extracting those details from a conversation. The hosted flow is not just a privacy mechanism; it is how consent becomes real.

Second, blast radius. If the agent is compromised, whether by prompt injection, a bad tool in the same session, or a model misbehaving, the attacker gets session IDs and reason codes. That is a bad day. Getting a context window full of identity numbers is a breach notification.

Make it the default in the server, not the prompt

The last point is the one I would underline. Do not rely on the system prompt to tell the model "never ask for the NIN directly." Prompts are suggestions. Design the MCP server so that the direct path does not exist: there is no tool that accepts raw identifiers, and no tool that returns raw records. The model cannot leak what it cannot obtain.

Speedmap does this with scoped API keys as well: an MCP-scoped key simply lacks the entitlements that return records. The restriction is enforced in the gateway, logged in the audit trail, and tested in the suite that covers scopes.

The rule, once more, because it is the whole post: let the model act on sensitive data without seeing it. Reference, don't carry. Return decisions, not records. Enforce it in the server, not the prompt.

Written by

Samuel Ojerinde · AI Software Engineer

Next: Agents are untrusted by default