Zipy held session recordings and error data for its customers. The idea was to let a customer ask Claude questions about that data in plain language, instead of clicking through a dashboard to find it.
Model Context Protocol, or MCP, is the standard way for an AI assistant to connect to an outside system. So I built an MCP server that offered Zipy's data as tools the assistant could call: get_session, search_errors, get_user_journey.
Security was the whole problem. This is an AI agent reading a company's production data on their behalf. The server had to know which customer it was acting for, respect what that customer's plan allowed, and work with software we had never seen before. We had built nothing like it.
Why not an API key
An API key is one secret string. Whoever holds it can do everything it can do. It does not expire, you cannot limit it to a single action, and you cannot withdraw it from one user without breaking every other user. It usually ends up sitting in a config file somewhere.
OAuth 2.0 is the alternative, and it is the system behind every "Sign in with Google" button. The user approves the access. The application receives a token instead of a password. The token has limits, an expiry date, and can be withdrawn.
The secret arrives last
MCP clients run on the user's own machine, which means they cannot keep a secret. Anyone can look inside them.
PKCE is the part of OAuth built for exactly that situation. The client invents a random secret and sends only a scrambled version of it at the start. It reveals the real secret at the very end. If somebody intercepts the code in the middle, it is worthless to them, because the secret never travelled with it.
1. client generates code_verifier (random, 43–128 chars)
2. code_challenge = BASE64URL(SHA256(code_verifier))
3. /authorize with code_challenge, method=S256
4. server stores challenge (short TTL), returns auth_code
5. /token with auth_code + code_verifier
6. server checks SHA256(verifier) == stored challenge
7. access_token + refresh_token
Clients I had never met
With MCP you do not know in advance which software will connect to you. Registering each one by hand does not scale, so the server supports two standards that let clients set themselves up:
- RFC 7591, which lets a client register itself
- RFC 8414, a file at a known address that tells a client where everything is
That convenience moves the risk somewhere else. Once anyone can register, checking the return address exactly, character for character, is what stops an attacker sending the login back to their own server. Limiting how often anyone can register matters for the same reason.
Checked on every call, not just at login
What a customer's plan allows becomes the set of permissions written into their token. I check those permissions every time a tool is called, not only when the client first connects.
A connection can stay open for a long time. If I only checked at the start, a customer who moved to a smaller plan would keep their old access until something disconnected them.
The cost
Several standards to implement, tokens to issue, refresh and withdraw, and a registration endpoint open to the public that has to be defended. That is a lot of protocol for a small team to own, and all of it has to keep working.
It shipped, and customers could ask Claude about their own sessions and errors, limited to what they were paying for.
The part I keep coming back to is that nobody is sitting at a consent screen when an agent calls a tool. Whatever the model decides to do is not the same thing as being allowed to do it. The token decides that, not the model.