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 the era of cloud-native applications, real-time data processing, and automation, message-driven architectures are increasingly essential. MCP (Message Control Protocol) servers act as intermediaries that listen for client messages, process them, and return responses in real time.
In this article, youโll learn how to build and deploy a remote MCP Server using Python and FastAPI. Unlike local implementations, this solution is cloud-hosted, accessible from anywhere via a public URL, and serves as a foundation for integrating smart clients, bots, or automations.
๐ฆ What is an MCP Server?
An MCP Server is a lightweight message-processing backend that listens for structured messagesโusually over HTTPโand responds based on predefined rules or logic. MCP Servers are especially useful when:
- You want to allow remote systems or users to trigger actions or computations.
- You need a controlled interface for communication between components.
- You're building a system where message acknowledgment or feedback is important.
In Business Intelligence (BI), an MCP server could be used to:
- Trigger scheduled data processing from external systems.
- Receive natural language inputs from chatbots and pass them to AI agents.
- Integrate dashboards and pipelines with real-time control endpoints.
๐ ๏ธ Requirements
Before you start, ensure you have the following:
- Python 3.7 or newer
- A GitHub account (for code hosting)
- A Render.com (or Railway) account for deployment
- Basic understanding of HTTP, JSON, and API interactions
๐งโ๐ป 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 server:
- Accepts
POST
requests at/mcp
- Receives a JSON body with a
"content"
key - Prints the message to the server logs
- Sends back a structured JSON response
This architecture is perfect for lightweight remote commands.
๐ฆ Step 2: Add Requirements
Create a requirements.txt
file with the dependencies for deployment:
fastapi
uvicorn
These packages are essential:
-
FastAPI
: for creating modern async APIs in Python. -
Uvicorn
: an ASGI server to run FastAPI apps in production or locally.
๐งช Step 3: Test Locally (Optional but Recommended)
To make sure everything works before going live:
pip install -r requirements.txt
uvicorn main:app --reload
Visit: http://localhost:8000/docs
FastAPI automatically generates interactive API docs using Swagger UI. You can test your /mcp
endpoint directly from there by sending a JSON like:
{
"content": "Hello, MCP Server"
}
The server will return:
{
"response": "Hello from the remote MCP Server!"
}
โ๏ธ Step 4: Deploy to Render
Now, letโs make your MCP Server publicly accessible.
โ Steps:
Push to GitHub
Create a new repository and upload your files (main.py
,requirements.txt
, and optionallyREADME.md
).Log in to Render.com
Create a new Web Service and connect your GitHub account.-
Deployment Settings:
- Build Command:
pip install -r requirements.txt
-
Start Command:
uvicorn main:app --host 0.0.0.0 --port 10000
Port:
10000
- Click "Deploy" and wait for the build to finish.
After deploying, Render will assign a public URL like:
https://mcp-remote-example.onrender.com
You can now access your Swagger docs at:
https://mcp-remote-example.onrender.com/docs
And test it just like you did locallyโonly now it works from anywhere!
๐ก Why Use MCP in Business Intelligence?
MCP Servers become highly useful in a modern BI pipeline when:
- You want external clients or apps to trigger data ingestion or processing remotely.
- You build automation workflows that respond to user input, chatbot messages, or API events.
- You create a control endpoint to update dashboards, refresh models, or notify downstream tools.
Because MCP Servers are lightweight, stateless, and decoupled, they are ideal for microservice environments and rapid experimentation.
๐ 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
โ๏ธ Written by Christian Dennis Hinojosa Mucho
๐ GitHub Repository: https://github.com/dennisdhm7/mcp_u3
Top comments (1)
Great work! ๐
This article provides a very clear explanation of how to build and deploy an MCP server using FastAPI.
I liked the structure and the way you showed each step, especially the Render deployment part.
This could be very useful for remote automation or integrating with external AI tools.
Thanks for sharing!