Deploy a Secure MCP Server on Cloud Run
A comprehensive tutorial for building and deploying a Model Context Protocol (MCP) server to Google Cloud Run.
About this Workshop
| Subject | Last Updated | Written By |
|---|---|---|
| Cloud Run, MCP | Oct 28, 2025 | Luke Schlangen, Jack Wotherspoon |
1. Introduction
Overview
In this lab, you will build and deploy a Model Context Protocol (MCP) server. MCP servers are useful for providing LLMs with access to external tools and services. You will configure it as a secure, production-ready service on Cloud Run that can be accessed from multiple clients. Then you will connect to the remote MCP server from Gemini CLI.
What You'll Do
We will use FastMCP to create a zoo MCP server that has two tools: get_animals_by_species and get_animal_details. FastMCP provides a quick, Pythonic way to build MCP servers and clients.
What You'll Learn
- Deploy the MCP server to Cloud Run
- Secure your server's endpoint by requiring authentication for all requests, ensuring only authorized clients and agents can communicate with it
- Connect to your secure MCP server endpoint from Gemini CLI
2. Project Setup
If you don't already have a Google Account, you must create a Google Account.
Use a personal account instead of a work or school account. Work and school accounts may have restrictions that prevent you from enabling the APIs needed for this lab.
Sign in to the Google Cloud Console.
Enable billing in the Cloud Console.
Completing this lab should cost less than $1 USD in Cloud resources. You can follow the steps at the end of this lab to delete resources to avoid further charges. New users are eligible for the $300 USD Free Trial.
Create a new project or choose to reuse an existing project.
3. Open Cloud Shell Editor
Click this link to navigate directly to Cloud Shell Editor.
- If prompted to authorize at any point, click Authorize to continue.
- If the terminal doesn't appear at the bottom of the screen, open it:
- Click View
- Click Terminal
In the terminal, set your project with this command:
Format:
gcloud config set project [PROJECT_ID]Example:
gcloud config set project lab-project-id-example- If you can't remember your project ID, you can list all your project IDs with:
gcloud projects list | awk '/PROJECT_ID/{print $2}'
- If you can't remember your project ID, you can list all your project IDs with:
You should see this message:
Updated property [core/project].If you see a WARNING and are asked Do you want to continue (Y/n)?, then you have likely entered the project ID incorrectly. Press n, press Enter, and try to run the
gcloud config set projectcommand again.
4. Enable APIs
In the terminal, enable the necessary APIs:
gcloud services enable \
run.googleapis.com \
artifactregistry.googleapis.com \
cloudbuild.googleapis.com
If prompted to authorize, click Authorize to continue.
This command may take a few minutes to complete, but it should eventually produce a successful message similar to this one:
Operation "operations/acf.p2-73d90d00-47ee-447a-b600" finished successfully.
5. Prepare Your Python Project
Create a folder named
mcp-on-cloudrunto store the source code for deployment:mkdir mcp-on-cloudrun && cd mcp-on-cloudrunCreate a Python project with the
uvtool to generate apyproject.tomlfile:uv init --description "Example of deploying an MCP server on Cloud Run" --bare --python 3.13The
uv initcommand creates apyproject.tomlfile for your project. To view the contents of the file run the following:cat pyproject.tomlThe output should look like the following:
[project] name = "mcp-on-cloudrun"
Tools 2
get_animals_by_speciesRetrieves a list of animals belonging to a specific species.get_animal_detailsRetrieves specific details for a given animal.