Back to paths

Tools and integrations through MCP

Connect an agent to enterprise systems through the Model Context Protocol. Choose a Google Cloud MCP server, MCP Toolbox for Databases or a custom MCP server, expose only named, parameterised queries, and register what agents may use in Agent Registry.

advanced~25 min#agentic-ai#mcp#tools#integrations
Chapter 4Custom agentsLesson 5 of 8Show

Prerequisites: Building agents with ADK


Why agents need integrations

An agent is useful only when it acts on real systems: reading orders, querying analytics, booking a pickup. In the ADK lesson each of those was a Python function inside the agent. That works for one agent, but every team ends up rewriting the same database and API wrappers, each with its own credentials and its own bugs.

The is an open standard for offering tools to agents. An MCP server publishes a set of tools, each with a name, a description and a parameter schema; an MCP client, such as an ADK agent, lists those tools, offers them to the model and calls them when the model proposes one. The loop from The agent loop does not change: the model proposes, the runtime executes, but the execution now happens in the MCP server. Write the server once, and any MCP-capable agent can use it.

A server can run as a local process the client starts and talks to over standard input and output (the stdio transport), or as a remote service the client reaches over HTTP (the streamable HTTP transport). Agents in production use remote servers.

Three routes, three owners

Take the support agent from the ADK lesson and give it three new capabilities. Access on Google Cloud is controlled by IAM (Identity and Access Management), which grants identities roles that decide who may call what.

CapabilityRouteWho hosts and updates itWho secures it
Query sales analytics in BigQueryA Google Cloud MCP server (BigQuery's)GoogleIAM roles you grant on your project
Look up one customer's order in the orders databaseMCP Toolbox for Databases, with named queriesYou run the open-source server; you write the queriesYou: database account, query design, caller authentication
Book a pickup through the internal carrier APIA custom MCP serverYou build, host and patch itYou, end to end

The map below draws the three routes, with Agent Registry underneath. Predict which route leaves your team the least to run for the BigQuery analytics, then click each server to see who hosts it, who updates it and who secures it.

Simulation: mcp-routes-explorer

are remote MCP servers that run on Google's infrastructure and offer an HTTP endpoint for a Google Cloud service, for example BigQuery, Cloud SQL, Spanner, GKE or Cloud Storage. You enable the product's API, and access goes through IAM: the caller needs the MCP Tool User role plus the product's own roles. To keep an agent to read-only tools, an IAM deny policy can block every tool that is not marked read-only. When a server exists for the service, use it: Google runs and updates it, and you only manage access.

is an open-source MCP server that connects agents to databases (AlloyDB, BigQuery, Cloud SQL, Spanner, PostgreSQL, MySQL and many more). You describe each tool in a configuration file: the source, a fixed SQL statement and its parameters. Choose it when the agent needs specific queries against your own tables.

A custom MCP server wraps an internal API that nothing else covers. Build it with an MCP SDK and host it where agents can reach it over HTTP. Cloud Run (Google Cloud's serverless container service) supports MCP servers that use streamable HTTP, not stdio, and requires an IAM identity on every request by default. A common layout runs the agent on Agent Runtime (Google Cloud's managed service for running agents) and the MCP server as a separate Cloud Run service.

A Google Cloud service already has a remote MCP server. Why use it rather than write your own?

Database tools: named queries, never free-form SQL

The fastest way to connect an agent to a database is one tool that runs any SQL the model writes. It is also the most dangerous. The model can read every table the database account can, run an UPDATE that text it retrieved talked it into, (a prompt injection), or return another customer's rows. MCP Toolbox's own execute-SQL tools carry the warning that they are for developer workflows with a human in the loop, not production agents.

Give the agent named, parameterised queries instead: each tool has a fixed statement, and the model only supplies typed values, which are bound as query parameters, never spliced into the SQL. Here is the order lookup as an MCP Toolbox configuration (one YAML document per source, auth service and tool):

kind: source
name: orders-db
type: cloud-sql-postgres
project: my-project
region: europe-west1
instance: orders
database: orders
user: ${DB_USER}
password: ${DB_PASSWORD}
---
kind: authService
name: customer-auth
type: google
clientId: ${OAUTH_CLIENT_ID}
---
kind: tool
name: get-my-order
type: postgres-sql
source: orders-db
description: Returns the status and tracking id of one of the signed-in customer's orders. Use when the customer gives an order id.
parameters:
  - name: order_id
    type: string
    description: The order id, for example A1234.
  - name: customer_id
    type: string
    description: The signed-in customer's id.
    authServices:
      - name: customer-auth
        field: sub
statement: SELECT status, tracking_id FROM orders WHERE order_id = $1 AND customer_id = $2;

Three choices make this safe:

  • A fixed statement. The agent can run this one SELECT and nothing else. Add one named tool per action the agent needs.
  • An authenticated parameter. customer_id is filled from the caller's verified Google OIDC token (a signed identity token whose sub claim is the user's unique id), not by the model. A user who types someone else's id into the chat still gets only their own orders.
  • Secrets from the environment. The database user and password come from environment variables (in production, a secret manager), never from the file.

