Transparency: This article was generated with AI assistance. The code is illustrative, and the linked MCP specifications are the primary references for protocol requirements.
An MCP server can be working perfectly in a local demo and still be unsafe to connect to a real account.
The protocol makes it easier for AI applications to discover and call tools. But the hard engineering questions do not disappear:
- Which user is allowed to perform this action?
- What happens when the model sends an unexpected argument?
- Can a retry create the same record twice?
- Should a destructive operation happen immediately?
- What information is safe to return to the model?
The gap between a tool that works and a tool that is safe to trust is where the engineering gets interesting. Here is a checklist to use before connecting an MCP server to anything important.
1. Treat tool descriptions as guidance, not authorization
A description such as:
This tool can delete a project. Only use it when the user asks.
is useful context for a model. It is not an access-control system.
The server must independently decide whether the authenticated actor is allowed to delete that project. Never let a model's interpretation of a description become the permission check.
A useful mental model:
- The model decides what it wants to do.
- The server decides whether the caller is allowed to do it.
- The application decides whether the action needs human approval.
Those are three different responsibilities.
2. Separate read operations from write operations
I prefer making the difference obvious in the tool surface.
For example:
-
get_projectreads project information. -
list_project_membersreads membership. -
invite_project_memberchanges membership. -
delete_projectperforms a destructive action.
This is easier to reason about than one large tool that can inspect, modify, invite, and delete depending on a loosely defined argument.
It also makes it easier to assign different permissions and approval requirements.
3. Validate arguments and business rules on the server
A JSON schema can describe the expected shape of an input. The server still needs to validate the actual values and enforce domain rules.
Imagine an agent proposing a refund:
const input = RefundInput.parse(args);
await assertCanRefund(actor, input.orderId);
await assertOrderIsRefundable(input.orderId);
await assertRefundDoesNotExceedOrderTotal(input);
return createRefund(input);
This is illustrative TypeScript, not a drop-in implementation. The important point is that authorization and business invariants run in trusted application code, not only in the prompt.
A valid JSON object can still represent an invalid business action.
4. Bind access to the authenticated user
Never assume that knowing a project ID, workflow ID, or state handle proves ownership.
For every request, derive the actor from verified authentication and check access to the specific resource. Do not trust a user ID supplied by the model as the source of identity.
For HTTP-based MCP authorization, token audience validation matters too. A server should accept tokens intended for that server, not blindly reuse credentials issued for another service.
5. Put a human checkpoint before sensitive actions
Not every tool call needs a confirmation dialog.
Reading a public document and deleting a production database should not have the same interaction model.
A practical policy could be:
| Action | Suggested handling |
|---|---|
| Read public metadata | Allow within scope |
| Read private data | Check identity and permissions |
| Create a draft | Allow or notify |
| Send an invitation | Confirm or apply policy |
| Delete data | Require explicit approval |
| Transfer money or change ownership | Strong confirmation and audit |
The exact policy depends on the application. The principle is to make the impact of an action visible before it happens.
6. Make writes safe to retry
Agents retry. Networks time out. A tool may successfully create something while the client fails to receive the response.
Without an idempotency strategy, the next attempt can create a duplicate payment, invitation, ticket, or event.
For state-changing tools, consider an idempotency key tied to the actor and intended operation. Store the result so that a retry can return the original outcome instead of repeating the side effect.
Also distinguish between:
- The operation failed.
- The operation succeeded but the response was lost.
- The operation is still running.
These are not interchangeable states.
7. Minimize and sanitize tool output
Returning an entire database row or a complete document when the model only needs a status is usually unnecessary.
Return the smallest useful result. Remove secrets and unrelated personal information. Limit large results and paginate them. Treat content retrieved from external sources as untrusted data, not as instructions.
This helps keep the context focused and reduces the amount of sensitive information exposed to the model.
8. Log what happened
For important tool calls, record enough information to answer:
- Who initiated the request?
- Which tool was called?
- Which resource was affected?
- Was approval required?
- Did validation pass?
- Did the operation succeed?
- Was it retried?
Avoid logging access tokens, passwords, or sensitive payloads.
A useful audit trail is part of the product, not an optional debugging feature.
A practical starting checklist
Before exposing an MCP server to a real application, I would check:
- [ ] Every write operation has server-side authorization.
- [ ] Inputs are validated beyond their JSON shape.
- [ ] Read and write capabilities are clearly separated.
- [ ] Sensitive actions have an approval policy.
- [ ] Retries cannot accidentally repeat side effects.
- [ ] Tokens are validated for the intended resource.
- [ ] Tool outputs are minimized and sanitized.
- [ ] Important actions are auditable.
- [ ] Failure and timeout behavior is tested.
You do not need an enormous security framework before building your first MCP server. Start with the operations that could cause the most damage, enforce those boundaries, and expand deliberately.
Useful resources
Your turn
What is the first thing you secure when exposing tools to an AI agent: permissions, input validation, human approval, or retry safety?
I'd especially like to hear from people who have moved MCP integrations beyond local demos.
I share practical engineering work and things I'm building:
Follow along if these topics are useful to you.
Top comments (0)