Server Deployment Guide¶
This guide covers various deployment options for BioMCP, from local development to production cloud deployments with authentication.
Deployment Options Overview¶
Mode | Use Case | Transport | Authentication | Scalability |
---|---|---|---|---|
Local STDIO | Development | STDIO | None | Single user |
HTTP Server | Small teams | Streamable HTTP | Optional | Moderate |
Docker | Containerized | Streamable HTTP | Optional | Moderate |
Cloudflare Worker | Production | SSE/HTTP | OAuth optional | High |
Local Development (STDIO)¶
The simplest deployment for development and testing.
Setup¶
Configuration¶
For Claude Desktop integration:
Use Cases¶
- Local development
- Single-user research
- Testing new features
HTTP Server Deployment¶
Modern deployment using Streamable HTTP transport.
Basic Setup¶
With Environment Variables¶
# Create .env file
cat > .env << EOF
BIOMCP_HOST=0.0.0.0
BIOMCP_PORT=8000
NCI_API_KEY=your-key
ALPHAGENOME_API_KEY=your-key
EOF
# Run with env file
biomcp run --mode http
Systemd Service (Linux)¶
Create /etc/systemd/system/biomcp.service
:
[Unit]
Description=BioMCP Server
After=network.target
[Service]
Type=simple
User=biomcp
WorkingDirectory=/opt/biomcp
Environment="PATH=/usr/local/bin:/usr/bin"
EnvironmentFile=/opt/biomcp/.env
ExecStart=/usr/local/bin/biomcp run --mode http
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
Enable and start:
Nginx Reverse Proxy¶
server {
listen 443 ssl;
server_name biomcp.example.com;
ssl_certificate /etc/ssl/certs/biomcp.crt;
ssl_certificate_key /etc/ssl/private/biomcp.key;
location /mcp {
proxy_pass http://localhost:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_buffering off;
}
}
Docker Deployment¶
Containerized deployment for consistency and portability.
Basic Dockerfile¶
FROM python:3.11-slim
# Install BioMCP
RUN pip install biomcp-python
# Add API keys (use secrets in production!)
ENV NCI_API_KEY=""
ENV ALPHAGENOME_API_KEY=""
# Expose port
EXPOSE 8000
# Run server
CMD ["biomcp", "run", "--mode", "http", "--host", "0.0.0.0"]
With AlphaGenome Support¶
FROM python:3.11-slim
# Install system dependencies
RUN apt-get update && apt-get install -y git
# Install BioMCP
RUN pip install biomcp-python
# Install AlphaGenome
RUN git clone https://github.com/google-deepmind/alphagenome.git && \
cd alphagenome && \
pip install .
# Configure
ENV MCP_MODE=http
ENV BIOMCP_HOST=0.0.0.0
ENV BIOMCP_PORT=8000
EXPOSE 8000
CMD ["biomcp", "run"]
Docker Compose¶
version: "3.8"
services:
biomcp:
build: .
ports:
- "8000:8000"
environment:
- MCP_MODE=http
- NCI_API_KEY=${NCI_API_KEY}
- ALPHAGENOME_API_KEY=${ALPHAGENOME_API_KEY}
volumes:
- ./logs:/app/logs
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
interval: 30s
timeout: 10s
retries: 3
Running¶
# Build and run
docker-compose up -d
# View logs
docker-compose logs -f
# Scale horizontally
docker-compose up -d --scale biomcp=3
Cloudflare Worker Deployment¶
Enterprise-grade deployment with global edge distribution.
Prerequisites¶
- Cloudflare account
- Wrangler CLI installed
- Remote BioMCP server running
Architecture¶
Setup Worker¶
- Install dependencies:
- Create
wrangler.toml
:
name = "biomcp-worker"
main = "src/index.js"
compatibility_date = "2024-01-01"
[vars]
REMOTE_MCP_SERVER_URL = "https://your-biomcp-server.com/mcp"
MCP_SERVER_API_KEY = "your-secret-key"
[[kv_namespaces]]
binding = "AUTH_TOKENS"
id = "your-kv-namespace-id"
- Deploy:
With OAuth Authentication (Stytch)¶
- Configure Stytch:
[vars]
STYTCH_PROJECT_ID = "project-test-..."
STYTCH_SECRET = "secret-test-..."
STYTCH_PUBLIC_TOKEN = "public-token-test-..."
JWT_SECRET = "your-jwt-secret"
-
OAuth Endpoints: The worker automatically provides:
-
/.well-known/oauth-authorization-server
/authorize
/callback
-
/token
-
Client Configuration:
{
"mcpServers": {
"biomcp": {
"transport": {
"type": "sse",
"url": "https://your-worker.workers.dev"
},
"auth": {
"type": "oauth",
"client_id": "mcp-client",
"authorization_endpoint": "https://your-worker.workers.dev/authorize",
"token_endpoint": "https://your-worker.workers.dev/token",
"scope": "mcp:access"
}
}
}
}
Production Considerations¶
Security¶
- API Key Management:
# Use environment variables
export NCI_API_KEY="$(vault kv get -field=key secret/biomcp/nci)"
# Or use secrets management
docker run --secret biomcp_keys biomcp:latest
-
Network Security:
-
Use HTTPS everywhere
- Implement rate limiting
- Set up CORS properly
-
Use authentication for public endpoints
-
Access Control:
# Example middleware
async def auth_middleware(request, call_next):
token = request.headers.get("Authorization")
if not validate_token(token):
return JSONResponse({"error": "Unauthorized"}, status_code=401)
return await call_next(request)
Monitoring¶
- Health Checks:
# Built-in health endpoint
GET /health
# Custom health check
@app.get("/health/detailed")
async def health_detailed():
return {
"status": "healthy",
"version": __version__,
"apis": check_api_status(),
"timestamp": datetime.utcnow()
}
- Metrics:
# Prometheus metrics
from prometheus_client import Counter, Histogram
request_count = Counter('biomcp_requests_total', 'Total requests')
request_duration = Histogram('biomcp_request_duration_seconds', 'Request duration')
- Logging:
# Structured logging
import structlog
logger = structlog.get_logger()
logger.info("request_processed",
tool="article_searcher",
duration=0.234,
user_id="user123"
)
Scaling¶
- Horizontal Scaling:
# Kubernetes deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: biomcp
spec:
replicas: 3
selector:
matchLabels:
app: biomcp
template:
metadata:
labels:
app: biomcp
spec:
containers:
- name: biomcp
image: biomcp:latest
ports:
- containerPort: 8000
resources:
requests:
memory: "512Mi"
cpu: "500m"
limits:
memory: "1Gi"
cpu: "1000m"
- Caching:
# Redis caching
import redis
from functools import wraps
redis_client = redis.Redis()
def cache_result(ttl=3600):
def decorator(func):
@wraps(func)
async def wrapper(*args, **kwargs):
key = f"{func.__name__}:{str(args)}:{str(kwargs)}"
cached = redis_client.get(key)
if cached:
return json.loads(cached)
result = await func(*args, **kwargs)
redis_client.setex(key, ttl, json.dumps(result))
return result
return wrapper
return decorator
Performance Optimization¶
- Connection Pooling:
# Reuse HTTP connections
import httpx
client = httpx.AsyncClient(
limits=httpx.Limits(max_keepalive_connections=20),
timeout=httpx.Timeout(30.0)
)
- Async Processing:
# Process requests concurrently
async def handle_batch(requests):
tasks = [process_request(req) for req in requests]
return await asyncio.gather(*tasks)
- Response Compression:
# Enable gzip compression
from fastapi.middleware.gzip import GZipMiddleware
app.add_middleware(GZipMiddleware, minimum_size=1000)
Migration Path¶
From STDIO to HTTP¶
- Update server startup:
- Update client configuration:
From SSE to Streamable HTTP¶
- Update worker code to use
/mcp
endpoint - Update client to use new transport:
Troubleshooting¶
Common Issues¶
- Port Already in Use:
- API Key Errors:
# Verify environment variables
env | grep -E "(NCI|ALPHAGENOME|CBIO)"
# Test API key
curl -H "X-API-KEY: $NCI_API_KEY" https://api.cancer.gov/v2/trials
-
Connection Timeouts:
-
Increase timeout values
- Check firewall rules
- Verify network connectivity
Debug Mode¶
# Enable debug logging
BIOMCP_LOG_LEVEL=DEBUG biomcp run --mode http
# Or in Docker
docker run -e BIOMCP_LOG_LEVEL=DEBUG biomcp:latest
Next Steps¶
- Set up monitoring
- Configure authentication
- Review security policies
- Implement CI/CD pipeline