# 🧠 How to Build a Remote MCP Server in Python Using FastAPI



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

  1. Push your project to GitHub (create a new repo, e.g., mcp_remote_fastapi).
  2. Go to https://render.com and log in.
  3. Click New Web Service and connect your GitHub repo.
  4. Configure the service:
    • Build Command: pip install -r requirements.txt
    • Start Command: uvicorn main:app --host 0.0.0.0 --port 10000
    • Port: 10000
  5. 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


This content originally appeared on DEV Community and was authored by Christian Dennis HINOJOSA MUCHO