When Not to Use This Pattern
This pattern is ideal for:
Analytics
KPI Dashboards
Business Intelligence
Operational Monitoring
Executive Reporting
It may be excessive for:
If you only have one client and never expect another, direct rendering may be perfectly acceptable.
But most enterprise ecosystems don’t stay that simple for long.
* * *
## **Final Thoughts**
One lesson I’ve learned is that client diversity grows much faster than backend complexity.
The first client is easy.
The fifth client exposes every architectural shortcut.
The Abstract UI Schema Pattern addresses that challenge by applying established software architecture principles — Separation of Concerns, Adapter Patterns, API-first design — to the world of MCP.
The MCP Server becomes a source of meaning.
The client becomes a renderer of meaning.
And that separation turns out to be one of the most important architectural boundaries in scalable MCP systems.
Because the moment your MCP server starts generating UI, it stops being a protocol server and starts becoming a frontend framework.
* * *
========================================
---
# How to Build a Secure MCP Server: The Middle-Tier Gatekeeper Pattern
- URL: https://akshaykgupta.me/blog/mcp-the-middle-tier-gatekeeper-pattern/
- Author: Akshay K Gupta
- Published: May 20, 2026
- Tags: mcp, mcp-server-pattern, system-architecture, enterprise-architecture, architecture-pattern, cyber-security
- Description: Secure your enterprise data warehouse from prompt injections when connecting LLMs via the Model Context Protocol.
import Figure from '../../../components/mdx/Figure.astro';
import Mermaid from '../../../components/mdx/Mermaid.astro';
import middleTierImg from './middle-tier-enforcement.png';
Imagine this scenario: You’ve just deployed a brilliant enterprise AI assistant using the **Model Context Protocol (MCP)**. It connects your Enterprise Copilot directly to your enterprise data warehouse (e.g. Snowflake) via a remote SSE/HTTP server. Your executive team is thrilled -they can now ask natural language questions and instantly see revenue breakdowns, instead of waiting for the BI team to generate those Power BI reports.
Then, an employee asks the assistant:
> "Show me the previous payroll details and filter for the CxO's salary."
If your underlying data warehouse relies on a shared service account or lacks fine-grained, row-level access controls mapped to every single end-user (which is the case for most enterprises), your AI will happily fetch that data. You are exactly one prompt injection away from a massive corporate security incident.
How do we fix this when we cannot completely rewrite our database permissions overnight?
The answer lies in a decoupled architecture pattern: **the Middle-Tier Policy Enforcement Pattern,** often referred to as the **Application-Level Gatekeeper.**
Let’s walk through the problem and build a secure gateway step-by-step.
## **The Problem: The “All-Powerful” AI Agent**
In an ideal zero-trust architecture, the database handles its own Row-Level Security (RLS) and data governance. In the real world, analytical data warehouses or legacy systems often use a single, unified connection string for applications.
If you expose a generic tool like `run_sql_query(query)` to an LLM, the model can be manipulated by malicious user inputs to bypass your structural intent, alter the SQL syntax, or query highly sensitive tables it should never see.
> ***The Architectural Pivot:*** *When underlying data systems cannot enforce granular data ownership rules, we must shift the Policy Decision Point (PDP) away from the database and place it squarely inside our remote MCP server. The MCP server stops being a passive translator and becomes a strict, policy-enforcing security gatekeeper.*
## **Building the Gatekeeper Pattern**
Implementing this pattern means decoupling *authentication* (who the user is) from *authorisation* (what data they are allowed to see). Here is how you build this flow inside your remote HTTP/SSE MCP server.