This content originally appeared on DEV Community and was authored by Christian Dennis HINOJOSA MUCHO
A step-by-step guide to creating a remote MCP (Message Control Protocol) server using Python and FastAPI, and deploying it online with Render.
Introduction
In this article, youβll learn how to build and deploy a remote MCP Server using Python and FastAPI. This type of server can receive messages from external clients and respond, making it useful in automation, control systems, and intelligent applications. Unlike local-only implementations, this version will be hosted online and accessible globally via HTTP.
What is an MCP Server?
An MCP Server is a message-processing system that listens for incoming client messages and responds in real time. In business intelligence contexts, MCP Servers can trigger data processes, integrate with analytics tools, or connect to AI agents like Claude.
Requirements
- Python 3.7+
- GitHub account
- A Render.com account (or Railway)
- Basic understanding of HTTP APIs and JSON
Step 1: Create the FastAPI MCP Server
Create a file named main.py
with the following content:
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Message(BaseModel):
content: str
@app.post("/mcp")
async def handle_message(msg: Message):
print(f"Received message: {msg.content}")
return {"response": "Hello from the remote MCP Server!"}
This FastAPI app listens for POST
requests at /mcp
and returns a JSON response.
Step 2: Add Requirements
Create a file requirements.txt
with:
fastapi
uvicorn
Step 3: Test Locally (Optional)
To run locally:
pip install -r requirements.txt
uvicorn main:app --reload
Visit: http://localhost:8000/docs
Try the /mcp
endpoint with a JSON body like:
{
"content": "Hello, MCP Server"
}
Step 4: Deploy to Render
- Push your project to GitHub (create a new repo, e.g.,
mcp_remote_fastapi
). - Go to https://render.com and log in.
- Click New Web Service and connect your GitHub repo.
- Configure the service:
-
Build Command:
pip install -r requirements.txt
-
Start Command:
uvicorn main:app --host 0.0.0.0 --port 10000
-
Port:
10000
-
Build Command:
- Click Deploy.
After a few seconds, Render will give you a public URL (e.g., https://mcp-xyz.onrender.com/mcp
).
You now have a fully remote MCP Server!
References
- Build a Remote MCP Server β Cloudflare Docs
- Build and Deploy a Remote MCP Server to Google Cloud Run β Google Cloud Blog
- MCP Server: A Step-by-Step Guide to Building from Scratch β Composio
- How to Build an MCP Server (Step-by-Step Guide) β Leanware
This content originally appeared on DEV Community and was authored by Christian Dennis HINOJOSA MUCHO