GCP MCP (Model Context Protocol) Guide
This skill provides comprehensive guidance on interacting with, deploying, and governing Model Context Protocol (MCP) servers and tools within Google Cloud and the Gemini Enterprise Agent Platform. It covers native Google Cloud managed endpoints (OneMCP), custom MCP deployments (like the Looker Toolbox), and integration with the ADK (Agent Development Kit).
1. Discovering MCP Endpoints
Agents and developers can discover available MCP endpoints in two primary ways:
- Google Cloud REST Directory: Query
https://serviceusage.googleapis.com/v2beta/services?filter=mcp_server:urls. This returns native GCP service MCP endpoints (e.g.,bigquery.googleapis.com/mcp,spanner.googleapis.com/mcp). - Agent Registry (ADK): Query the Agent Registry for registered custom or native MCP servers.
from google.adk.integrations.agent_registry.agent_registry import AgentRegistry registry = AgentRegistry(project_id="your-project", location="us-central1") servers = registry.list_mcp_servers()
2. OneMCP: Native Google Cloud & Apigee MCP Endpoints
Google Cloud services automatically expose managed MCP endpoints that don't require infrastructure setup.
- URL Format:
<service>.googleapis.com/mcp - Listing Tools (
tools/list): Unauthenticated POST request.{ "jsonrpc": "2.0", "method": "tools/list" } - Calling Tools (
tools/call): Requires OAuth2 authentication and proper IAM permissions. - Authentication:
- End Users: OAuth2 flow via standard Google auth endpoints.
- Agents: GCP Service Accounts. Tokens fetched from metadata server or via
gcloud auth application-default print-access-token. Pass in header:Authorization: Bearer <token>.
- Authorization: The principal (user or agent service account) MUST have the
mcp.tools.callIAM permission (included in theroles/mcp.toolUserrole) on the target GCP project/resource.
3. Custom MCP Servers (e.g., Looker Toolbox, 3rd Party Binaries)
To use a custom MCP binary (which usually communicates via stdio) in a cloud environment:
- Wrap in an SSE Proxy: Create a FastAPI wrapper using
mcp.server.sse.SseServerTransportthat bridges incoming HTTP Server-Sent Events (SSE) to the binary'sstdiosubprocess. - Deploy to Cloud Run: Package the binary (Linux version) and the wrapper into a Docker container and deploy it as a Cloud Run service (
https://your-service.a.run.app/sse). - Register with Agent Registry: (See Section 4).
4. Agent Registry: Registering Custom MCP Servers
To make a custom Cloud Run MCP endpoint available to Gemini Enterprise Agents natively, it must be registered as a Service in the Agent Registry via the REST API (v1alpha).
API Endpoint: POST https://agentregistry.googleapis.com/v1alpha/projects/{project}/locations/{location}/services?serviceId={service_id}
Payload Schema (Verified):
{
"displayName": "My Custom MCP",
"description": "Description of the MCP server.",
"interfaces": [
{
"protocolBinding": "HTTP_JSON",
"url": "https://your-cloud-run-url.a.run.app/sse"
}
],
"mcpServerSpec": {
"type": "TOOL_SPEC",
"content": {
"tools": [
{
"name": "tool_name",
"description": "Tool description",
"inputSchema": { "type": "object", "properties": {} },
"annotations": {
"readOnlyHint": true,
"destructiveHint": false,
"idempotentHint": true
}
}
]
}
}
}
Note: The tool array must exactly match the schema returned by a standard MCP tools/list response. Max size: 10KB.
5. Consuming MCPs in ADK Sessions
Once an MCP server is registered in the Agent Registry, ADK orchestration code can dynamically pull and use its toolset without hardcoding URLs or manual protocol management.
from google.adk.integrations.agent_registry.agent_registry import AgentRegistry
from google.adk.agents import Agent
registry = AgentRegistry(project_id="your-project", location="us-central1")
# Use short format "mcpServers/SERVER_ID" or full resource name
my_mcp_toolset = registry.get_mcp_toolset(mcp_server_name="mcpServers/looker-mcp-server")
my_agent = Agent(
name="data_expert",
tools=[my_mcp_toolset],
instruction="You have access to MCP tools."
)
6. Security and Governance (Defense in Depth)
GCP provides several layers to secure MCP traffic:
- Organization Policies: Use
gcp.managed.allowedMCPServicesto block/allow specific MCP endpoints across folders/projects, or conditionally based on resource tags (e.g., allow only inenvironment: dev). - IAM Deny Policies: Can block mutable actions by inspecting the
tool.isReadOnlyattribute.- Condition:
api.getAttribute('mcp.googleapis.com/tool.isReadOnly') == false
- Condition:
- VPC Service Controls (VPC-SC): Can block/allow ingress/egress based on
api.mcp.is_mcp,api.mcp.tool.is_read_only, or the agent's identity (request.auth.oauth.client_id). - Model Armor: Inspects and blocks harmful content in
tools/callrequests/responses (Jailbreaks, PI data). Enabled viagcloud model-armor floorsettings update ... --add-integrated-services=GOOGLE_MCP_SERVER. - Cloud Audit Logs: Captures MCP attributes (tool name, OAuth client ID,
mcp.tools.calloperations) for anomaly detection and compliance.