DEV Community

# ๐ŸŒ Deploying a Remote MCP Server with Python and FastAPI

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!"}
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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"
}
Enter fullscreen mode Exit fullscreen mode

The server will return:

{
  "response": "Hello from the remote MCP Server!"
}
Enter fullscreen mode Exit fullscreen mode

โ˜๏ธ Step 4: Deploy to Render

Now, letโ€™s make your MCP Server publicly accessible.

โœ… Steps:

  1. Push to GitHub

    Create a new repository and upload your files (main.py, requirements.txt, and optionally README.md).

  2. Log in to Render.com

    Create a new Web Service and connect your GitHub account.

  3. Deployment Settings:

    • Build Command:
     pip install -r requirements.txt
    
  • Start Command:

     uvicorn main:app --host 0.0.0.0 --port 10000
    
  • Port: 10000

  1. Click "Deploy" and wait for the build to finish.

After deploying, Render will assign a public URL like:

https://mcp-remote-example.onrender.com
Enter fullscreen mode Exit fullscreen mode

You can now access your Swagger docs at:

https://mcp-remote-example.onrender.com/docs
Enter fullscreen mode Exit fullscreen mode

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


โœ๏ธ Written by Christian Dennis Hinojosa Mucho

๐Ÿ”— GitHub Repository: https://github.com/dennisdhm7/mcp_u3


Top comments (1)

Collapse
 
pablo_mullunicardenas_9d profile image
Pablo Mulluni Cardenas

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!