Dev.to AI 🤖 Ai 👁 0 📖 8 min read

Connect Cloud Run MCP Server to Gemini Enterprise: Google's Private Recipe

Say you build an AI agent that answers questions from your company's private sales database. It works on your laptop. Then your security team asks one thing: how does the agent reach that data without putting it on the p

Connect Cloud Run MCP Server to Gemini Enterprise: Google's Private Recipe

Say you build an AI agent that answers questions from your company's private sales database. It works on your laptop. Then your security team asks one thing: how does the agent reach that data without putting it on the public internet? On November 20, 2026, Google's developer blog published its answer for Cloud Run and Gemini Enterprise. This post explains how that pattern works. It is not a how-to and has no full setup commands.

To connect a Cloud Run MCP server to Gemini Enterprise privately, Google uses three pieces: Private Service Connect for the network path, a DNS zone scoped to your server's exact name, and two auth headers on every call. MCP is the standard that lets an AI agent call a company's private tools and data. You can practice only the user-auth layer for free, because the network parts need a company network.

Key takeaways

  • MCP is how an AI agent calls private company tools and data.
  • Google's recipe keeps the agent's traffic on a private network path.
  • A narrow DNS zone stops one fix from breaking other Cloud Run services.
  • Every tool call is checked twice: once for the service, once for the user.
  • Students can practice the user-auth layer with a small Cloud Run project; the network parts need a company network.

What MCP is and why companies care

MCP (Model Context Protocol) is a standard way for an AI agent to call a company's private APIs and databases as tools. Google's custom MCP server guide shows how Gemini Enterprise plugs such a server in as a data store.

Here is a concrete case. A sales manager in Pune or Austin types, "Which deals closed last week?" The agent sees a tool called get_closed_deals and calls it with a date range. Your MCP server runs the real database query and sends back rows. The model then writes the answer in plain English.

Companies care because their useful data sits behind firewalls. An agent that cannot reach it can only give general answers. If you want to see how an agent chooses between many tools, read how Gemini loads tools only when it needs them.

One thing to be clear about: Gemini Enterprise is a paid product for companies. It is not the free Gemini app on your phone. You will not run this exact setup as a student, and that is fine.

Three problems enterprises must solve

Google's post names three failures. Public calls get rejected with HTTP 404. One identity check is not enough. A wildcard DNS zone can break other services. The author is Neeraj Agrawal, a Forward Deployed Engineer at Google Cloud.

