Working across enterprise data estates and AI delivery engagements over the last couple of years, I have seen a lot of promising internal AI prototypes stall before ever reaching real users. In most cases, the model quality was fine. What stopped the rollout was how the prototype connected to company data.

Problem statement

When a team builds its first internal AI assistant, the quickest path is usually to drop a service-account admin key for SharePoint, Google Drive, HubSpot, or Snowflake into a workflow tool and connect an LLM to the search endpoint. It gets a demo working quickly.

The trouble starts as soon as Information Security reviews the architecture. If an agent holds a broad service-account token, what stops a junior user in one department from asking the assistant about restricted finance, HR, or deal-room files belonging to another team?

Often the answer is that someone added a line in the system prompt instructing the model to respect team permissions. That does not hold up in production. An LLM processes your system prompt and retrieved document content as one stream of tokens, so a single indirect prompt injection buried inside an external PDF or email can bypass prompt-level restrictions.

Across work for a FTSE 100 Regulated Energy Utility and a Top-Tier Private Equity Firm, this permission gap has been the number one barrier between a Friday demo and a governed production deployment.

Area Shared service-account key Per-user OAuth MCP gateway
Access boundary Broad tenant-wide read/write Exact Entra ID or Google Workspace ACL of the signed-in user
Prompt injection impact Can expose restricted board, HR, or deal-room documents Limited strictly to files the user can already open natively
Audit trail Single generic ai-bot@company.com identity Real employee identity, OAuth scope, tool inputs, and latency per trace
Offboarding Rotating one key breaks multiple workflows at once Standard IdP offboarding revokes agent access immediately
Security sign-off Blocked in regulated and PE reviews Aligns with existing Zero Trust and least-privilege policies

When you walk a security team through that comparison early on, the conversation becomes straightforward. Instead of asking Infosec to trust an LLM with access control, you keep enforcement inside the identity provider they already run.

One FastAPI MCP gateway in front of your tools

Rather than letting each agent manage its own connectors and credentials, I put a single stateless FastAPI Model Context Protocol (MCP) gateway between the agent mesh and downstream systems such as SharePoint, Google Drive, Slack, GitHub, Jira, Confluence, Snowflake, and Neo4j.

Signed-In User (Entra ID / Google OAuth) | v [ FastAPI MCP Policy Gateway ] |-- 1. Validate JWT & run OAuth 2.0 On-Behalf-Of (OBO) exchange |-- 2. Enforce read-only scopes and role-based tool allowlists |-- 3. Lazy-load only the 3-5 tool schemas needed for the request |-- 4. Scrub PII & inspect payloads for prompt injection |-- 5. Emit OpenTelemetry + Langfuse trace tied to user identity | +---> SharePoint MCP (User OBO token, Sites.Read.All) +---> Snowflake MCP (Scoped role, read-only warehouse) +---> Neo4j GraphRAG MCP (Entity lineage + page citations) +---> Email / Slack MCP (Draft-only; sending requires human sign-off) 

Notice the last connector. Even with valid per-user OAuth tokens, external write actions (sending a client email, posting an invoice in Xero, deleting a file) stay in draft-only mode until a human clicks Approve. Keeping a single human-in-the-loop gate on state-changing actions avoids avoidable mistakes in live operations.

What the request guard looks like

The gateway code does not need to be complicated. Keeping the request boundary small and easy to audit is the whole point. Here is the stripped-down FastAPI guard pattern I use before forwarding any MCP tool call downstream:

from fastapi import Depends, FastAPI, HTTPException, Request from pydantic import BaseModel app = FastAPI(title="MCP Policy Gateway") WRITE_TOOLS = {"email.send", "xero.post_invoice", "sharepoint.delete_file"} class ToolCallRequest(BaseModel): server: str tool: str arguments: dict approval_token: str | None = None async def verify_user_context(request: Request) -> dict: bearer = request.headers.get("Authorization", "") if not bearer.startswith("Bearer "): raise HTTPException(status_code=401, detail="Missing user OAuth token") # Validate signature, audience, and tenant claims against IdP JWKS return await validate_idp_jwt(bearer.removeprefix("Bearer ")) @app.post("/mcp/invoke") async def invoke_mcp_tool( payload: ToolCallRequest, user: dict = Depends(verify_user_context), ): if payload.tool in WRITE_TOOLS and not payload.approval_token: return { "status": "pending_human_approval", "tool": payload.tool, "preview": payload.arguments, } # Exchange caller JWT for a short-lived downstream token scoped to this user scoped_token = await exchange_obo_token( user_assertion=user["raw_token"], target_scope=resolve_scope(payload.server), ) result = await forward_to_mcp_server( server=payload.server, tool=payload.tool, arguments=payload.arguments, access_token=scoped_token, ) await emit_langfuse_audit_span(user_id=user["sub"], payload=payload, result=result) return result 

One small practical gotcha to watch out for: if you add in-memory caching for downstream OBO tokens, always key the cache by (user_sub, target_scope) with a short TTL, never just by server name. Better still, start without caching until real latency traces show you need it.

Dealing with tool bloat at ten connectors

Another issue shows up once a gateway grows from two connectors to eight or ten.

Across SharePoint, Jira, Confluence, Slack, GitHub, Snowflake, and internal APIs, you can easily end up with 70 to 90 MCP tools. Passing every tool's JSON schema into every prompt burns 15,000 to 25,000 input tokens before the model even reads the user's question. Latency increases, token spend climbs, and tool selection accuracy drops.

To keep prompts lean, I split tool invocation into two small steps at the gateway:

  1. catalog.search(intent) returns only the top 3 to 5 matching tool definitions that the signed-in user is permitted to call.
  2. mcp.invoke(server, tool, arguments) runs the chosen tool with Pydantic validation and bounded output truncation.

Combining lazy MCP discovery with Neo4j GraphRAG lineage cut prompt token overhead by more than 60% across regulatory and due-diligence pipelines while keeping page-level citation groundedness at 99.4%.

Do you need this on day one?

Ok, great, so should every AI project start by building a full OAuth MCP gateway on day one?

Well, no. If I am validating an idea during a five-day prototype using anonymised sample files, a simple Python script or low-code tool like n8n is completely fine. You want to confirm that the workflow genuinely saves people time before investing in production infrastructure.

The point to move behind a governed OAuth MCP gateway is straightforward: when different users need different data permissions, when auditors or clients need a clear trail of who approved an output and which source page backed it up, or when the system needs regression tests and spend limits running inside your own Azure, AWS, or GCP environment.

Thoughts

Enterprise security principles have not changed just because an LLM is calling the API. Keep your first prototype lean on safe sample data, verify the business value, and then put per-user OAuth, lazy tool loading, and a human approval gate in place before real company records flow through it.

Originally published on Intelligentstack AI.