Model Context Protocol servers are becoming a core building block for agentic systems. They expose tools resources and prompts in a structured and predictable way so agents can rely on them as stable dependencies.
In this guide you will build a minimal MCP server using FastMCP and deploy it to Google Cloud Run. The result is a production ready server that can scale automatically and be consumed by any MCP compatible client.
This walkthrough assumes basic familiarity with Python and Google Cloud.
What You Will Build
You will create a simple MCP server that:
- Exposes a tool
- Runs as an HTTP service
- Is containerized with Docker
- Deploys to Cloud Run
- Scales automatically with demand
Prerequisites
- A Google Cloud project
- The gcloud CLI installed and authenticated
- Docker installed locally
- Python 3.10 or newer
Step 1: Create a New Python Project
Create a new folder and initialize a virtual environment.
mkdir mcp-server
cd mcp-server
python -m venv .venv
source .venv/bin/activateInstall FastMCP.
pip install fastmcpStep 2: Define Your MCP Server
Create a file called main.py.
from fastmcp import FastMCP
mcp = FastMCP(
name="example-mcp",
description="Example MCP server running on Cloud Run"
)
@mcp.tool()
def greet(name: str) -> str:
"""
Return a greeting for the given name.
"""
return f"Hello {name} from your MCP server"
app = mcp.http_app()What is happening here
- You create an MCP instance with metadata
- You register a tool using a decorator
- You expose an ASGI app that can be served over HTTP
This app object is what Cloud Run will execute.
Step 3: Add a Requirements File
Create a requirements.txt.
fastmcpCloud Run will use this during the container build.
Step 4: Create a Dockerfile
Create a file named Dockerfile.
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY main.py .
ENV PORT=8080
CMD ["python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]Key points
- Cloud Run expects the service to listen on port 8080
- Uvicorn runs the ASGI app exposed by FastMCP
- The container is small and fast to start
Step 5: Build and Push the Container
Authenticate Docker with Google Container Registry or Artifact Registry.
gcloud auth configure-dockerBuild and tag the image.
docker build -t gcr.io/YOUR_PROJECT_ID/mcp-server .Push the image.
docker push gcr.io/YOUR_PROJECT_ID/mcp-serverStep 6: Deploy to Cloud Run
Deploy the container.
gcloud run deploy mcp-server \
--image gcr.io/YOUR_PROJECT_ID/mcp-server \
--platform managed \
--region europe-west1 \
--allow-unauthenticatedOnce deployed Cloud Run will return a public URL.
That URL is now your MCP server endpoint.
Step 7: Verify the MCP Server
You can test the server by sending a request from an MCP compatible client or by inspecting the metadata endpoint exposed by FastMCP.
For example you should be able to see the registered tool and its schema and call it through an MCP client.
Cloud Run will automatically
- Scale to zero when idle
- Scale up with traffic
- Handle TLS and HTTPS
Production Considerations
Before using this in production consider the following
- Authentication for private MCP servers
- Versioning of tools and prompts
- Monitoring and logging
- Rate limiting and quotas
- Capability drift detection over time
These are especially important once agents start relying on your MCP server as a long lived dependency.
Why Cloud Run Works Well for MCP
Cloud Run is a great fit for MCP servers because
- MCP traffic is often bursty
- Cold starts are acceptable for many agent workflows
- You only pay when the server is used
- Scaling is fully managed
Combined with FastMCP you get a clean developer experience with minimal infrastructure overhead.
Next Steps
From here you can
- Add more tools resources and prompts
- Connect your MCP server to internal systems
- Add structured monitoring and status pages
- Run multiple MCP servers per workspace
Once deployed your MCP server becomes a reliable building block in the agentic ecosystem.
Happy building.