Context Blog
/Tutorials

Building and Deploying an MCP Server on Cloud Run with FastMCP

December 16, 2025
Building and Deploying an MCP Server on Cloud Run with FastMCP

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

  1. A Google Cloud project
  2. The gcloud CLI installed and authenticated
  3. Docker installed locally
  4. Python 3.10 or newer

Step 1: Create a New Python Project

Create a new folder and initialize a virtual environment.

Bash
mkdir mcp-server
cd mcp-server
python -m venv .venv
source .venv/bin/activate

Install FastMCP.

Bash
pip install fastmcp

Step 2: Define Your MCP Server

Create a file called main.py.

python
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

  1. You create an MCP instance with metadata
  2. You register a tool using a decorator
  3. 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.

Text
fastmcp

Cloud Run will use this during the container build.

Step 4: Create a Dockerfile

Create a file named Dockerfile.

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

  1. Cloud Run expects the service to listen on port 8080
  2. Uvicorn runs the ASGI app exposed by FastMCP
  3. The container is small and fast to start

Step 5: Build and Push the Container

Authenticate Docker with Google Container Registry or Artifact Registry.

Bash
gcloud auth configure-docker

Build and tag the image.

Bash
docker build -t gcr.io/YOUR_PROJECT_ID/mcp-server .

Push the image.

Bash
docker push gcr.io/YOUR_PROJECT_ID/mcp-server

Step 6: Deploy to Cloud Run

Deploy the container.

Bash
gcloud run deploy mcp-server \
  --image gcr.io/YOUR_PROJECT_ID/mcp-server \
  --platform managed \
  --region europe-west1 \
  --allow-unauthenticated

Once 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

  1. Scale to zero when idle
  2. Scale up with traffic
  3. Handle TLS and HTTPS

Production Considerations

Before using this in production consider the following

  1. Authentication for private MCP servers
  2. Versioning of tools and prompts
  3. Monitoring and logging
  4. Rate limiting and quotas
  5. 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

  1. MCP traffic is often bursty
  2. Cold starts are acceptable for many agent workflows
  3. You only pay when the server is used
  4. Scaling is fully managed

Combined with FastMCP you get a clean developer experience with minimal infrastructure overhead.

Next Steps

From here you can

  1. Add more tools resources and prompts
  2. Connect your MCP server to internal systems
  3. Add structured monitoring and status pages
  4. Run multiple MCP servers per workspace

Once deployed your MCP server becomes a reliable building block in the agentic ecosystem.

Happy building.

Latest Posts