Deploy an MCP Server on AWS EC2

Deploy a remote MCP server on an Amazon Linux EC2 instance — SSH in, install Anaconda and uv, serve over Streamable HTTP with OpenAI embeddings, and connect Claude Desktop.

Jun 17, 20269 min readFollow

Topics You Will Master

Connecting to an Amazon Linux EC2 instance over SSH from Windows and Linux/macOS
Installing Anaconda and uv on a fresh Linux server
Serving an MCP server over Streamable HTTP on 0.0.0.0 so it is reachable remotely
Switching to OpenAI embeddings for a cloud server and connecting Claude Desktop

A local MCP server only helps you. To share it — or to give Claude Desktop a tool that runs in the cloud — you deploy it to a server. This lesson hosts the research assistant server on an Amazon Linux EC2 instance, serving it over the Streamable HTTP transport so any MCP client can reach it.

Two changes adapt the server for the cloud: it embeds with OpenAI (no local GPU needed) and it binds to 0.0.0.0 so it listens on the instance's public address.

Note

Prerequisites: the server from Research Assistant with MCP and LangGraph, an AWS account, and an OpenAI API key. Basic AWS familiarity helps but each step is spelled out.

95% OFF

MCP Mastery: Build AI Apps with Claude, LangChain and Ollama

Build MCP servers and clients with Python, Streamlit, ChromaDB, LangChain, LangGraph agents, and Ollama — from your first tool to cloud deployment.

Enroll Now — 95% OFF →

Launch the EC2 instance

The deployment steps: launch EC2, SSH in, install, then run the server

In the AWS console, launch an Amazon Linux EC2 instance and:

  1. Create or choose a key pair (download the .pem file, e.g. mcp.pem).
  2. In the security group, allow inbound SSH (port 22) from your IP and a custom TCP rule for port 8000 (the MCP server port).

Caution

Opening port 8000 to 0.0.0.0/0 exposes your server to the whole internet. For learning that is fine; for anything real, restrict the source to known IPs and put the server behind HTTPS.


Connect over SSH

Use the .pem key to connect. Replace the host with your instance's public DNS from the EC2 console.

From Windows (PowerShell / Command Prompt):

POWERSHELL
# If the .pem file is in the current directory
ssh -i "mcp.pem" ec2-user@your-ec2-public-dns.compute.amazonaws.com

On Linux/macOS: the same command works, but you may first need to tighten the key's permissions:

BASH
chmod 400 mcp.pem
ssh -i "mcp.pem" ec2-user@your-ec2-public-dns.compute.amazonaws.com

Important

Always log in as ec2-user (not root) on Amazon Linux. Replace your-ec2-public-dns with the actual public DNS shown in the EC2 console (for example ec2-XX-XX-XX-XX.ap-south-1.compute.amazonaws.com). Never share your .pem file or your instance's real address publicly.


Install Anaconda and uv on the server

Once connected, update the system and install Anaconda.

BASH
# 1. Update the system
sudo yum update -y

# 2. Download the Anaconda installer
curl -O https://repo.anaconda.com/archive/Anaconda3-2025.06-0-Linux-x86_64.sh

# 3. Run the installer
bash Anaconda3-2025.06-0-Linux-x86_64.sh

Follow the prompts, accept the license, and use the default install location /home/ec2-user/anaconda3. When asked about shell initialization, choose "no" initially, then add it to PATH manually:

BASH
export PATH="/home/ec2-user/anaconda3/bin:$PATH"
echo 'export PATH="/home/ec2-user/anaconda3/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

Initialize conda and install uv:

BASH
conda init bash
source ~/.bashrc
pip install uv

Verify the toolchain:

BASH
conda --version
python --version
uv --version

Tip

The Amazon Deep Learning AMI shows a welcome banner with the tools and GPU configuration it ships with. A plain Amazon Linux AMI works fine here since this server embeds with OpenAI rather than a local model.


Adapt the server for the cloud

The cloud server swapping Ollama for OpenAI and binding to 0.0.0.0

Copy your server folder to the instance (with scp, git clone, or by pasting the file) and adjust two things in server.py.

First, embed with OpenAI instead of Ollama — a cloud server has no local model:

PYTHON
from langchain_openai import OpenAIEmbeddings
from dotenv import load_dotenv

load_dotenv()

EMBED_MODEL = "text-embedding-3-small"
embeddings = OpenAIEmbeddings(model=EMBED_MODEL)

Second, serve over HTTP bound to all interfaces so the instance's public IP can receive requests:

PYTHON
if __name__ == "__main__":
    mcp.run(transport="http", host="0.0.0.0")

Create a .env on the server with your key:

BASH
OPENAI_API_KEY=your-openai-api-key

Important

Binding to host="0.0.0.0" makes the server listen on every network interface, including the public one — that is what makes it reachable. Keep your OPENAI_API_KEY in .env, never in the code or in version control.

Install dependencies and run it:

BASH
uv sync
uv run python server.py

The server is now reachable at http://your-ec2-public-dns.compute.amazonaws.com:8000/mcp.

Tip

An SSH session ends when you disconnect, stopping the server. To keep it running, start it inside tmux (tmux new -s mcp, run the server, detach with Ctrl-b d) or with nohup uv run python server.py &. For production, run it as a systemd service.


Connect Claude Desktop to the remote server

Claude Desktop reaching the EC2 server through the mcp-remote bridge

On your laptop, point Claude Desktop at the remote server using the mcp-remote bridge in claude_desktop_config.json:

JSON
{
  "mcpServers": {
    "remote-research-server": {
      "command": "npx",
      "args": ["mcp-remote", "http://your-ec2-public-dns.compute.amazonaws.com:8000/mcp", "--allow-http"]
    }
  }
}

Restart Claude Desktop, and your cloud-hosted research tools appear alongside your local ones.

Important

Replace the URL with your instance's real address. --allow-http is for testing only — for real deployments, terminate HTTPS in front of the server (for example with a reverse proxy or load balancer) and drop the flag. See Connect MCP Servers to Claude Desktop for the full host config.


Recap

  • Launch Amazon Linux EC2, open ports 22 and 8000, and SSH in as ec2-user.
  • Install Anaconda + uv, then uv sync your server's dependencies.
  • For the cloud, embed with OpenAI and run mcp.run(transport="http", host="0.0.0.0").
  • Keep the process alive with tmux/systemd, and reach it from Claude Desktop via mcp-remote.

A server tied to one EC2 box is hard to share widely. The final step is packaging your server so anyone can install it with one command — see Publish Your MCP Server on PyPI.

Found this useful? Keep building with me.

New tutorials every week on YouTube — or go deeper with a full structured course.

Find this tutorial useful?

Subscribe to our YouTube channels for more practical production walk-throughs.

Discussion & Comments