Cloud Run MCP Server

Cloud Run MCP Server

A secure MCP server example that demonstrates how to deploy to Google Cloud Run with authentication and identity token protection. Serves as a tutorial template for building production-ready MCP servers in the cloud.

Category
Visit Server

README

mcp-server-cloud-run

An example MCP server deployable to Cloud Run that is secured by authentication and requires an identity token to access.

Full Codelab tutorial available here: https://codelabs.developers.google.com/codelabs/cloud-run/how-to-deploy-a-secure-mcp-server-on-cloud-run

To run this example

Install dependencies

From the project root directory run the following command:

uv sync

Authenticate gcloud CLI

Authenticate the gcloud CLI using the following command:

gcloud auth application-default login

This will trigger an OAuth 2.0 flow and will prompt you to login to your Google account. Log in to your account using your credentials then return to your terminal once completed.

Deploy MCP server to Cloud Run

Set the environment variables related to your GCP project in the set_env.sh script. From the shell terminal run the following to source its variables:

chmod +x set_env.sh
source set_env.sh

Run the following command to deploy the MCP server to Cloud Run:

gcloud run deploy zoo-mcp-server \
    --no-allow-unauthenticated \
    --project=$GOOGLE_CLOUD_PROJECT \
    --region=$GOOGLE_CLOUD_LOCATION \
    --source=. \
    --labels=demo=mcp-server-cloud-run

Bind Cloud Run: Invoker role to end user account

The --no-allow-unauthenticated flag of the Cloud Run deployment command secures the MCP server by requiring an Authorization header with a valid Bearer <token> is presented to the server to allow traffic through.

Run the following command to give your user account permissions to invoke the MCP server on Cloud Run.

gcloud projects add-iam-policy-binding $GOOGLE_CLOUD_PROJECT \
    --member=user:$(gcloud config get-value account) \
    --role='roles/run.invoker'

Save your Google Cloud credentials and project number in environment variables for use in the Gemini CLI tool.

export PROJECT_NUMBER=$(gcloud projects describe $GOOGLE_CLOUD_PROJECT --format="value(projectNumber)")
export ID_TOKEN=$(gcloud auth print-identity-token)

You may need to re-run the command to export an ID_TOKEN if the token timteout expires.

Use an MCP Client to use tools on the MCP Server

To test the MCP Server and its authentication requirement, you will need an MCP Client.

To quickly test this setup, you can use the Gemini CLI. To install it you can run the following command from your shell:

npm install -g @google/gemini-cli@latest

This will install the latest Gemini CLI and requires having node package manager (npm) installed.

Configure Gemini CLI settings.json file

To tell the Gemini CLI to use your Cloud Run MCP Server with required Authentication parameters:

Open your Gemini CLI settings file:

vi ~/.gemini/settings.json

Add the zoo-remote server to the list of mcpServers available. Replace the PROJECT_NUMBER and GOOGLE_CLOUD_LOCATION with the settings for your project (if this is your first one, you can copy the settings below).

{
  "mcpServers": {
    "zoo-remote": {
      "httpUrl": "https://zoo-mcp-server-$PROJECT_NUMBER.$GOOGLE_CLOUD_LOCATION.run.app/mcp/",
      "headers": {
        "Authorization": "Bearer $ID_TOKEN"
      }
    }
  },
  "selectedAuthType": "cloud-shell",
  "hasSeenIdeIntegrationNudge": true
}

To retrieve a new token and update your settings file you can run the script update_token.sh to insert the updated token into the MCP server settings.

Use one of the MCP Server's tools

Start the Gemini CLI from your shell:

gemini

List MCP tools available to the Gemini CLI (MCP Client):

/mcp

Ask gemini to find something in the zoo:

Where can I find walruses?

You may need to tell the Gemini CLI to allow execution of the MCP tool running on the remote server.

The output should indicate that an MCP server tool defined in server.py was used.

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured