Skip to content
AI and automation4 min read

Deploy your own remote MCP server, in Node.js or Python

Short answer

A remote MCP server is a small web app that answers JSON-RPC on one URL such as /mcp. Build it with the official SDK in stateless mode with JSON responses, protect it with a secret key in an environment variable, and run it like any Node.js or Python app: on cPanel through Setup Node.js App or Setup Python App. In Python behind Passenger, start the SDK's session manager yourself, or every call answers 500.

ArabyHost teamLast updated: ShareWhatsAppXLinkedIn
Contents
  1. What a remote MCP server needs
  2. Option 1: Node.js
  3. Option 2: Python
  4. Two errors you will meet in Python
  5. Connect your apps to it
  6. Safety
  7. On ArabyHost

An MCP server gives an AI assistant tools: check an order, search your catalogue, create a ticket. Running it on your computer works for you alone. Put it on a server and the same tools work from Claude Code on your laptop, Cursor on a colleague’s machine, and Codex on your server. This guide builds a small working server in Node.js and in Python, the way we tested it with the official MCP client.

What a remote MCP server needs

  • One HTTPS URL, such as https://mcp.example.com/mcp, that accepts POST requests with JSON.
  • The Streamable HTTP transport from the official SDK. In stateless mode with JSON responses, every request gets a plain JSON answer and nothing stays open, which suits any web server.
  • A secret key checked on every request, kept in an environment variable, never in the code.
  • A process manager that starts the app and restarts it: on cPanel, Phusion Passenger through Setup Node.js App or Setup Python App.

Option 1: Node.js

Install the SDK in the app folder:

npm install @modelcontextprotocol/sdk express zod

app.js:

const express = require("express");
const { McpServer } = require("@modelcontextprotocol/sdk/server/mcp.js");
const { StreamableHTTPServerTransport } = require("@modelcontextprotocol/sdk/server/streamableHttp.js");
const { z } = require("zod");

function buildServer() {
  const server = new McpServer({ name: "my-tools", version: "1.0.0" });
  server.registerTool(
    "order_status",
    { description: "Return the status of an order by its number",
      inputSchema: { order: z.string().describe("Order number") } },
    async ({ order }) => ({ content: [{ type: "text", text: `Order ${order}: shipped` }] })
  );
  return server;
}

const app = express();
app.use(express.json());

app.use("/mcp", (req, res, next) => {
  const token = process.env.MCP_TOKEN;
  if (!token || req.headers.authorization !== `Bearer ${token}`) {
    return res.status(401).json({ error: "unauthorized" });
  }
  next();
});

app.post("/mcp", async (req, res) => {
  const server = buildServer();
  const transport = new StreamableHTTPServerTransport({
    sessionIdGenerator: undefined, // stateless
    enableJsonResponse: true,      // plain JSON replies
  });
  res.on("close", () => { transport.close(); server.close(); });
  await server.connect(transport);
  await transport.handleRequest(req, res, req.body);
});

app.get("/mcp", (req, res) => res.status(405).end());
app.delete("/mcp", (req, res) => res.status(405).end());

app.listen(process.env.PORT || 3000);

On cPanel, create the app in Setup Node.js App with app.js as the startup file, add MCP_TOKEN as an environment variable, run Run NPM Install, then restart. The steps for any Node app are in deploy a Node.js app.

Option 2: Python

Install the official SDK and the WSGI adapter in the app’s virtual environment:

pip install mcp a2wsgi

server.py:

import os
from mcp.server.mcpserver import MCPServer
from mcp.server.transport_security import TransportSecuritySettings

mcp = MCPServer("my-tools")

@mcp.tool()
def order_status(order: str) -> str:
    """Return the status of an order by its number."""
    return f"Order {order}: shipped"

class RequireToken:
    def __init__(self, app):
        self.app = app

    async def __call__(self, scope, receive, send):
        if scope["type"] == "http":
            token = os.environ.get("MCP_TOKEN", "")
            auth = dict(scope["headers"]).get(b"authorization", b"").decode()
            if not token or auth != f"Bearer {token}":
                await send({"type": "http.response.start", "status": 401,
                            "headers": [(b"content-type", b"application/json")]})
                await send({"type": "http.response.body", "body": b'{"error": "unauthorized"}'})
                return
        await self.app(scope, receive, send)

app = RequireToken(mcp.streamable_http_app(
    stateless_http=True,
    json_response=True,
    transport_security=TransportSecuritySettings(allowed_hosts=[os.environ["MCP_HOST"]]),
))

passenger_wsgi.py:

import asyncio
from a2wsgi import ASGIMiddleware
from server import app, mcp

application = ASGIMiddleware(app)

# Passenger never sends the ASGI startup event, so start the session manager here.
async def _run_session_manager():
    async with mcp.session_manager.run():
        await asyncio.Event().wait()

asyncio.run_coroutine_threadsafe(_run_session_manager(), application.loop)

Set MCP_TOKEN and MCP_HOST (your domain, such as mcp.example.com) as environment variables in Setup Python App. This uses version 2 of the Python SDK, where FastMCP became MCPServer; older tutorials import FastMCP.

Two errors you will meet in Python

What you see Why Fix
500 and Task group is not initialized in the log Passenger doesn’t run the ASGI lifespan that starts the session manager The last lines of passenger_wsgi.py above
421 Invalid Host header The SDK’s DNS-rebinding protection only allows the host names you list Put your exact domain in MCP_HOST

Connect your apps to it

Claude Code:

claude mcp add --transport http my-tools https://mcp.example.com/mcp --header "Authorization: Bearer YOUR_KEY"

Cursor, in ~/.cursor/mcp.json:

{ "mcpServers": { "my-tools": { "url": "https://mcp.example.com/mcp", "headers": { "Authorization": "Bearer YOUR_KEY" } } } }

Codex, in ~/.codex/config.toml, with the key in the MY_TOOLS_TOKEN environment variable:

[mcp_servers.my-tools]
url = "https://mcp.example.com/mcp"
bearer_token_env_var = "MY_TOOLS_TOKEN"

If it doesn’t show as connected, see MCP server not connecting.

Safety

  • Give each tool the least it needs: a read-only database user for read tools.
  • Keep the key long and random, and change it if it leaks.
  • Log tool calls, and never return passwords or full customer records in tool results.

On ArabyHost

The AI and Developer plans run both versions as they are: Node.js 20 and 24 through Setup Node.js App, Python 3.12 through Setup Python App, free SSL for the subdomain your server answers on, SSH and Git for deploying, and daily backups. Read more in MCP server hosting. And if what you need is managing your hosting itself from Claude, that’s already built: Araby MCP works on every plan.

FAQ

What's the difference between a local and a remote MCP server?

A local server runs on your computer and talks to the app over stdio, so only you can use it. A remote server runs on a server and talks over HTTP, so you, your team and your other devices can use the same tools from anywhere.

Why stateless mode?

Each request stands alone, so the server keeps nothing in memory between calls. That suits hosting where the web server may start several processes or restart an idle one, and it's enough for tools that read or write data.

Can claude.ai or ChatGPT connect to it?

Their custom connectors expect sign-in through OAuth, not a fixed key in a header. The key method in this guide is for Claude Code, Cursor, Codex and other apps that let you set headers.

Useful? Share it with someone who needs it:WhatsAppXLinkedIn

Read next

Ready to put your idea online?

Fast, isolated hosting, support that understands you, and an AI assistant that fixes problems with you.