Stop Building AI Apps for Every Idea. Start Building MCP Servers — Part #4
From the publisher’s feed, collected in the ZeroLabs newsroom.
In Part 1, I argued that the center of gravity in applied AI is shifting from full applications to MCP servers. The UI is becoming the shell. The capability layer is becoming the product.In Part 2, we looked at what it takes for that capability layer to survive production: transport choices, stateless HTTP, streaming, sampling, roots, OAuth, encrypted state, principals, and deployment topology.In Part 3, we went deeper into runtime context: why user_id, tenant_id, subproject_id, chat_id, and other trusted identifiers should never be passed through the LLM or stuffed into the system prompt.Stop Building AI Apps for Every Idea. Start Building MCP Servers - Part #1Stop Building AI Apps for Every Idea. Start Building MCP Servers - Part #2Stop Building AI Apps for Every Idea. Start Building MCP Servers — Part #3This part is about the natural next question:If MCP servers are becoming the capability layer, how do we actually secure them?Because the uncomfortable truth is this:A working MCP server is not the same thing as a secure MCP server. And a tool the model can call is not the same thing as a tool the user should be allowed to call.That difference is where a lot of real-world security problems begin.Photo by Charles Snow on UnsplashBefore we start!🦾If this piece gives you something practical you can take into your own system:👏 leave 50 claps (yes, you can!) — Medium’s algorithm favors this, increasing visibility to others who then discover the article.🔔 Follow me on Medium and LinkedIn for more deep dives into agentic systems, LLM architecture, and production-grade AI engineering.The dangerous mental modelWhen teams first start building with MCP, the model is usually simple:Build an MCP server.Add a few tools.Connect it to Claude, ChatGPT, Gemini, or an internal agent.Let the agent decide which tool to call.That works beautifully for a demo. But then the server gets connected to real systems: internal documents, customer data, billing systems, Jira, GitHub, Confluence, Google Drive, databases, cloud accounts, deployment pipelines, admin APIs.At that point, the question is no longer “Can the model call this tool?”The real question becomes:Can this specific user, in this specific tenant, in this specific project, under this specific context, call this specific tool with these specific arguments?That is not a prompt engineering problem. That is an authorization problem. And authorization does not belong inside the model.Tool discovery is not authorizationMCP gives clients a way to discover tools — names, descriptions, input schemas, annotations. That is useful. It is also easy to misunderstand.Tool discovery answers: “What can this server expose?”It does not answer: “What should this user be allowed to use?”Imagine your MCP server exposes:[ "search_project_files", "get_file_content", "search_rfi_knowledge_base", "create_jira_ticket", "delete_document", "rotate_api_key", "run_aws_cost_report", "trigger_deployment"]From the server’s point of view, those tools exist. But from a user’s point of view, the allowed set may look very different:A regular project user might only get search_project_files and get_file_content.An RFI user gets those plus search_rfi_knowledge_base.An admin gets more.A background job gets a completely different set of machine-to-machine tools.The key point: the agent should not receive the full list and be told by prompt not to use some of it.This is weak:You have access to admin tools, but do not use them unless the user is an admin.This is better:The user is not an admin, so admin tools are never included in the tool list.The strongest security control is not convincing the model to behave. It is making the unsafe action unavailable in the first place.Build the tool list per requestIn a production MCP or agentic system, the tool list should be assembled dynamically — not once globally, not hardcoded into the agent, not blindly loaded from every connected server. It should be built per user request, based on trusted server-side context.The flow should look like this:User request ↓Backend resolves user identity ↓Backend resolves tenant, project, roles, scopes, entitlements ↓MCP clients discover available tools ↓Policy layer filters tools for this user and this context ↓Agent receives only the allowed tools ↓Every tool call is checked again before executionThat last step matters.Filtering tools before the agent sees them is necessary. But it is not sufficient. You still need execution-time authorization, because security should not depend on one layer working perfectly.A safe design has at least two checks:Do not expose tools the user should not use.Do not execute tool calls the user is not allowed to make.The first reduces the model’s action space. The second protects the system if something unexpected gets through anyway.The policy registry: the missing layerThis is where a simple concept does a lot of work: the policy registry.A policy registry is not a special MCP feature. It doesn’t need to be a separate product. It can start as a YAML file. It can later become a database table, an admin UI, a policy engine, or a dedicated service. The important thing is the role it plays:A policy registry is the source of truth for which tools, models, agents, data sources, and actions are allowed under which conditions.For example:tools: search_rfi_knowledge_base: server: rfi_mcp enabled: true allowed_roles: - rfi_user - admin auth_flow: obo data_classification: internal read_only: true audit_required: true rate_limit: 30/min get_project_file_content: server: project_mcp enabled: true allowed_roles: - project_user - admin requires_project_access: true data_classification: confidential read_only: true audit_required: true delete_document: server: project_mcp enabled: true allowed_roles: - admin destructive: true requires_confirmation: true audit_required: trueThis file is not for the LLM. It is for your backend. The orchestrator reads it and decides what the model is allowed to see. The gateway reads it and decides whether a tool call can execute. The audit layer reads it and decides what must be logged. The UI may read parts of it to show confirmation prompts for destructive actions.The policy registry becomes the bridge between MCP tool discovery and real enterprise authorization.Tags and annotations: useful metadata, not securityThere is a practical MCP/FastMCP feature that is easy to underestimate: tool tags and annotations. They are not a replacement for authorization — but they are very useful for building a cleaner governance layer around your tools.In FastMCP you can describe a tool like this:from fastmcp import FastMCPfrom mcp.types import ToolAnnotationsmcp = FastMCP("RFI MCP Server")@mcp.tool( tags={"rfi", "rag", "read_only", "internal"}, annotations=ToolAnnotations( title="RFI RAG Search", readOnlyHint=True, idempotentHint=True, openWorldHint=False, ),)async def rfi_rag_search(query: str) -> list[dict]: """Search the internal RFI knowledge base.""" ...Tags are useful for grouping and filtering tools: rfi, rag, admin, read_only, destructive, billing, github, aws, etc.Annotations are useful for describing behavior: readOnlyHint=True signals the tool should not modify state; idempotentHint=True signals repeated calls are safe; destructiveHint=True signals the tool may perform irreversible changes.This metadata can help your orchestrator make better decisions:all_tools = await mcp_client.list_tools()# Instead of hardcoding tool names:allowed_tools = filter_tools( tools=all_tools, required_tags={"rfi", "read_only"}, denied_tags={"admin", "destructive"},)That is much easier to maintain when your MCP server grows from 5 tools to 50. But the line here is critical:Tags and annotations are metadata. They are not authorization.A tag like admin does not protect the tool by itself. An annotation like readOnlyHint=True does not prove the current user is allowed to run it. A malicious or badly implemented MCP server can lie. Even a trusted server can accidentally annotate a tool incorrectly.The clean mental model:Layer Role MCP / FastMCP metadata What this tool is and how it behaves Policy registry Who can use it and under what conditions Orchestrator / gateway Where the rules are enforcedDo not confuse these layers. If the model can see a tool, it may try to use it. If the backend executes without checking policy, that is not an AI problem. That is a backend security bug.Prompt is not policyThis is one of the most important rules in agent security:Anything you put in the prompt is guidance, not enforcement.Prompts are useful for behavior shaping. They are not reliable access-control mechanisms.Weak:Only use the billing tool if the user is from the finance department.Stronger:The billing tool is only included when the user has the finance role.Strongest:The billing tool is only included when the user has the finance role,and every billing tool call is validated again before execution.The same applies to runtime context — which I covered in Part 3. The reason is not just code cleanliness. It is security. If the LLM can see or generate a tenant_id, prompt injection can try to change it. If the LLM passes user_id into a tool, an attacker can attempt to impersonate another user.The model gives intent. The backend gives authority. Do not mix them.Authorization must happen at the argument level tooTool-level filtering is not enough. Sometimes the user is allowed to call the tool, but not with every possible argument.A user may be allowed to call get_file_content(file_id) — but only for files inside projects they can access. A user may be allowed to call run_cost_report(account_id) — but only for AWS accounts mapped to their business unit.This means your policy check cannot stop at “Can this user call this tool?” It must also ask: “Can this user call this tool with these arguments?”That is where many agentic systems fail. The tool exists. The user has access to the tool. The model generates an argument. The backend trusts it. And suddenly a normal user is reading data from the wrong project.A safer execution flow:Agent proposes tool call ↓Orchestrator validates tool name ↓Orchestrator validates user role/scope ↓Orchestrator validates tenant/project/data boundaries ↓Orchestrator validates arguments ↓Tool executes with server-side context ↓Audit event is writtenThe model should never be the final authority on access. It can propose actions. Your system decides whether those actions are allowed.Token forwarding is not a security architectureAnother common mistake: the app receives a user token, the agent gets the same token, the MCP server gets the same token, the downstream API gets the same token. Everything “works.”But security and auditability become blurry. The downstream system doesn’t know whether the call came from the application, the agent, the MCP server, or a background process. The token may carry too broad a scope. The call chain may be impossible to explain in an incident report.A better pattern is token exchange: each boundary receives a token intended for that boundary.User authenticates to application ↓Application calls agent with a token scoped for the agent ↓Agent exchanges for a scoped token for the MCP server ↓MCP server exchanges or obtains a scoped token for the downstream APIThis gives you cleaner audit lineage, correct audience on every token, and smaller scopes that limit blast radius.One more distinction that matters: a user asking a question in a UI is not the same security scenario as a nightly sync job ingesting Confluence pages into a knowledge base. The first maps to an on-behalf-of pattern. The second maps to client credentials. Treat them differently.RAG and memory are part of the security boundarySecurity discussions around agents tend to focus on action tools: create ticket, send email, trigger deployment. Those are obviously sensitive. But retrieval tools are sensitive too.Search is not harmless.A RAG tool can leak confidential information if it searches across the wrong tenant. A memory tool can resurrect stale or poisoned context. A document retrieval tool can expose files the user should not know exist. A vector store can become a privilege escalation layer if metadata filters are optional or model-controlled.The safe pattern:// What the model provides:{ "query": "compliance requirements for the RFI" }// What the model must never decide:{ "tenant_id": "customer-a", "include_confidential": true, "bypass_acl": true}Access filters belong to code. Not to prompts. Not to model-generated JSON. Not to user-editable parameters.Retrieval systems also need provenance. For every chunk, you should know: source system, document ID, source URL, tenant, project, access classification, ingestion timestamp, and uploader identity. This matters for both security and answer quality — a poisoned knowledge base is still a security problem.RAG security is not just “filter by tenant.” It is also source trust, document provenance, metadata validation, stale document detection, and prompt injection resistance. Memory and retrieval are not just product features. They are security boundaries.Destructive tools need a separate pathNot all tools carry the same risk. A read-only search and a deployment trigger are not the same category.A good MCP security design separates tools into classes:read-only — basic authorization and audit logsread-write — stronger scopesdestructive — confirmation requiredexternal-world — content review before executionadmin-only — elevated roles, short-lived sessionsbackground-only — never exposed to interactive agentsFor example:delete_document: destructive: true allowed_roles: - admin requires_confirmation: true audit_required: true argument_policy: require_same_tenant: true require_document_access: trueThe key point: a prompt can tell the model to ask for confirmation before deleting. But the backend must enforce that the tool call cannot execute unless confirmation was actually recorded. Human-in-the-loop is not a sentence in the system prompt. It is a state transition in your backend.Every tool call should leave an audit trailIf MCP servers become the capability layer, tool calls become business events. They should be observable — not just for debugging, but for security, compliance, incident response, cost attribution, and understanding how the system is actually used.A useful audit event answers:{ "timestamp": "...", "request_id": "...", "trace_id": "...", "user_id": "...", "tenant_id": "...", "agent_name": "...", "mcp_server": "...", "tool_name": "...", "arguments_hash": "...", "data_sources": ["..."], "authorization_decision": "allowed", "policy_version": "...", "latency_ms": 842, "status": "success"}For sensitive tools you may also need: approval status, confirmation result, downstream resource IDs, retrieved document IDs, model used, token usage, error category.When something goes wrong, “the AI did it” is not an acceptable incident report. You need to know which user asked, which agent handled it, which MCP server was called, which tool executed, which data source was touched, which policy allowed it, and which result was returned. Without that chain, you do not have enterprise-grade agent security.The secure MCP architectureFor a production-grade enterprise MCP setup, I think in layers:Identity layer — validates users and service principals — resolves roles, scopes, tenants, projectsPolicy registry — defines tool, model, agent, and data-source permissions — stores risk classification and audit requirementsTool discovery layer — connects to MCP servers — reads tool metadata, schemas, annotations, tagsTool filtering layer — builds the allowed tool list for this user/sessionAgent runtime — sees only the filtered tools — proposes actions, but does not authorize themExecution gateway — validates every tool call again — checks arguments, tenant boundaries, rate limits, confirmationsMCP server — executes business capability — uses server-side context, not model-supplied identifiersData layer — enforces row/document/source-level permissions — preserves provenance and audit metadataObservability layer — logs traceable user → agent → MCP → tool → data lineageMany of these components are small in practice. The mistake is not that teams cannot build them. The mistake is that teams do not name them. And what you do not name, you usually implement accidentally.The practical checklistIf I had to reduce this whole article to a checklist:[ ] Do not expose all MCP tools to every user[ ] Build the tool list dynamically per request[ ] Keep a policy registry for tools, agents, models, and data sources[ ] Treat MCP metadata (tags, annotations) as capability description, not authorization[ ] Never rely on prompts for access control[ ] Never let the LLM pass trusted identifiers like user_id or tenant_id[ ] Validate every tool call again at execution time[ ] Validate tool arguments against tenant, project, and resource permissions[ ] Use token exchange or scoped credentials instead of blind token forwarding[ ] Separate user-driven flows from background machine-to-machine flows[ ] Log every sensitive tool call with user, agent, tool, data, and policy lineage[ ] Treat RAG and memory as security boundaries[ ] Protect retrieval with server-side access filters[ ] Require confirmation and stronger controls for destructive tools[ ] Design guardrails per layer, not as one magical central filterThe common thread:The model can reason. The platform must enforce.Final takeMCP is powerful because it gives AI clients a standard way to reach tools, systems, files, APIs, and workflows. That is also exactly why MCP security matters.Once your MCP server connects to real enterprise systems, it is no longer just an integration demo. It is part of your application security boundary.The agent should not receive every tool. The prompt should not define permissions. The LLM should not pass trusted context. The retrieval layer should not trust model-generated filters. The MCP server should not blindly forward tokens. And the platform should not execute actions it cannot audit later.If Part 1 was about why MCP servers matter, Part 2 was about making them production-ready, and Part 3 was about keeping runtime context out of the model — then Part 4 is the next logical layer:MCP servers need security architecture, not just tool descriptions.Build the capability. But build the boundary around it too.That is what separates a useful MCP server from a dangerous one.And that’s a wrap! If you’ve read this far, it probably means you found this article useful or insightful. If that’s the case, consider leaving a few claps or sharing it with your team, please. Thanks for reading! 🚀Stop Building AI Apps for Every Idea. Start Building MCP Servers — Part #4 was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.