# Lamplighter-MCP Deployment Plan

## 1. Build Process

1. **Prepare Codebase**
   - Ensure all code is committed to version control
   - Merge feature branches if working collaboratively
   - Verify all environment variables are documented in `.env.example`

2. **Build Production Version**
   - Run `npm run build` to compile TypeScript to JavaScript
   - Verify build artifacts in `dist/` directory
   - Create production-optimized build configurations if needed

3. **Test Build Locally**
   - Set up `.env` with production-like settings
   - Run `node dist/server.js` to verify server starts correctly
   - Test all MCP tools via Cursor or MCP Inspector to verify functionality

## 2. Deployment Options

### Option A: Manual Deployment to Development Server

1. **Server Requirements**
   - Node.js 18.x or higher
   - Network access to Confluence API
   - Network access to AI service APIs (OpenAI/Google)
   - Firewall rules allowing inbound connections on port 3001 (or configured port)

2. **Deployment Steps**
   - SSH into development server
   - Clone repository or copy build artifacts
   - Install dependencies with `npm ci` (or copy `node_modules` if same architecture)
   - Set up `.env` file with proper credentials and configuration
   - Run `node dist/server.js` to start the server
   - Optionally use a process manager like PM2: `pm2 start dist/server.js --name lamplighter-mcp`

3. **Verification**
   - Verify server is running with `curl http://server-address:3001/health` (would need to add health endpoint)
   - Configure Cursor to connect to the deployed instance
   - Test a basic workflow like codebase analysis

### Option B: Containerized Deployment (Docker)

1. **Create Dockerfile**
   ```dockerfile
   FROM node:18-alpine
   
   WORKDIR /app
   
   COPY package*.json ./
   RUN npm ci --only=production
   
   COPY dist/ ./dist/
   
   # Copy default context directory structure
   RUN mkdir -p lamplighter_context/feature_tasks
   
   EXPOSE 3001
   
   CMD ["node", "dist/server.js"]
   ```

2. **Build and Run Container**
   ```bash
   docker build -t lamplighter-mcp:latest .
   docker run -d -p 3001:3001 --env-file .env --name lamplighter-mcp lamplighter-mcp:latest
   ```

3. **Verification**
   - Same verification steps as manual deployment

### Option C: Cloud Deployment (AWS/Azure/GCP)

1. **AWS EC2**
   - Launch EC2 instance with Node.js
   - Follow manual deployment steps
   - Set up security group to allow port 3001
   - Configure domain/DNS if needed

2. **AWS Elastic Beanstalk**
   - Create `Procfile` with `web: node dist/server.js`
   - Deploy using Elastic Beanstalk CLI
   - Configure environment variables in Elastic Beanstalk console

## 3. Continuous Integration/Deployment (Optional)

1. **GitHub Actions Workflow**
   ```yaml
   name: Deploy Lamplighter-MCP

   on:
     push:
       branches: [ main ]

   jobs:
     build-and-deploy:
       runs-on: ubuntu-latest
       steps:
         - uses: actions/checkout@v3
         - name: Setup Node.js
           uses: actions/setup-node@v3
           with:
             node-version: '18'
         - name: Install dependencies
           run: npm ci
         - name: Build
           run: npm run build
         - name: Deploy to development server
           uses: appleboy/ssh-action@master
           with:
             host: ${{ secrets.SERVER_HOST }}
             username: ${{ secrets.SERVER_USERNAME }}
             key: ${{ secrets.SERVER_PRIVATE_KEY }}
             script: |
               cd /path/to/deployment
               git pull
               npm ci
               npm run build
               pm2 restart lamplighter-mcp || pm2 start dist/server.js --name lamplighter-mcp
   ```

## 4. Monitoring and Maintenance

1. **Process Management**
   - Use PM2 for process management
   - Configure automatic restarts: `pm2 startup`
   - Save process list: `pm2 save`

2. **Monitoring**
   - Add logging to file: `pm2 start dist/server.js --name lamplighter-mcp -o logs/out.log -e logs/error.log`
   - Consider PM2 monitoring: `pm2 monitor`
   - Implement /health endpoint for uptime monitoring

3. **Backup Strategy**
   - Set up periodic backups of `lamplighter_context/` directory
   - Consider Git-backing the context files for version control

## 5. Environment-Specific Configurations

1. **Development**
   - Use local environment with DEBUG logs
   - Use development LLM models (e.g., smaller/cheaper ones)

2. **Staging/Production**
   - Use production-grade LLM models
   - Implement rate limiting if needed
   - Consider authentication for MCP server access

## 6. Rollback Plan

In case of deployment issues:
1. Stop the server: `pm2 stop lamplighter-mcp`
2. Revert to previous version (Git checkout or restore from backup)
3. Restart: `pm2 start dist/server.js --name lamplighter-mcp`
4. Verify functionality

## 7. Security Considerations

1. **API Keys and Secrets**
   - Ensure all API keys are stored as environment variables
   - Do not commit `.env` files to version control
   - Consider using a secrets manager for production

2. **Network Security**
   - Limit access to the MCP server by IP if possible
   - Consider using a reverse proxy (Nginx/Apache) with SSL
   - Implement rate limiting to prevent abuse

3. **Data Security**
   - Be mindful of sensitive data in context files
   - Implement secure handling of Confluence credentials 