Deploying machine learning components and APIs at scale has become easier than ever with the rise of managed serverless platforms. For developers and teams working with FastMCP, a framework for building Model Context Protocol (MCP) servers, combining it with Google Cloud Run offers a powerful and cost-efficient way to expose remote MCP servers to clients worldwide.
In this article, we’ll walk step by step through how to deploy a remote MCP server using FastMCP and Google Cloud Run. By the end, you’ll have a clear roadmap for taking your MCP-based applications from local development to a production-ready, scalable, and secure deployment.
What is FastMCP?
FastMCP is a developer-friendly framework that simplifies building MCP (Model Context Protocol) servers. MCP is a specification that defines how tools, models, and contexts interact in structured environments, especially useful for connecting AI systems to external tools and APIs.
FastMCP provides the scaffolding, routing, and communication layers necessary to quickly create MCP-compatible servers. Instead of building protocols and handlers from scratch, developers can define their tools and contexts in Python, while FastMCP takes care of the protocol-compliant server layer. You can explore more on the official FastMCP GitHub repository.
Why Deploy with Google Cloud Run?
Google Cloud Run is a fully managed compute platform that automatically scales your containerized applications. It runs on top of Google’s serverless infrastructure and offers several advantages for deploying MCP servers:
- Scalability: Cloud Run automatically scales your container up or down depending on incoming requests, ensuring you only pay for what you use.
- Simplicity: No need to manage Kubernetes clusters or VM infrastructure. Just deploy a container and you’re live.
- Security: Cloud Run provides HTTPS endpoints, IAM integration, and automatic isolation per request.
- Cost Efficiency: With per-request billing, it’s ideal for workloads that may be idle for long periods.
If you want to dive deeper, you can check out the official Google Cloud Run documentation.
Prerequisites
Before we dive into deployment, make sure you have the following:
- A Google Cloud account with billing enabled
- Google Cloud SDK (
gcloud) installed locally - Docker installed to build container images
- A working FastMCP server locally (Python project)
Step 1: Build Your FastMCP Server
Let’s start by creating a simple FastMCP server. For example, a basic server could look like this:
from fastmcp import MCPApp, tool
app = MCPApp("example-mcp")
@tool
def hello_world(name: str) -> str:
return f"Hello, {name}!"
if __name__ == "__main__":
app.run()
This simple FastMCP app defines a tool called hello_world that returns a greeting. When run locally, it exposes the MCP protocol over a socket or HTTP depending on your configuration.
Step 2: Containerize the Application
To run this server on Google Cloud Run, we need to package it inside a Docker container. Create a Dockerfile like this:
# Use official Python image
FROM python:3.11-slim
# Set working directory
WORKDIR /app
# Copy project files
COPY . /app
# Install dependencies
RUN pip install --no-cache-dir fastmcp gunicorn
# Expose port
EXPOSE 8080
# Run the MCP app with Gunicorn
CMD ["gunicorn", "-b", "0.0.0.0:8080", "app:app"]
Here, we:
- Start from a Python 3.11 slim image
- Copy the MCP server code into the container
- Install FastMCP and Gunicorn for serving
- Expose port
8080since Cloud Run expects it - Run the app with Gunicorn for production reliability
Step 3: Build and Push the Docker Image
Next, we’ll build the Docker image and push it to Google’s container registry:
# Set project ID
gcloud config set project YOUR_PROJECT_ID
# Build container
gcloud builds submit --tag gcr.io/YOUR_PROJECT_ID/mcp-server
This will build your image and store it in Google Container Registry (GCR) or Artifact Registry.
Step 4: Deploy to Google Cloud Run
Once the image is built and pushed, deploy it with:
gcloud run deploy mcp-server \
--image gcr.io/YOUR_PROJECT_ID/mcp-server \
--platform managed \
--region us-central1 \
--allow-unauthenticated
Here’s what each flag does:
--image: The container image to deploy--platform managed: Runs on fully managed Cloud Run--region: Deployment region--allow-unauthenticated: Makes the service publicly accessible
After a few moments, Cloud Run will give you a live HTTPS endpoint where your MCP server is deployed.
Step 5: Configure the MCP Client
To use the deployed server, you need to configure your MCP client with the Cloud Run endpoint. For example, if you’re connecting from an AI assistant, update its configuration to point to:
{
"servers": {
"example-mcp": {
"url": "https://YOUR_CLOUD_RUN_URL"
}
}
}
This tells your MCP-compatible client where to send requests.
Step 6: Add Authentication (Optional but Recommended)
By default, allowing unauthenticated requests makes your MCP server public. While this might be fine for experimentation, in production you’ll likely want authentication.
You can enable IAM-based authentication in Cloud Run and issue identity tokens from clients. Alternatively, you can add an API key or OAuth layer inside your FastMCP server code to validate requests before executing tools. For more on IAM, see Google’s Cloud Run authentication guide.
Best Practices
When deploying MCP servers in production, consider these best practices:
- Monitoring: Use Google Cloud Logging and Monitoring to track request volume and errors.
- Scaling: Configure minimum and maximum instances to balance performance and cost.
- Security: Restrict access with IAM or API keys to prevent misuse.
- Testing: Test your server locally and in staging before production deployment.
Conclusion
Deploying a remote MCP server with FastMCP and Google Cloud Run combines the simplicity of FastMCP for protocol-compliant server development with the scalability of Google’s serverless infrastructure. In just a few steps: writing your FastMCP app, containerizing it, pushing the image, and deploying to Cloud Run, you can have a fully functioning, production-ready MCP server accessible worldwide.
This approach not only reduces operational overhead but also ensures your MCP-based applications are flexible, secure, and cost-efficient. Whether you’re experimenting with AI integrations or building production-grade tools, this deployment pattern offers a solid foundation.
If you enjoyed this article, check out more guides on my blog. You can also learn more about me or get in touch for any kind of feedback on the article.