Authenticate MCP servers

When your agent needs to connect to an MCP server or tool hosted on Cloud Run, you can secure the connection using built-in Identity and Access Management and Identity-Aware Proxy (IAP).

If you're connecting an agent running on Cloud Run to an MCP server on Cloud Run, see Authenticate your AI agents for instructions on run.invoker policies.

Developer CLI tools and clients to MCP server

To securely connect developer tools, local SDKs, and generic MCP clients to a private MCP server hosted on Cloud Run, we strongly recommend configuring Identity-Aware Proxy.

Enable IAP

Enable IAP for your deployed Cloud Run MCP service:

gcloud run services update MCP_SERVICE_NAME \
    --iap \
    --region=REGION

Replace the following:

  • MCP_SERVICE_NAME: the name of your MCP server service.
  • REGION: the region where your service is deployed.

Grant access to the MCP server

Bind the calling agent's identity or a developer's user identity to the IAP invoker role on the backend service:

gcloud iap web add-iam-policy-binding \
    --resource-type=cloud-run \
    --service=MCP_SERVICE_NAME \
    --member="PRINCIPAL" \
    --role="roles/iap.httpsResourceAccessor" \
    --region=REGION

Replace the following:

  • MCP_SERVICE_NAME: the name of your MCP server service.
  • PRINCIPAL: An identifier for the principals, or members, which usually has the following form: PRINCIPAL:ID. For example, user:my-user@example.com. For a full list of the values that PRINCIPAL can have, see the Policy Binding reference.
  • REGION: the region where your service is deployed.

Configure access with IAP

By default, IAP uses a Google-managed OAuth client that only supports browser-based user logins. To allow CLI tools and agents to access the MCP server programmatically, you must configure a Custom OAuth Client ID.

  1. Create an OAuth client in the Google Cloud console under APIs and Services > Credentials. Note the Client ID and Client Secret.
    • If configuring for local developer tools like the Antigravity CLI, add http://localhost:7777/oauth/callback to your allowlisted redirection URLs.
  2. Add the OAuth client to the allowlist for programmatic access in your IAP settings by following the guide to Share OAuth clients.

Update client settings to connect

After setting up programmatic access, update your client configuration to supply the connection details and Custom OAuth Client ID credentials.

For example, to configure a tool like the Antigravity CLI to connect to your protected MCP server, update the mcpServers block in your settings:

{
  "mcpServers": {
    "my-mcp-server": {
      "httpUrl": "https://my-mcp-server-<PROJECT_NUMBER>.<REGION>.run.app",
      "oauth": {
        "enabled": "true",
        "clientId": "YOUR_CUSTOM_OAUTH_CLIENT_ID",
        "clientSecret": "YOUR_CLIENT_SECRET",
        "scopes": [
          "email",
          "openid"
        ],
        "redirectUri": "http://localhost:7777/oauth/callback"
      }
    }
  }
}