Skip to main content

Overview

The Financial MCP Server can be deployed to various platforms, from simple cloud services to enterprise Kubernetes clusters. This guide covers the most popular deployment options with step-by-step instructions.

Railway

Recommended for beginners
  • Zero-config deployment
  • Automatic scaling
  • Built-in monitoring

Docker

Flexible containerization
  • Platform independent
  • Easy scaling
  • Production ready
Railway offers the simplest deployment experience with automatic builds and scaling.

Prerequisites

  • GitHub account
  • Railway account (free tier available)
  • FMP API key (optional but recommended)

Step 1: Fork the Repository

  1. Visit the GitHub repository
  2. Click “Fork” to create your own copy
  3. Clone your fork locally for any customizations

Step 2: Connect to Railway

1

Create Railway Project

  1. Go to Railway
  2. Sign up/login with GitHub
  3. Click “New Project”
  4. Select “Deploy from GitHub repo”
  5. Choose your forked repository
2

Configure Environment Variables

  1. In Railway dashboard, go to your project
  2. Click “Variables” tab
  3. Add the following variables:
FMP_API_KEY=your_actual_api_key_here
PORT=$PORT
3

Deploy

Railway automatically detects the Python app and deploys it using the Procfile.The deployment process:
  • Detects Python runtime
  • Installs dependencies from requirements.txt
  • Runs the command from Procfile
  • Assigns a public URL

Step 3: Verify Deployment

# Test your deployed server
curl "https://your-app-name.railway.app/api/v1/health"

# Expected response
{
  "status": "healthy",
  "tools_available": 32,
  "data_sources": ["YFinance", "FMP"],
  "timestamp": "2025-06-28T18:42:12.471731"
}

Railway Configuration

{
  "build": {
    "builder": "NIXPACKS"
  },
  "deploy": {
    "restartPolicyType": "ON_FAILURE",
    "restartPolicyMaxRetries": 10
  }
}

Docker Deployment

Docker provides a consistent deployment environment across different platforms.

Prerequisites

  • Docker installed
  • Docker Hub account (for image hosting)
  • Basic Docker knowledge

Step 1: Build Docker Image

FROM python:3.11-slim

# Set working directory
WORKDIR /app

# Copy requirements first for better caching
COPY requirements.txt .

# Install dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Copy application code
COPY . .

# Expose port
EXPOSE 8001

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
  CMD curl -f http://localhost:8001/api/v1/health || exit 1

# Run the application
CMD ["python", "main.py"]
version: '3.8'

services:
  financial-mcp:
    build: .
    ports:
      - "8001:8001"
    environment:
      - FMP_API_KEY=${FMP_API_KEY}
      - PORT=8001
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8001/api/v1/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

  # Optional: Add reverse proxy
  nginx:
    image: nginx:alpine
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf
    depends_on:
      - financial-mcp
    restart: unless-stopped

Step 3: Production Docker Setup

# Optimized Dockerfile for production
FROM python:3.11-slim as builder

WORKDIR /app
COPY requirements.txt .
RUN pip install --user --no-cache-dir -r requirements.txt

FROM python:3.11-slim

# Create non-root user
RUN useradd --create-home --shell /bin/bash app

# Copy installed packages
COPY --from=builder /root/.local /home/app/.local
COPY --chown=app:app . /home/app/

WORKDIR /home/app
USER app

# Make sure scripts are in PATH
ENV PATH=/home/app/.local/bin:$PATH

EXPOSE 8001
CMD ["python", "main.py"]

Heroku Deployment

Heroku provides a simple platform-as-a-service solution.

Prerequisites

  • Heroku account
  • Heroku CLI installed
  • Git repository

Deployment Steps

1

Prepare Application

Ensure your repository has the required files:
├── main.py
├── requirements.txt
├── Procfile
└── runtime.txt (optional)
2

Create Heroku App

# Login to Heroku
heroku login

# Create new app
heroku create your-financial-mcp-server

# Set environment variables
heroku config:set FMP_API_KEY=your_actual_api_key
3

Deploy

# Add Heroku remote
heroku git:remote -a your-financial-mcp-server

# Deploy
git push heroku main

# Open in browser
heroku open

Heroku Configuration

web: python main.py

VPS/Cloud Server Deployment

Deploy to any cloud server (AWS EC2, DigitalOcean, Linode, etc.).

Prerequisites

  • Ubuntu/Debian server
  • SSH access
  • Domain name (optional)

Step 1: Server Setup

# Update system
sudo apt update && sudo apt upgrade -y