Also give the database account only the privileges the tools need, such as read access to the orders table.

What is an authenticated parameter in MCP Toolbox?

An ADK agent loads these tools from a running Toolbox server, and loads a remote MCP server's tools through McpToolset:

from google.adk.agents import LlmAgent
from google.adk.tools.mcp_tool import McpToolset
from google.adk.tools.mcp_tool.mcp_session_manager import StreamableHTTPConnectionParams
from google.adk.tools.toolbox_toolset import ToolboxToolset
import google.auth.transport.requests
from google.oauth2 import id_token
 
orders_tools = ToolboxToolset(
    server_url="https://toolbox-orders.example.run.app",
    # get_user_id_token returns the signed-in user's Google ID token,
    # which Toolbox verifies to fill the authenticated customer_id parameter
    auth_token_getters={"customer-auth": get_user_id_token},
)
 
CARRIER_URL = "https://carrier-mcp.example.run.app"  # your custom server on Cloud Run
 
def carrier_auth_headers(ctx):
    # The agent's own service identity proves itself to Cloud Run: a fresh
    # ID token for the service's URL (its audience), on every new MCP session.
    token = id_token.fetch_id_token(google.auth.transport.requests.Request(), CARRIER_URL)
    return {"Authorization": f"Bearer {token}"}
 
carrier_tools = McpToolset(
    connection_params=StreamableHTTPConnectionParams(url=f"{CARRIER_URL}/mcp"),
    header_provider=carrier_auth_headers,
    tool_filter=["book_pickup", "get_pickup_status"],  # offer the model only these
)
 
support_agent = LlmAgent(
    name="support_agent",
    model="gemini-flash-latest",
    instruction="You help customers with their orders and returns.",
    tools=[orders_tools, carrier_tools],
)

tool_filter limits which of a server's tools the model is offered, so it sees only the declarations it needs and cannot call the rest. It is not access control: because the Cloud Run service requires IAM, the agent's own service identity must be allowed to invoke it (the invoker role) and must also send an identity token with each request, which is what carrier_auth_headers does. The role alone attaches no token. This is a different boundary from get_user_id_token above, which carries the end user's identity to Toolbox. The security lessons later in this path cover agent identities.

Register what agents may use

