Fine-Grained MCP Tool Authorization for AI Agents with Google Cloud Agent Gateway

As AI agents become capable of discovering and invoking external tools, one security question becomes increasingly important:

Just because an agent can discover and request a tool, should it automatically be allowed to execute it?

I wanted to validate this practically on Google Cloud rather than treat it only as an architecture discussion.

I built a hands-on reference implementation using Google ADK, Gemini on Vertex AI, Agent Runtime, Agent Identity, Agent Registry, Agent Gateway, IAP Authorization Extension, Network Security Authorization Policy, IAM Unified Access Policy, MCP, and Cloud Run.

The objective was simple:

Allow an agent to discover multiple MCP tools, but independently authorize each tool at execution time.

The final validated result was:

read_customer_profile
→ ALLOWED
→ EXECUTED

update_customer_profile
→ DENIED
→ NOT EXECUTED

The important point is that the authorization decision happens outside the model reasoning loop.

The model proposes the action. The authorization layer decides whether the action is allowed to execute.


Architecture

At a high level, the lab follows this path:

User
  ↓
Google ADK Agent
  ↓
Agent Runtime
  ↓
Agent Identity
  ↓
Agent Gateway
  ├──────────────────────┐
  │                      │
  ↓                      ↓
Vertex AI            MCP Server
Gemini               registered in
                     Agent Registry
                          ↓
                      MCP tools

The authorization chain is:

Agent Gateway
  ↓
Network Security Authorization Policy
  ↓
IAP Authorization Extension
  ↓
IAM Unified Access Policy
  ↓
ALLOW / DENY

This gives the model access to available capabilities while keeping the final execution decision at an external policy boundary.


The MCP tools

The MCP server exposes two synthetic operations.

read_customer_profile

This tool retrieves a synthetic customer record.

Example result:

customer_id: CUST-1001
name: Sample Customer
email: sample@example.com
tier: gold

Policy outcome:

ALLOW

Execution outcome:

EXECUTED

update_customer_profile

This tool represents a higher-risk mutation operation.

It is deliberately implemented as a simulation and does not modify stored data.

Policy outcome:

DENY

Execution outcome:

NOT EXECUTED

The model was still able to identify and request the tool.

The authorization layer prevented the requested operation from reaching downstream execution.


Tool discovery is different from tool authorization

One of the most important findings from the implementation was that MCP discovery operations must be considered separately from tool execution.

An MCP client may need operations such as:

initialize
notifications/initialized
tools/list

before it can understand which tools are available.

Blocking all MCP traffic would prevent normal discovery.

Instead, the policy permits registered MCP discovery and handshake operations while applying more specific authorization to:

tools/call

This creates an important distinction:

Tool is visible
≠
Tool is authorized

An agent can therefore know that update_customer_profile exists without automatically receiving permission to execute it.


Fine-grained authorization with IAM Unified Access Policy

The validated policy contains four logical rules.

Rule 1 — Allow MCP discovery and handshake

destination.is_registered == true &&
destination.agent_registry.mcp_server.method != 'tools/call'

Effect:

ALLOW

Rule 2 — Allow registered Vertex AI endpoints

destination.is_registered == true &&
destination.agent_registry.resource_type == 'ENDPOINT'

Effect:

ALLOW

Rule 3 — Allow the read tool

destination.is_registered == true &&
destination.agent_registry.mcp_server.method == 'tools/call' &&
destination.agent_registry.mcp_server.tool.name == 'read_customer_profile'

Effect:

ALLOW

Rule 4 — Deny the update tool

destination.is_registered == true &&
destination.agent_registry.mcp_server.method == 'tools/call' &&
destination.agent_registry.mcp_server.tool.name == 'update_customer_profile'

Effect:

DENY

The permission used by the policy is:

iap.googleapis.com/resources.egressViaIAP

This enabled the authorization decision to include the agent identity, registered destination, MCP method, and specific tool name.


Agent Identity

The Agent Runtime is configured with:

AGENT_IDENTITY

This gives the deployed agent its own security principal instead of relying on a broadly shared runtime identity.

One important implementation detail is that the Agent Identity should not be reconstructed from assumptions about the project or trust domain.

The deployment retrieves the Runtime’s effective identity and passes it to the policy as:

${AGENT_PRINCIPAL}

This is particularly important because the Agent Identity trust domain can vary between environments.

From a security perspective, this allows policy to answer a more specific question:

Can this particular agent
perform this particular operation
against this registered destination?

rather than simply:

Can some shared service identity access this system?


Agent Registry does not equal authorization

The MCP server and its tool metadata are registered in Agent Registry.