# Install Python and dependencies
sudo apt install python3 python3-pip python3-venv nginx git -y

# Create application user
sudo useradd -m -s /bin/bash financial-mcp
sudo su - financial-mcp

Step 2: Process Management

# Create /etc/systemd/system/financial-mcp.service
[Unit]
Description=Financial MCP Server
After=network.target

[Service]
Type=simple
User=financial-mcp
WorkingDirectory=/home/financial-mcp/yfi-deployment
Environment=PATH=/home/financial-mcp/yfi-deployment/venv/bin
Environment=FMP_API_KEY=your_actual_api_key
Environment=PORT=8001
ExecStart=/home/financial-mcp/yfi-deployment/venv/bin/python main.py
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target

Step 3: Reverse Proxy (Nginx)

# /etc/nginx/sites-available/financial-mcp
server {
    listen 80;
    server_name your-domain.com;

    location / {
        proxy_pass http://127.0.0.1:8001;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Kubernetes Deployment

For enterprise deployments requiring high availability and scaling.

Prerequisites

  • Kubernetes cluster
  • kubectl configured
  • Basic Kubernetes knowledge

Deployment Manifests

apiVersion: apps/v1
kind: Deployment
metadata:
  name: financial-mcp-server
  labels:
    app: financial-mcp
spec:
  replicas: 3
  selector:
    matchLabels:
      app: financial-mcp
  template:
    metadata:
      labels:
        app: financial-mcp
    spec:
      containers:
      - name: financial-mcp
        image: username/financial-mcp-server:latest
        ports:
        - containerPort: 8001
        env:
        - name: FMP_API_KEY
          valueFrom:
            secretKeyRef:
              name: financial-mcp-secret
              key: fmp-api-key
        - name: PORT
          value: "8001"
        livenessProbe:
          httpGet:
            path: /api/v1/health
            port: 8001
          initialDelaySeconds: 30
          periodSeconds: 10
        readinessProbe:
          httpGet:
            path: /api/v1/health
            port: 8001
          initialDelaySeconds: 5
          periodSeconds: 5

Kubernetes Commands

# Create secret for API key
kubectl create secret generic financial-mcp-secret \
  --from-literal=fmp-api-key=your_actual_api_key

# Apply manifests
kubectl apply -f k8s/

Monitoring & Maintenance

Health Monitoring

# Basic health check
curl -f https://your-domain.com/api/v1/health

# Detailed monitoring script
#!/bin/bash
ENDPOINT="https://your-domain.com/api/v1/health"
RESPONSE=$(curl -s $ENDPOINT)
STATUS=$(echo $RESPONSE | jq -r '.status')

if [ "$STATUS" != "healthy" ]; then
    echo "Server unhealthy: $RESPONSE"
    # Send alert (email, Slack, etc.)
fi

Log Management

# Setup logrotate for application logs
sudo cat > /etc/logrotate.d/financial-mcp << EOF
/var/log/financial-mcp/*.log {
    daily
    missingok
    rotate 14
    compress
    delaycompress
    notifempty
    create 644 financial-mcp financial-mcp
    postrotate
        systemctl reload financial-mcp
    endscript
}
EOF

Troubleshooting

Common Deployment Issues

Error: [Errno 48] error while attempting to bind on address ('0.0.0.0', 8001): [errno 48] address already in useSolutions:
# Find process using port
lsof -i :8001

# Kill process
kill -9 <PID>

# Or use different port
export PORT=8002
Error: Server uses demo API key despite setting FMP_API_KEYSolutions:
# Verify environment variables
printenv | grep FMP

# Restart service after setting variables
sudo systemctl restart financial-mcp

# Check service environment
sudo systemctl show financial-mcp --property=Environment
Error: Container exits immediately after startingSolutions:
# Check container logs
docker logs container-name

# Run interactively for debugging
docker run -it --entrypoint /bin/bash financial-mcp-server

# Check if all dependencies are installed
docker run financial-mcp-server pip list

Performance Optimization

Production Optimizations

# Use connection pooling
import aiohttp
import asyncio

# Global session with connection pooling
session = aiohttp.ClientSession(
    connector=aiohttp.TCPConnector(
        limit=100,
        limit_per_host=30,
        keepalive_timeout=30
    )
)

# Implement caching
from functools import lru_cache
import time

@lru_cache(maxsize=1000)
def get_cached_data(symbol: str, minute: int):
    # Cache data for 1-minute intervals
    return fetch_data(symbol)

Next Steps