Problem What you see
Cloud Run ingress is set to internal-only (Google's post) Gemini Enterprise calls from the public side and gets HTTP 404
Each tool call needs two identity checks Cloud Run must trust the calling service, and your app must trust the human user
A wildcard *.run.app Private DNS zone in a Shared VPC DNS for every Cloud Run service gets hijacked, not only yours

Private Service Connect keeps traffic off the public internet

Gemini Enterprise reaches your internal server through an Egress Agent Gateway that uses a Private Service Connect network attachment, so no public endpoint is needed. A VPC is your company's private network inside Google Cloud. A network attachment is a doorway that lets Google's side send traffic into that network.

A call from Gemini Enterprise reaches your server through a private path, never the public internet

A call from Gemini Enterprise reaches your server through a private path, never the public internet

Once traffic is inside your VPC, it still has to reach Cloud Run privately. Your Cloud Run service is set to internal-only ingress, which is why a call from the public side gets HTTP 404. Google gives two ways to build the private route. Pick A if you want Google's fixed range and one subnet setting. Pick B if you need an address that fits your own network plan.

Option A: Subnet Private Google Access Option B: Global PSC endpoint for Google APIs
Address used Google's fixed private range, 199.36.153.8/30 An internal IP you choose, 240.0.0.10 in the example
What you set up Turn on Private Google Access for the subnet Create one endpoint inside your own network plan
Source Google Developers Blog, Nov 20, 2026

The Agent Gateway is only offered in us-central1 and europe-west1, according to Google's setup docs. Plan your Cloud Run region around that.

Scope DNS to one server name, not all of run.app

A Private Cloud DNS zone for your server's exact name wins over the broader zone because DNS uses the longest matching suffix, so other Cloud Run services keep working. Google calls this an FQDN-scoped zone. FQDN means the full hostname, every part of it.

Say your MCP server lives at sales-tools-abcxyz.a.run.app. You create a private zone for that full name only. It points the name at the private address from the previous section.

Now a lookup arrives for your server. The resolver compares zones, and your full-name zone matches more of the hostname than run.app does. It wins.

Another team's service, say billing-abcxyz.a.run.app, does not match your zone at all. Its lookup falls through to normal DNS and works as before. The wildcard zone from the table above would have caught that lookup too.

Two headers, two identity checks

Each tool call carries a Google-signed token for the service and the user's own OAuth token, so Cloud Run checks who is calling and your app checks who the user is. The service token travels in X-Serverless-Authorization. The user's Bearer token stays in the normal Authorization header.

For the first check to pass, you grant the Cloud Run Invoker role (roles/run.invoker) to the Gemini Enterprise service agent. That agent's address looks like service-PROJECT_NUMBER@gcp-sa-discoveryengine.iam.gserviceaccount.com, per the docs. Cloud Run verifies that token before your code even runs.

The second check is your job. Google's post includes a Python OAuth2ValidationMiddleware that returns HTTP 401 when the token is missing or invalid. Here is a shorter version of the same idea, using Starlette. The verify_token function is yours to write; it should call your OAuth provider, for example Google's google.oauth2.id_token verify function in Python:

from http import HTTPStatus
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.responses import JSONResponse
class BearerCheckMiddleware(BaseHTTPMiddleware):
    async def dispatch(self, request, call_next):
        header = request.headers.get("authorization", "")
        if not header.startswith("Bearer "):
            return JSONResponse({"error": "missing token"},
                                status_code=HTTPStatus.UNAUTHORIZED)
        user = verify_token(header.removeprefix("Bearer "))  # ask your OAuth provider
        if user is None:
            return JSONResponse({"error": "invalid token"},
                                status_code=HTTPStatus.UNAUTHORIZED)
        request.state.user = user  # tools can now filter data for this user
        return await call_next(request)

Why both? The service check proves the call came from Gemini Enterprise. It says nothing about which employee asked. Without the user check, an intern and the CFO would see the same rows.

Limits to know before you build

Google's docs set hard requirements. You need StreamableHTTP transport and a trusted TLS certificate, and there is a cap on enabled actions.

  • Transport: StreamableHTTP only. SSE (server-sent events), an older MCP transport, is not supported (docs).
  • TLS: the certificate must come from a publicly trusted certificate authority. A private CA works only with Agent Gateway, through a tlsConfig setting.
  • Actions: at most 100 enabled actions per server (docs, last updated 2026-11-19).

This post does not give full setup commands; the exact steps are in Google's post and docs linked above.

Practice the free parts: build a small MCP server on Cloud Run

You can learn the pattern without Gemini Enterprise by building a StreamableHTTP MCP server on Cloud Run's free tier with OAuth token checks. The paid product is not the skill. The skill is knowing what must be secured when an AI touches private data.

Every version of this problem asks you to secure the same things:

  • No public exposure of the data source.
  • A service check and a user check on every call.
  • DNS changes that do not break anyone else's services.

The first and third need a company network to practice fully. The second you can build today.

  1. Build one tool

Write a tool that reads a small fake dataset, like a list of library books or orders.

  1. Serve it over StreamableHTTP

Use an MCP SDK and pick StreamableHTTP as the transport, matching Google's requirement.

  1. Add Bearer token checks

Put middleware like the one above in front of your tools. Return unauthorized for missing or bad tokens.

  1. Deploy to Cloud Run

Cloud Run gives you HTTPS with a trusted certificate by default.

  1. Test with an MCP client

Call the tool once with a valid token and once without. Confirm the second call fails.

  1. Write up the private version

In your README, describe what you would add for a company network: ingress settings, a PSC path, and a scoped DNS zone.

For more project ideas in the same style, see these Gemini builder projects.

What to say about this in an AI-engineer interview

Interviewers want you to explain the pattern in plain words. Start with what MCP is and what must be secured. Then say why one check is not enough.

These talking points may help, though every interviewer is different:

  • "MCP turns private APIs into tools an agent can call, so the security moves to the tool server."
  • "I would keep the server internal and give the agent a private network path."
  • "I check the calling service and the end user separately, because they answer different questions."
  • "I would scope any DNS change narrowly, so my fix does not break other teams."

If you want to know what this kind of work pays as you gain experience, read AI engineer salaries by experience.

Read Google's blog post once, then build a small StreamableHTTP MCP server on Cloud Run's free tier with Bearer token checks, and write three sentences on how you would make it private.

Check it yourself

📰 Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.