Skip to main content

Overview

Deploy your MCP server to the cloud for remote access via HTTP/SSE transport. This enables:
  • Access from anywhere (not just localhost)
  • Integration with web applications
  • Multi-user support
  • Always-available analytics

Deployment Options

Why Fly.io:
  • Built-in MCP support (fly mcp wrap)
  • Automatic HTTPS
  • Global edge network
  • Free tier available
Steps:
  1. Install flyctl
curl -L https://fly.io/install.sh | sh
  1. Wrap your MCP server
fly mcp wrap --port 8080
  1. Deploy
fly deploy
  1. Get your endpoint
fly status
# Your MCP is now at: https://your-app.fly.dev/sse
Fly.io machines auto-stop after 5 minutes of inactivity. The Surfa platform handles cold starts automatically with retry logic (3 attempts × 9 seconds).

Other Platforms

Railway, Render, Heroku:
  • Use HTTP/SSE transport
  • Expose port 8080
  • Set environment variables
  • Enable HTTPS

Transport: SSE vs STDIO

STDIO (Local Only)

Pros:
  • ✅ Fast, low latency
  • ✅ Simple setup
Cons:
  • ❌ Only works on localhost
  • ❌ Can’t be accessed remotely

SSE (Remote-Ready)

Pros:
  • ✅ Works over HTTP/HTTPS
  • ✅ Accessible from anywhere
  • ✅ Web-compatible
Cons:
  • ⚠️ Slightly higher latency
  • ⚠️ May have cold starts
When to use SSE:
  • Deploying to cloud platforms
  • Building web applications
  • Multi-user scenarios
  • Remote access needed

Authentication

API Key via Headers

curl -X POST https://your-mcp.fly.dev/sse \
  -H "Authorization: Bearer sk_live_your_key" \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":"1","method":"tools/list","params":{}}'

In Surfa Platform

The platform automatically handles authentication when you add your MCP with headers:
{
  "Authorization": "Bearer sk_live_your_key"
}

Cold Start Handling

Remote MCPs may “sleep” after inactivity. The Surfa platform handles this automatically:
1

First Request

Returns 202 (machine starting)
2

Retry 1

Wait 9 seconds, try again
3

Retry 2

Wait 9 seconds, try again
4

Retry 3

Wait 9 seconds, try again
5

Success

Tools discovered and displayed
Total wait time: Up to 27 seconds for cold starts. To avoid cold starts:
  • Keep machines always-on (costs more)
  • Use health check pings
  • Accept the retry delay

Testing Your Deployment

1. Test with curl

curl -X POST https://your-mcp.fly.dev/sse \
  -H "Authorization: Bearer sk_live_your_key" \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":"1","method":"tools/list","params":{}}'

2. Test in Surfa Platform

1

Navigate

Go to Settings → MCP
2

Add MCP

Click Add New MCP
3

Configure

  • Name: “My Remote MCP”
  • Transport: SSE
  • Endpoint: https://your-mcp.fly.dev/sse
  • Headers: {"Authorization": "Bearer sk_live_your_key"}
4

Test

Click Test Connection
5

Wait

Wait for retries (if cold start)
6

Success

See discovered tools ✅

CORS Configuration

If accessing from web apps, enable CORS:
from fastapi.middleware.cors import CORSMiddleware

app.add_middleware(
    CORSMiddleware,
    allow_origins=["https://surfa.dev"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

Security Best Practices

Never expose API keys over HTTP. Use HTTPS in production.
Check API keys on every request. Reject invalid keys immediately.
Prevent abuse by limiting requests per IP or API key.
Track all API requests for auditing and debugging.
Regularly rotate API keys and revoke old ones.

Troubleshooting

Cause: Machine is starting (cold start)Solution:
  • Wait for retry logic to complete
  • Check Fly.io logs: fly logs
  • Verify machine is running: fly status
Cause: Invalid or missing API keySolution:
  • Check API key is correct
  • Verify Authorization header format: Bearer sk_live_...
  • Ensure key has correct permissions
Cause: Server not responding after 27 secondsSolution:
  • Increase timeout in Surfa platform
  • Check machine is running: fly status
  • Configure always-on if needed
Cause: MCP server not returning toolsSolution:
  • Verify /sse endpoint is correct
  • Check initialize request works
  • Test tools/list manually with curl
  • Review server logs for errors

Next Steps

Test Connection

Learn how to test your MCP connection

Claude Desktop Setup

Connect Claude Desktop to your remote MCP

API Reference

Complete API documentation

GitHub Repository

View source and contribute