The registered tools are:

read_customer_profile
update_customer_profile

But registration alone does not grant execution permission.

That distinction matters.

Agent Registry provides governed metadata about the destination and capabilities.

IAM policy determines whether the agent is authorized to use those capabilities.

A registered MCP tool can still be denied.


Proving that the denied tool did not execute

A denied response from the agent was not enough for me to consider the test complete.

The more important question was:

Did the downstream service actually receive the mutation request?

For the denied update scenario, the model selected:

update_customer_profile

but the downstream Cloud Run invocation window showed only MCP initialization and discovery activity:

initialize
notifications/initialized
tools/list

There was no downstream update tool execution.

That allowed the test to establish:

Model selected the tool
        ↓
Authorization rejected execution
        ↓
Downstream mutation did not occur

This is much stronger validation than relying only on the text returned to the model.


Observability requires correlation

Another practical finding was around logging.

Individual successful or denied tools/call requests were not always visible as separate Agent Gateway or IAP records during validation.

Because of this, absence of one specific Gateway log should not automatically be interpreted as evidence that policy enforcement was bypassed.

The validation instead correlated multiple evidence sources:

Agent Runtime events
+
Agent Gateway logs
+
IAP audit logs
+
Cloud Run request logs

Each layer answers a different question.

Agent Runtime can show what the model attempted.

Agent Gateway can show governed routing and authorization context.

IAP provides authorization-related evidence.

Cloud Run confirms whether downstream execution actually occurred.

For security validation, the last point is particularly important.


Policy propagation also matters

IAM policy changes do not necessarily become effective instantaneously.

During testing, policy propagation sometimes required several minutes.

This created an operational lesson that applies beyond this lab:

Do not repeatedly modify an authorization policy while the previous change may still be propagating.

Otherwise, it becomes difficult to determine whether observed behavior comes from:

  • the previous policy,

  • the current policy,

  • propagation delay,

  • or an actual configuration error.

The deployment guide therefore treats policy rollout as a lifecycle:

Define
  ↓
Dry run / evaluate
  ↓
Observe
  ↓
Validate
  ↓
Enforce
  ↓
Verify downstream execution


A bound-token compatibility finding

I also tested the Runtime configuration:

GOOGLE_API_PREVENT_AGENT_TOKEN_SHARING_FOR_GCP_SERVICES

The known-good configuration for this lab currently uses:

False

A controlled experiment was performed without changing the Gateway or authorization policy.

With:

False

the read tool worked.

With:

True

the Agent Gateway logs showed the registered Vertex AI request being allowed, but Vertex AI returned:

401 UNAUTHENTICATED

Returning the setting to:

False

restored the successful execution path.

This indicated that the failure occurred after Gateway authorization and was related to authentication presented to Vertex AI rather than a UAP denial.

I have documented this behavior separately in the repository so it can be re-tested as the platform evolves.


Automated validation

The repository contains automated tests for both the agent authentication layer and the MCP server.

The authentication tests validate areas such as:

  • Cloud Run token audience derivation

  • MCP toolset construction

  • Gemini model configuration

  • credential caching

  • token refresh

  • refresh failure propagation

  • rejection of insecure MCP URLs

The MCP integration workflow validates:

  • real MCP HTTP transport

  • tool discovery

  • successful read execution

  • missing-customer handling

  • simulated update behavior

  • confirmation that the update does not mutate stored data

  • containerized MCP server execution

This was important because I wanted the repository to be reproducible rather than just a record of one successful cloud experiment.


Repository

The complete implementation is available here:

The validated baseline is released as:

v1.0.0

The repository contains:

  • Google ADK agent implementation

  • synthetic MCP server

  • Agent Runtime deployment configuration

  • Agent Identity configuration

  • Agent Gateway integration

  • Agent Registry metadata

  • IAM Unified Access Policy

  • IAM v3 Policy Binding

  • Network Security Authorization Policy

  • IAP Authorization Extension

  • automated unit and integration tests

  • architecture documentation

  • reproducible deployment guide

  • validation methodology

  • troubleshooting guidance


Final takeaway

The experiment reinforced a principle that I believe will become increasingly important as enterprise agents gain access to more tools:

Tool availability
does not imply
tool authorization.

A model may discover a capability.

A model may determine that the capability is useful.

A model may even generate the correct tool invocation.

But none of those things should automatically grant execution authority.

The model proposes the action. The authorization boundary decides whether that action is allowed to execute.

I would be interested in hearing how others are approaching MCP tool authorization, agent identity, and external policy enforcement for enterprise AI agents on Google Cloud.