Understanding the MCP Gateway Architecture: A Secure Bridge to Claude
Building a bridge between powerful LLMs like Claude (functioning as MCP Clients) and your application services requires careful consideration of security, user identity, and API governance. The API0 MCP Gateway manages this complexity, providing a secure, turnkey architecture.
In this article, we'll walk through the exact architecture that powers our MCP Gateway. The system is split into three distinct phases: Admin Setup, User OAuth Flow, and Real-Time Tool Execution.
Below, we detail each phase of the integration using a hypothetical application provider called "Acme". The heart of it is the OAuth handshake — how Claude gets a key that encodes both the user and the application, without anyone sharing a password:
Phase 1: Admin Setup (One-Time Configuration)
Before any users can connect Claude to your tools, the application admin must configure the Gateway connection.
- Dashboard Authentication: The admin signs into the API0 Dashboard (
app.api0.ai) using Google. The dashboard verifies their identity via a Firebase JWT. - Client ID Registration: The admin opens Connectors → MCP and registers a unique Client ID (e.g.,
acme-mcp). The Dashboard securely updates the Gateway's database (Store) with this mapping. - Downstream Auth Configuration: The admin configures how the Gateway should authenticate with their application (Acme). In this flow, we select the Google Service Account (OIDC) authentication mode, providing a Service Account JSON and the target audience (e.g.,
https://api.acme.com). - Tool Synchronization: The admin uploads an OpenAPI specification detailing the available endpoints. The Gateway parses this and upserts the available MCP tools into the datastore.
At this point, the Gateway knows about the application provider's endpoints, knows how to authenticate securely against them, and is ready to onboard users.
Phase 2: User OAuth Flow (Per End-User)
When an end-user wants to connect Claude to their application account, they initiate a standard OAuth 2.0 flow. However, the API0 Gateway streamlines this process significantly.
- Authorization Request: Claude initiates the flow by hitting the Gateway's
/oauth/authorizeendpoint withclient_id=acme-mcp. The Gateway looks up the Client ID, identifies "Acme" as the provider, and redirects Claude to the API0 Dashboard. - User Consent: The API0 Dashboard prompts the user: "Authorize Claude to access your Acme account." Because the user is already authenticated via Google Firebase, approving the prompt generates a Firebase JWT.
- Code Exchange: The Dashboard exchanges this Firebase JWT with the Gateway for a short-lived authorization code (a JWT containing the user's email, the provider's tenant ID, and a 5-minute expiration).
- Token Generation: Claude is redirected back and exchanges this short-lived code at the Gateway's
/oauth/tokenendpoint. - The Magic API Key: The Gateway validates the exchange, generates a live API Key (
ak_live_...), and returns it to Claude as a Bearer token.
Phase 3: The Tool Call Lifecycle
Now, Claude is fully authorized. Here is what happens under the hood when Claude makes a real-time request to execute a tool — seven steps, but only one network hop your application ever sees:
- Inbound Request: Claude sends a
POST /mcprequest to the Gateway, calling a specific tool (e.g.,search_cv) and providing the Bearer API Key. - Context Resolution: The Gateway validates the API Key against its Store. This is a critical insight: The single API key inherently identifies two things simultaneously:
- The End-User (their email and user tenant ID).
- The Provider (the downstream
acme_tenant_id).
- Tool & Auth Retrieval: Knowing the provider, the Gateway fetches the tool's definition (HTTP verb, application URL, cost) and pulls the downstream auth configuration established in Phase 1.
- Secure OIDC Minting: The Gateway dynamically mints a Google OIDC Identity Token using the admin's Service Account and the configured target audience. To ensure low latency, this token is securely cached for 55 minutes.
- Credit Validation: The Gateway checks the tenant's credit balance to ensure they have sufficient funds to execute the tool call.
- Downstream Proxying: The Gateway proxies the request to the Acme application (
https://api.acme.example/search). Crucially, it injects three things:Authorization: Bearer <oidc_token>(for application security).X-User-Email: user@example.com(for user-level context).X-Tenant-Id: acme_tenant_id(for tenant isolation).
- Execution & Billing: The Acme application easily verifies the OIDC token using standard Google middleware, processes the request, and returns the results. The Gateway completes the flow by fire-and-forget deducting API0 credits and returning the final results to Claude.
The Key Takeaway
By cleanly separating the OAuth authorization layer from the real-time proxying layer, the API0 MCP Gateway ensures total security without sacrificing latency.
The primary insight of this architecture is how the API Key unifies identity: the key Claude holds intrinsically links the end-user to the application provider. This means the Gateway always knows exactly whose tools to load and whose downstream authentication configuration to apply—all instantly, without requiring additional round-trip lookups at call time.