Once several teams build MCP servers, nobody can see which agents use what. is the catalogue: it lists the agents, MCP servers and their tools, and endpoints in your project or organisation.

  • Google Cloud remote MCP servers are registered automatically.
  • Custom servers register automatically in some cases: a Cloud Run service deployed with --functional-type=mcp-server, or a GKE workload with the matching label. Otherwise you register one yourself, with gcloud agent-registry services create and a tool spec file that describes its tools. The carrier server, deployed to Cloud Run with that flag, appears in the registry with its two tools and no extra step.
  • Governance: access policies bind agent identities to the registered servers they may use, and Agent Gateway enforces them at runtime on agent traffic routed through it.
  • Discovery: an ADK agent can look a registered server up and load its tools from the registry, instead of hard-coding a URL.
  • Search: the registry searches registered agents, A2A skills, standalone skills and MCP servers. MCP servers are found by keyword over the server's name and description and its tools' names and descriptions. Standalone skills can also be searched semantically (--search-type=semantic), a mode Google describes as optimised for orchestrator agents finding capabilities by intent.

Search matters because loading every tool does not scale. Google's architecture guidance calls the problem : too many tool definitions in the system prompt, sent with every request. They dilute the model's attention, so it picks the wrong tool more often, and they add tokens, cost and latency. Google lists several fixes that can be combined: simpler tools, smaller toolsets split by task, and progressive disclosure, unlocking tools only when they are needed. One form of progressive disclosure is the search tool pattern: the agent gets a single search tool and loads only the relevant tool schema when a task calls for it, instead of declaring every tool up front. (Context engineering at scale measures what declarations cost per call.)

What is tool bloat, and what does the search tool pattern do about it?

Registration does not host, scale or secure the server for you. It makes the server findable and puts its use under policy, which is what lets a security team answer "which agents can book pickups?"

Sources

Show 11 sourcesHide sources
SourcePublisherWhat it supports
Google Cloud MCP servers overview (opens in a new tab)docs.cloud.google.comGoogle Cloudremote MCP servers run on the service's infrastructure and offer an HTTP endpoint
Search for agents and tools (opens in a new tab)docs.cloud.google.comGoogle Cloudkeyword search over MCP server and tool names and descriptions; semantic search over SKILL.md for standalone skills, optimised for orchestrator agents
Choose your agentic AI architecture components (opens in a new tab)docs.cloud.google.comGoogle Cloud Architecture Centertool bloat: too many tool definitions in the system prompt; mitigations: limit tool complexity, granular toolsets, progressive disclosure; the search tool pattern loads only the relevant tool schema
Supported products (opens in a new tab)docs.cloud.google.comGoogle CloudBigQuery, Cloud SQL, Spanner, GKE, Cloud Storage and others, with their endpoints
Access control for MCP servers (opens in a new tab)docs.cloud.google.comGoogle CloudMCP Tool User role, roles/mcp.toolUser, plus the product's roles
Restrict MCP tools to read-only (opens in a new tab)docs.cloud.google.comGoogle CloudIAM deny policies on tools not marked read-only
Host MCP servers on Cloud Run (opens in a new tab)docs.cloud.google.comGoogle Cloudstreamable HTTP supported, stdio not; IAM-authorised requests by default; clients send an ID token for the service, section "Authentication"
MCP Toolbox for Databases (opens in a new tab)github.comGoogleopen-source MCP server for databases; tool configuration; authenticated parameters; execute-SQL tools are for developer workflows with a human in the loop, not production agents
MCP tools (opens in a new tab)github.comGoogle, Agent Development Kit documentationMcpToolset, StreamableHTTPConnectionParams, tool_filter
MCP Toolbox for Databases (opens in a new tab)github.comGoogle, Agent Development Kit documentationToolboxToolset
"Agent Registry overview" and "Register MCP servers" (opens in a new tab)and docs.cloud.google.com/agent-registry/register-mcp-servers (opens in a new tab)docs.cloud.google.comGoogle Cloudwhat the registry catalogues; automatic registration of Google remote MCP servers; manual registration; access policies

Suggested videos

Show 3 videosHide videos

Review

Flashcards1 / 3

Name the three routes for giving an agent tools through MCP, and when each fits.

Check yourself

Quick exam1 / 8 · 0 correct

A support agent needs to run analytics queries over the company's BigQuery datasets. Google offers a remote MCP server for BigQuery. What is the best route?

Go deeper

Your notes on this lesson