Your team is about to ship a remote MCP server that wraps your internal APIs. What security concerns apply, and how do you address them?
Advertisement
🧩 Scenario
Architecture Walkthrough
Start from one mental model: the model is an untrusted caller. It is like a browser hitting your API. It can be confused, manipulated by text it reads, or driven by a malicious user. Every protection you would add to a public REST endpoint applies here, plus a few MCP-specific ones.
1. Authentication: tokens must be issued for your server
For HTTP transports, the spec defines an OAuth 2.1 based flow. Your MCP server acts as a protected resource and must validate that each access token was issued for it (the audience check). Invalid or expired tokens get a 401. Two rules matter most:
- No token passthrough. The spec says servers must not accept tokens not explicitly issued for the MCP server. If your server needs to call internal APIs, it gets its own credentials for them.
- Authenticate every request. Do not treat possession of a session or state id as proof of identity. The spec says servers must not treat a state handle as authentication.
If your server is a proxy to a third-party OAuth provider, read the spec's confused deputy section. Proxies must get per-client user consent before starting the third-party flow.
2. Authorization inside every tool
Auth at the edge is not enough. refundOrder must check that this user has the refund role and can access this order, every time. The model choosing to call a tool is not permission.
3. The tool server MUST list
The tools section of the spec says servers must validate all inputs, implement access controls, rate limit invocations and sanitise outputs. Rate limiting matters more than usual because an agent loop can call a tool many times in a few seconds.
4. Prompt injection through data
Tool results and resources go straight back into the model's context. A customer note, a ticket comment or a web page can contain instructions. Treat returned text as data: return only the fields needed, keep free text clearly labelled, and never let tool output alone authorise a destructive action. Pair this with human approval on the host side. The spec says a human should always be able to deny tool calls.
5. Scopes and blast radius
Request minimal scopes first (for example read-only), and step up with a precise scope challenge when a write is needed. The spec lists wildcard or omnibus scopes as a common mistake.
6. Local servers are a different risk
A local stdio server runs with the user's own permissions. The spec says clients must show the exact command and get explicit approval before a one-click install, and should sandbox servers. If a local server uses HTTP, protect it with an auth token or use stdio, because any site in the browser could otherwise try to reach it.
Key Code Explained (TypeScript)
import { McpServer } from '@modelcontextprotocol/server';
import * as z from 'zod/v4';
// Your own helpers, not part of the SDK
import { getCaller, orders, rateLimiter, audit } from './internal';
export function createServer() {
const server = new McpServer({ name: 'orders', version: '1.0.0' });
server.registerTool(
'refund-order',
{
description: 'Refund one order. Requires the support:refund permission.',
// Validate shape and limits before any business logic
inputSchema: z.object({
orderId: z.string().regex(/^ORD-\d{4,10}$/),
reason: z.string().max(200),
}),
},
async ({ orderId, reason }) => {
// Identity comes from the verified access token, never from model input
const caller = await getCaller();
if (!caller.permissions.includes('support:refund')) {
return { isError: true, content: [{ type: 'text', text: 'Not allowed to refund.' }] };
}
if (!(await rateLimiter.allow(caller.id, 'refund-order'))) {
return { isError: true, content: [{ type: 'text', text: 'Rate limit reached, try later.' }] };
}
const order = await orders.findForTenant(orderId, caller.tenantId);
if (!order) {
return { isError: true, content: [{ type: 'text', text: 'Order not found.' }] };
}
await orders.refund(order.id, { by: caller.id, reason });
await audit.log({ tool: 'refund-order', caller: caller.id, orderId });
// Sanitised output: only the fields the model needs, no raw notes
return {
content: [{ type: 'text', text: `Refunded ${order.id} for ${order.amountFormatted}.` }],
};
},
);
return server;
}
getCaller reads the identity that your HTTP layer attached after verifying the token's issuer and audience. The model can choose orderId, but it can never choose who the caller is. Errors come back as isError: true results, so the model sees a clear message instead of a crashed request.
Tradeoffs
| Control | Protects against | Cost |
|---|---|---|
| Audience-checked OAuth tokens | Stolen or misused tokens, passthrough | OAuth setup and metadata endpoints |
| Per-tool authorization checks | Model or user reaching data they should not | More code in every handler |
| Rate limiting per user and tool | Runaway agent loops, abuse, cost spikes | Needs a shared store such as Redis |
| Minimal output fields | Data leaks and prompt injection | Model may need a second call for details |
| Host-side human approval | Destructive actions from manipulated models | Slower flow for support agents |
What Interviewers Actually Check
- Whether you treat the model as an untrusted caller
- Whether you know the audience check and the no token passthrough rule
- Whether authorization happens inside each tool, not only at connect time
- Whether you mention prompt injection through tool results
- Whether you separate remote server risks from local stdio server risks
Follow-Up Questions
- How would you design scopes so a read-only assistant can later ask for refund access?
- What is the confused deputy problem for an MCP proxy server?
- Why should a client not decide approvals based on a server's destructiveHint?
- How would you detect an agent calling the same tool in a tight loop?
- What would you log for each tool call, and what would you avoid logging?
Common Candidate Mistakes
- Saying "the model only calls tools when it should". That is a hope, not a control.
- Passing the user's upstream token straight through to internal services.
- Returning full database rows, including free-text fields that can carry injected instructions.
- Relying on a long system prompt as the defence against prompt injection.
- Forgetting audit logs, which you need when something goes wrong.
Interview Readiness Checklist
Before you leave this question, make sure you can answer:
- Can you list the four MUST rules for tool servers from the spec?
- Can you explain token passthrough and why it is banned?
- Can you write a handler that derives identity from the token, not the input?
- Can you explain how prompt injection reaches the model through MCP?
- Can you describe the extra risks of local servers?
Summary
An MCP server is an API that a model drives, so secure it like a public API with an unpredictable caller. For remote servers, follow the spec's OAuth based authorization, verify that every token was issued for your server, and never pass client tokens through to other services. Inside each tool, validate inputs, check that this caller may perform this action on this resource, rate limit, sanitise outputs and write audit logs. Treat tool results as untrusted text that can carry prompt injection, request minimal scopes, and keep a human able to deny risky calls. Local stdio servers need explicit install approval and sandboxing because they run with the user's own permissions.
Is authorization required by the MCP spec?
The spec marks authorization as optional, but for HTTP transports it defines an OAuth 2.1 based flow that implementations should follow. For a remote server wrapping internal APIs, skipping auth is not a real option. stdio servers are different: the spec says they should read credentials from the environment instead.
Can I trust a tool annotation like destructiveHint to decide whether to ask the user?
Only if you trust the server. The spec says clients must treat tool annotations as untrusted unless they come from trusted servers. Use your own allow-list or policy for approvals instead of relying on what a server says about itself.
What is token passthrough, and why is it banned?
It is when an MCP server accepts a token the client got for some other service and forwards it downstream. The spec says servers must not accept tokens not explicitly issued for them, because passthrough skips audience checks, breaks audit trails and lets a stolen token reach more systems.
Advertisement
Stay Updated
Get the latest frontend challenges, interview questions and tutorials delivered to your inbox.
Advertisement