# Deploying to Railway
This guide explains how to deploy your Instagram MCP Server to Railway.
## Prerequisites
1. A Railway account (https://railway.app)
2. Railway CLI installed: `npm install -g @railway/cli` (optional)
## Deployment Steps
### Option 1: Deploy via Railway Dashboard (Recommended)
1. **Push your code to GitHub**
```bash
git init
git add .
git commit -m "Initial commit"
git branch -M main
git remote add origin YOUR_GITHUB_REPO_URL
git push -u origin main
```
2. **Create a new project on Railway**
- Go to https://railway.app
- Click "New Project"
- Select "Deploy from GitHub repo"
- Select your repository
3. **Set Environment Variables**
Railway will automatically detect your Node.js project. Add these environment variables in the Railway dashboard:
- `FB_APP_ID` - Your Facebook App ID
- `FB_APP_SECRET` - Your Facebook App Secret
- `FB_PAGE_ID` - Your Facebook Page ID
- `IG_ACCOUNT_ID` - Your Instagram Account ID
- `FB_PAGE_ACCESS_TOKEN` - Your Page Access Token
- `FB_USER_ACCESS_TOKEN` - Your User Access Token
- `FB_API_VERSION` - v24.0
- `MCP_API_KEY` - A secure random string (e.g., `openssl rand -hex 32`)
- `PORT` - Railway will set this automatically, but you can use 3000 for local testing
- `NODE_ENV` - production
4. **Deploy**
Railway will automatically build and deploy your app. The build process will:
- Run `npm install`
- Run `npm run build` (via the "prepare" script)
- Start the server with `npm start`
5. **Get Your Public URL**
- After deployment, Railway will provide a public URL (e.g., `https://your-app.railway.app`)
- Your MCP endpoint will be: `https://your-app.railway.app/mcp`
### Option 2: Deploy via Railway CLI
1. **Install Railway CLI**
```bash
npm install -g @railway/cli
```
2. **Login to Railway**
```bash
railway login
```
3. **Initialize and Deploy**
```bash
railway init
railway up
```
4. **Set Environment Variables**
```bash
railway variables set FB_APP_ID=your_value
railway variables set FB_APP_SECRET=your_value
railway variables set FB_PAGE_ID=your_value
railway variables set IG_ACCOUNT_ID=your_value
railway variables set FB_PAGE_ACCESS_TOKEN=your_value
railway variables set FB_USER_ACCESS_TOKEN=your_value
railway variables set FB_API_VERSION=v24.0
railway variables set MCP_API_KEY=your_secure_key
railway variables set NODE_ENV=production
```
5. **Get Your URL**
```bash
railway domain
```
## Connecting Claude Code to Your Railway Server
After deployment, update your `.mcp.json` to use your Railway URL:
```json
{
"mcpServers": {
"instagram": {
"type": "http",
"url": "https://your-app.railway.app/mcp",
"headers": {
"Authorization": "Bearer YOUR_MCP_API_KEY"
}
}
}
}
```
Then reload MCP in Claude Code:
```
/mcp reload
```
## Verify Deployment
Test your deployed server:
```bash
# Health check
curl https://your-app.railway.app/health
# Test MCP endpoint
curl -X POST https://your-app.railway.app/mcp \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_MCP_API_KEY" \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}'
```
## Security Notes
- ✅ Your `.env` file is in `.gitignore` - credentials won't be committed
- ✅ API key authentication is enabled via `MCP_API_KEY`
- ✅ CORS is enabled for web access
- ✅ HTTPS is provided by Railway automatically
## Troubleshooting
### Build Fails
- Check Railway build logs
- Ensure all dependencies are in `package.json`
- Verify TypeScript compiles locally: `npm run build`
### Server Won't Start
- Check environment variables are set correctly
- View logs in Railway dashboard
- Verify health check endpoint: `/health`
### MCP Connection Fails
- Verify the URL includes `/mcp` endpoint
- Check `Authorization` header matches your `MCP_API_KEY`
- Test with curl to isolate the issue
## Cost
Railway offers:
- **Free tier**: $5 of usage per month (includes 500 hours)
- **Hobby tier**: $5/month for more resources
Your MCP server should easily fit within the free tier for personal use.