
Create Remote MCP Server on Kubernetes (Amazon EKS)
概览
A containerized MCP (Model Context Protocol) server using FastMCP that provides a simple calculator tool for adding two numbers. This MCP server runs on Amazon EKS. The highlevel diagram of this project below: - server.py - FastMCP server with add_numbers tool - requirements.txt - Python dependencies - Dockerfile - Container definition - k8s-deployment.yaml - Kubernetes deployment and LoadBalancer service - test_mcp_client.py - Test Remote MCP Server The server will be available at http://localhost:8000 You can push this image to either Dockerhub or an ECR repo - AWS CLI configured with appropriate permissions - kubectl installed - Docker installed and running You can use an existing EKS cluster or create a new one, it's upto you. Ensure that your terminal has access to run Kubectl on it IMPORTANT: Change the container image to the repo URI in k8s-deployment.yaml file The server provides one tool: - add_numbers(a: float, b: float) -> float - Adds two numbers together
README
以下为原文 README 节选,完整内容请查看原文。
Remote MCP Server on Kubernetes (Amazon EKS)
A containerized MCP (Model Context Protocol) server using FastMCP that provides a simple calculator tool for adding two numbers. This MCP server runs on Amazon EKS. The highlevel diagram of this project below:
Files
server.py- FastMCP server with add_numbers toolrequirements.txt- Python dependenciesDockerfile- Container definitionk8s-deployment.yaml- Kubernetes deployment and LoadBalancer servicetest_mcp_client.py- Test Remote MCP Server
Building the Container
docker build -t mcp-calculator:latest .
Running Locally
# Run the container locally
docker run -p 8000:8000 mcp-calculator:latest
The server will be available at http://localhost:8000
Push to repo
You can push this image to either Dockerhub or an ECR repo
Deploying to Amazon EKS
Prerequisites
- AWS CLI configured with appropriate permissions
- kubectl installed
- Docker installed and running
EKS Cluster
You can use an existing EKS cluster or create a new one, it’s upto you. Ensure that your terminal has access to run Kubectl on it
Deployment Steps
IMPORTANT: Change the container image to the repo URI in k8s-deployment.yaml file
- Deploy MCP Server container to EKS:
# Deploy the application
kubectl apply -f k8s-deployment.yaml
# Check deployment status
kubectl rollout status deployment/mcp-calculator
# Get service information
kubectl get services mcp-calculator-service
- Get the LoadBalancer external IP:
kubectl get services mcp-calculator-service -w
Testing the MCP Server
The server provides one tool:
add_numbers(a: float, b: float) -> float- Adds two numbers together
Testing with curl
The MCP server is currently deployed and accessible at:
http:///mcp/
Complete curl Test Workflow
Step 1: Initialize MCP Session and Get Session ID
SESSION_ID=$(curl -s -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{"roots":{"listChanged":true},"sampling":{}},"clientInfo":{"name":"curl-test","version":"1.0.0"}}}' \
http:///mcp/ \
-D /dev/stderr 2>&1 | grep "mcp-session-id:" | cut -d' ' -f2 | tr -d '\r')
echo "Session ID: $SESSION_ID"
Step 2: Send Initialization Notification (Required by MCP Protocol)
curl -s -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-H "mcp-session-id: $SESSION_ID" \
-d '{"jsonrpc":"2.0","method":"notifications/initialized"}' \
http:///mcp/
Step 3: List Available Tools (Optional)
curl -X POST \
安装
docker run -p 8000:8000 mcp-calculator:latest