First Deployment
Prerequisites
Before you begin, make sure you have:
- ✅ Targetly CLI installed (
tly --version) - ✅ Authenticated with Targetly (
tly login) - ✅ Docker installed locally (for testing)
- ✅ A basic MCP server project
Step 1: Create Your MCP Server
If you don't have an MCP server yet, let's create a simple one:
mkdir my-first-mcp
cd my-first-mcp
Create a server.py file:
from mcp.server import Server
from mcp.server.sse import SseServerTransport
import uvicorn
app = Server("my-first-mcp")
@app.call_tool()
async def hello(name: str = "World") -> str:
"""Say hello to someone"""
return f"Hello, {name}!"
if __name__ == "__main__":
transport = SseServerTransport("/messages")
uvicorn.run(transport.asgi_app(app), host="0.0.0.0", port=8080)
Create requirements.txt:
mcp
uvicorn
Step 2: Create a Dockerfile
Create a Dockerfile in your project root:
FROM python:3.11-slim
WORKDIR /app
# Copy requirements and install dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY . .
# Expose port
EXPOSE 8080
# Run the server
CMD ["python", "server.py"]
Step 3: Test Locally (Optional)
Build and test your Docker image locally:
# Build image
docker build -t my-first-mcp .
# Run container
docker run -p 8080:8080 my-first-mcp
# Test in another terminal
curl http://localhost:8080/health
Step 4: Deploy to Targetly
Deploy your MCP server:
tly deploy
You'll see output like:
📦 Bundling project...
✓ Created bundle (1.8 MB)
🚀 Deploying to Targetly...
✓ Upload complete
🔨 Building Docker image...
Step 1/6 : FROM python:3.11-slim
Step 2/6 : WORKDIR /app
Step 3/6 : COPY requirements.txt .
Step 4/6 : RUN pip install --no-cache-dir -r requirements.txt
Step 5/6 : COPY . .
Step 6/6 : CMD ["python", "server.py"]
✓ Build successful
🎉 Deployment complete!
━━━━━━━━━━━━━━━━━━━━━━━━
📋 ID: abc123def456
🌐 URL: https://abc123def456.prod.targetly.io
📊 Status: Running
━━━━━━━━━━━━━━━━━━━━━━━━
Step 5: Verify Deployment
Test your deployed MCP server:
# Check if it's running
curl https://abc123def456.prod.targetly.io/health
# View logs
tly logs abc123def456
Step 6: Use Your MCP Server
Configure your AI client (e.g., Claude Desktop) to use your MCP server:
{
"mcpServers": {
"my-first-mcp": {
"url": "https://abc123def456.prod.targetly.io/messages",
"transport": "sse"
}
}
}
Congratulations! Your MCP server is now live and accessible via Targetly.
Next Steps
-
Sleep/Wake Guide Learn about auto-idle and manual resume
-
MCP Server Best Practices Optimize your MCP server for production
-
View Logs Monitor your deployment
-
Manage Deployments List and manage all deployments
Troubleshooting
Build failed - dependency error
Problem: Python dependencies failed to install
Solutions:
- Verify
requirements.txtsyntax - Pin dependency versions
- Check for platform-specific packages
Container won't start
Problem: Container exits immediately
Solutions:
- Check logs:
tly logs <deployment-id> - Verify port 8080 is exposed
- Ensure server runs on
0.0.0.0notlocalhost
URL not accessible
Problem: Deployment URL returns 502/504
Solutions:
- Wait 30 seconds for container to fully start
- Check if server is listening on port 8080
- View logs for startup errors