How to Deploy Your MCP Server to Google Cloud with Docker
Ready to take your MCP (Model Context Protocol) server from localhost to the cloud? Here's the complete step-by-step guide to get it running on Google Cloud Run.
📺 Watch the full walkthrough:
Step 1: Create Your Google Cloud Project
First, let's set up a new project for your MCP server:
# Create a new project
gcloud projects create your-mcp-project --name="Your MCP Server"
# Set it as your active project
gcloud config set project your-mcp-project
Step 2: Install Google Cloud CLI
macOS (with Homebrew):
brew install google-cloud-sdk
Windows: Download from https://cloud.google.com/sdk/docs/install
Linux:
curl https://sdk.cloud.google.com | bash
exec -l $SHELL
Step 3: Authenticate
gcloud auth login
This opens your browser to sign in with your Google account.
Step 4: Build Your Docker Image
Make sure your app listens on the PORT environment variable, then build:
# Build for Cloud Run (important: specify platform)
docker build --platform linux/amd64 -t your-mcp-server .
# Verify it was built
docker images
Step 5: Enable Required Services
# Enable Artifact Registry and Cloud Run
gcloud services enable artifactregistry.googleapis.com
gcloud services enable run.googleapis.com
Step 6: Create Docker Repository
# Create a repository for your Docker images
gcloud artifacts repositories create mcp-repo \
--repository-format=docker \
--location=us-central1
Step 7: Set Up IAM Permissions
# Grant yourself editor permissions
gcloud projects add-iam-policy-binding your-mcp-project \
--member="user:your-email@gmail.com" \
--role="roles/editor"
# Grant Artifact Registry writer permissions
gcloud projects add-iam-policy-binding your-mcp-project \
--member="user:your-email@gmail.com" \
--role="roles/artifactregistry.writer"
Step 8: Configure Docker Authentication
# Allow Docker to push to Google's registry
gcloud auth configure-docker us-central1-docker.pkg.dev
Step 9: Tag and Push Your Image
# Tag your image for the registry
docker tag your-mcp-server \
us-central1-docker.pkg.dev/your-mcp-project/mcp-repo/your-mcp-server:latest
# Push it to Google's registry
docker push \
us-central1-docker.pkg.dev/your-mcp-project/mcp-repo/your-mcp-server:latest
Step 10: Deploy to Cloud Run
# Deploy your container
gcloud run deploy your-mcp-server \
--image us-central1-docker.pkg.dev/your-mcp-project/mcp-repo/your-mcp-server:latest \
--region us-central1 \
--allow-unauthenticated \
--memory 1Gi \
--port 8080
That's it! Cloud Run will give you a URL where your MCP server is now live.
The Critical Detail: PORT Environment Variable
The #1 reason deployments fail is port configuration. Your MCP server, as well the dockerfile AND google cloud deploy must listen on the same PORT !
// ✅ Correct
mcp.run(
transport="streamable-http",
host="0.0.0.0",
port=port,
log_level="debug",
)
// ❌ Wrong - will fail
mcp.run()
Quick Debug Commands
If something goes wrong:
# Check your services
gcloud run services list
# View logs
gcloud logs tail --project=your-mcp-project
# Test locally first
PORT=8080 docker run -p 8080:8080 -e PORT=8080 your-mcp-server
Even Better: Use a Makefile
For future deployments, I've created a dynamic Makefile that handles all these steps automatically. Just configure your project variables in the .env and run:
# One-time setup, or set it in .env
make gcp-setup PROJECT_ID=your-project-id
# Future deployments
make deploy-image
The Makefile handles building, tagging, pushing, and deploying with a single command. Perfect for when you want to deploy quickly without remembering all the gcloud flags.
Whats you biggest issue on deploying your MCP server? write it in comments
Thanks for reading
J