Skip to main content
Glama
INTEGRATION_CHECKLIST.md21.7 kB
# Infrastructure Deployment Feature - Integration Checklist ## Pre-Integration Verification - [ ] **All files created successfully** - [x] `src/services/chat/commandGeneration.ts` (405 lines) ✅ - [x] `src/services/chat/commandExecution.ts` (420 lines) ✅ - [x] `src/services/chat/chatDeploymentHandler.ts` (520 lines) ✅ - [x] `src/api/routes/deployments.ts` (420 lines) ✅ - [x] `src/services/chat/__tests__/chatDeployment.test.ts` (650 lines) ✅ - [x] `docs/DEPLOYMENT_VIA_CHAT.md` (550 lines) ✅ - [x] `docs/DEPLOYMENT_QUICK_START.md` (400 lines) ✅ - [x] `docs/DEPLOYMENT_IMPLEMENTATION_SUMMARY.md` (450 lines) ✅ - [x] `docs/DEPLOYMENT_DIAGRAMS.md` (550 lines) ✅ - [ ] **Code quality checks** - [ ] Run TypeScript compiler check: `npm run type-check` - [ ] Run linter: `eslint src/services/chat/*.ts src/api/routes/deployments.ts` - [ ] Check for unused imports: `eslint --fix` - [ ] **Test execution** - [ ] Run test suite: `npm test -- --run src/services/chat/__tests__/chatDeployment.test.ts` - [ ] Expected: All 35+ tests pass - [ ] Check coverage: `npm test -- --coverage` --- ## Phase 1: Chat System Integration ### Step 1.1: Import Handler in Chat Integration Service **File:** `src/services/chat/integration.ts` (or main chat service) ```typescript // Add import import { ChatDeploymentHandler } from './chatDeploymentHandler'; // Add to class initialization private deploymentHandler: ChatDeploymentHandler; constructor(...args) { // ... existing code ... this.deploymentHandler = new ChatDeploymentHandler(); } ``` **Checklist:** - [ ] Locate correct integration file in chat service - [ ] Add ChatDeploymentHandler import - [ ] Create instance in constructor - [ ] Verify no compilation errors ### Step 1.2: Add Detection to Chat Message Handler **File:** `src/services/chat/integration.ts` (chat message processing) ```typescript async processChatMessage(message: string, context: ChatContext): Promise<ChatResponse> { // Check for deployment requests EARLY in the pipeline const deploymentRequest = await this.deploymentHandler.detectDeploymentRequest(message); if (deploymentRequest.isDeploymentRequest) { // Route to deployment workflow const response = await this.deploymentHandler.generateDeploymentCommands( message, deploymentRequest, context.llmClient ); return { type: 'deployment', content: response, sessionId: response.sessionId, requiresApproval: true, }; } // Continue with normal chat flow return this.processNormalChat(message, context); } ``` **Checklist:** - [ ] Locate chat message handler function - [ ] Add deployment detection before normal processing - [ ] Import necessary types and response builders - [ ] Handle deployment response separately - [ ] Ensure normal chat flow still works for non-deployment messages - [ ] Test with sample DHCP deployment message ### Step 1.3: Add Confirmation Handler **File:** `src/services/chat/integration.ts` (user approval handling) ```typescript async handleUserConfirmation( sessionId: string, approved: boolean, selectedCommandIds?: string[] ): Promise<ChatResponse> { const result = await this.deploymentHandler.handleUserConfirmation( sessionId, approved, selectedCommandIds ); return { type: 'deployment_confirmation_response', content: result.message, sessionId, status: approved ? 'approved' : 'rejected', }; } ``` **Checklist:** - [ ] Add confirmation handler method - [ ] Call deployment handler's confirmation method - [ ] Return appropriate response to user - [ ] Handle both approval and rejection cases --- ## Phase 2: Express API Integration ### Step 2.1: Import and Register Deployment Routes **File:** `src/api/server.ts` or main Express app initialization file ```typescript import { deploymentsRouter } from './routes/deployments'; import { ChatDeploymentHandler } from '../services/chat/chatDeploymentHandler'; // Initialize deployment handler (singleton) const deploymentHandler = new ChatDeploymentHandler(); // Register routes with app app.use('/v1/deployments', deploymentsRouter(deploymentHandler)); // Or if router needs to be updated for dependency injection: // In deployments.ts: export function createDeploymentsRouter(deploymentHandler: ChatDeploymentHandler) { const router = express.Router(); // ... all endpoints use the passed instance return router; } ``` **Checklist:** - [ ] Locate Express app initialization - [ ] Add import for deploymentsRouter - [ ] Create ChatDeploymentHandler instance - [ ] Register router at `/v1/deployments` path - [ ] Verify 8 endpoints are available: - [ ] POST /check - [ ] POST /generate - [ ] GET /:sessionId - [ ] POST /:sessionId/confirm - [ ] POST /:sessionId/result - [ ] POST /:sessionId/finalize - [ ] GET /:sessionId/results - [ ] DELETE /:sessionId ### Step 2.2: Verify API Endpoint Registration **Testing Commands:** ```bash # Check endpoint availability curl http://localhost:3000/v1/deployments/check -X OPTIONS # Test detection endpoint curl -X POST http://localhost:3000/v1/deployments/check \ -H "Content-Type: application/json" \ -d '{ "message": "Deploy DHCP on 172.251.96.200" }' # Test generation endpoint curl -X POST http://localhost:3000/v1/deployments/generate \ -H "Content-Type: application/json" \ -d '{ "message": "Deploy DHCP on 172.251.96.200", "context": { "userId": "user-123", "llmProvider": "openai" } }' ``` **Checklist:** - [ ] Server starts without errors - [ ] Routes are registered correctly - [ ] API responds to deployment requests - [ ] Response format matches documentation - [ ] Error handling works as expected --- ## Phase 3: Environment Configuration ### Step 3.1: Set Environment Variables **File:** `.env` or `.env.local` ```env # Deployment Feature ENABLE_DEPLOYMENTS=true DEPLOYMENT_LLM_PROVIDER=openai DEPLOYMENT_COMMAND_TIMEOUT=30000 DEPLOYMENT_SESSION_CLEANUP_INTERVAL=3600000 DEPLOYMENT_SESSION_MAX_AGE=86400000 # Optional: Override LLM settings DEPLOYMENT_LLM_MODEL=gpt-4 DEPLOYMENT_LLM_TEMPERATURE=0.3 DEPLOYMENT_LLM_MAX_TOKENS=2000 ``` **Checklist:** - [ ] Create `.env` file (if not exists) - [ ] Add ENABLE_DEPLOYMENTS=true - [ ] Set LLM provider (openai, anthropic, etc.) - [ ] Configure timeout values - [ ] Set cleanup schedule - [ ] Verify Docker containers also have these env vars ### Step 3.2: Update Docker Configuration **File:** `docker-compose.yml` or `docker-compose.dev.yml` ```yaml services: gateway: environment: - ENABLE_DEPLOYMENTS=true - DEPLOYMENT_LLM_PROVIDER=${DEPLOYMENT_LLM_PROVIDER} - DEPLOYMENT_COMMAND_TIMEOUT=${DEPLOYMENT_COMMAND_TIMEOUT:-30000} - DEPLOYMENT_SESSION_CLEANUP_INTERVAL=${DEPLOYMENT_SESSION_CLEANUP_INTERVAL:-3600000} ``` **Checklist:** - [ ] Add environment variables to container - [ ] Use secrets for sensitive data (credentials) - [ ] Verify mount volumes for logs - [ ] Test container startup --- ## Phase 4: Database/Storage Setup ### Step 4.1: Create Session Storage Tables (if using PostgreSQL) **File:** `migrations/009_deployment_sessions.sql` (new file) ```sql -- Create deployment sessions table CREATE TABLE IF NOT EXISTS deployment_sessions ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), user_id VARCHAR(255) NOT NULL, target_device VARCHAR(255) NOT NULL, device_type VARCHAR(50), connection_type VARCHAR(50), task_type VARCHAR(100), status VARCHAR(50) NOT NULL DEFAULT 'pending', commands JSONB NOT NULL, results JSONB, approval_timestamp TIMESTAMP, start_timestamp TIMESTAMP, end_timestamp TIMESTAMP, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); -- Create audit log table CREATE TABLE IF NOT EXISTS deployment_audit_log ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), session_id UUID NOT NULL REFERENCES deployment_sessions(id), action VARCHAR(100) NOT NULL, details JSONB, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); -- Create indexes CREATE INDEX idx_deployment_sessions_user_id ON deployment_sessions(user_id); CREATE INDEX idx_deployment_sessions_status ON deployment_sessions(status); CREATE INDEX idx_deployment_sessions_created_at ON deployment_sessions(created_at); CREATE INDEX idx_deployment_audit_session_id ON deployment_audit_log(session_id); ``` **Checklist:** - [ ] Create migration file - [ ] Run migration: `npm run migrate` - [ ] Verify tables created in database - [ ] Test insert/select operations ### Step 4.2: Update Execution Manager for Database Storage (Optional) If using database instead of in-memory session storage: ```typescript // In commandExecution.ts, update storage methods private async storeSession(session: ExecutionSession): Promise<void> { const db = getDatabase(); await db.query( 'INSERT INTO deployment_sessions (id, user_id, target_device, ...) VALUES (...)', [session.sessionId, session.userId, ...] ); } private async retrieveSession(sessionId: string): Promise<ExecutionSession | null> { const db = getDatabase(); const result = await db.query( 'SELECT * FROM deployment_sessions WHERE id = $1', [sessionId] ); return result.rows[0]; } ``` **Checklist:** - [ ] Update session storage to use database - [ ] Update session retrieval methods - [ ] Add audit logging for all operations - [ ] Test persistence across restarts --- ## Phase 5: Terminal Integration ### Step 5.1: Integrate with Web Terminal Service **File:** `src/services/terminal/executor.ts` (or existing terminal service) ```typescript import { CommandExecutionManager } from '../chat/commandExecution'; export class TerminalCommandExecutor { constructor( private terminalService: TerminalService, private executionManager: CommandExecutionManager ) {} async executeDeploymentCommands( sessionId: string, connectionInfo: ConnectionInfo, commands: Command[] ): Promise<ExecutionResult[]> { // Get or create terminal session const terminalSession = await this.terminalService.getSession(connectionInfo); const results: ExecutionResult[] = []; for (const command of commands) { try { const output = await terminalSession.execute(command.command, { timeout: 30000 }); const result: ExecutionResult = { commandId: command.id, success: output.exitCode === 0, stdout: output.stdout, stderr: output.stderr, exitCode: output.exitCode, duration: output.duration, timestamp: new Date() }; // Record in execution manager await this.executionManager.recordResult(sessionId, command.id, result); results.push(result); } catch (error) { const result: ExecutionResult = { commandId: command.id, success: false, stderr: error.message, exitCode: 1, timestamp: new Date() }; await this.executionManager.recordResult(sessionId, command.id, result); results.push(result); } } return results; } } ``` **Checklist:** - [ ] Locate existing terminal service - [ ] Add deployment command executor - [ ] Integrate with connection management - [ ] Test execution against saved connections - [ ] Verify result tracking ### Step 5.2: Connection Manager Integration **File:** `src/services/terminal/connectionManager.ts` (or existing) ```typescript // Ensure saved connections are accessible export async function getSavedConnection(connectionName: string): Promise<ConnectionInfo> { // Load from database or config const connection = await database.query( 'SELECT * FROM terminal_connections WHERE name = $1', [connectionName] ); if (!connection.rows[0]) { throw new Error(`Connection not found: ${connectionName}`); } return { host: connection.rows[0].host, port: connection.rows[0].port, username: connection.rows[0].username, connectionType: connection.rows[0].type, // ssh, telnet, local // ... other fields }; } ``` **Checklist:** - [ ] Verify saved connections are accessible - [ ] Test connection retrieval - [ ] Ensure credentials are loaded safely - [ ] Test SSH/Telnet/Local connections --- ## Phase 6: Testing & Validation ### Step 6.1: Run Comprehensive Tests ```bash # Run unit tests npm test -- --run src/services/chat/__tests__/chatDeployment.test.ts # Run with coverage npm test -- --coverage src/services/chat/__tests__/chatDeployment.test.ts # Run API tests (if exists) npm test -- --run src/api/__tests__/deployments.test.ts # Run integration tests (create if needed) npm test -- --run tests/integration/deployment.integration.test.ts ``` **Expected Results:** - ✅ All 35+ deployment tests pass - ✅ Code coverage > 80% - ✅ No TypeScript errors - ✅ No ESLint warnings **Checklist:** - [ ] All unit tests pass - [ ] Test coverage acceptable (>80%) - [ ] No console errors during tests - [ ] Mock LLM responses work correctly ### Step 6.2: Integration Testing ```bash # Start the gateway npm start # In another terminal, test the API workflow # Test 1: Detection curl -X POST http://localhost:3000/v1/deployments/check \ -H "Content-Type: application/json" \ -d '{"message": "Deploy DHCP on 172.251.96.200"}' # Test 2: Generation curl -X POST http://localhost:3000/v1/deployments/generate \ -H "Content-Type: application/json" \ -d '{ "message": "Deploy DHCP on 172.251.96.200", "context": {"userId": "test-user"} }' # Test 3: Confirmation (use sessionId from Test 2) curl -X POST http://localhost:3000/v1/deployments/{sessionId}/confirm \ -H "Content-Type: application/json" \ -d '{"approved": true}' # Test 4: Check results curl http://localhost:3000/v1/deployments/{sessionId}/results ``` **Checklist:** - [ ] Gateway starts without errors - [ ] API responds to all endpoints - [ ] Detection works correctly - [ ] Command generation works - [ ] Confirmation workflow works - [ ] Results are tracked ### Step 6.3: End-to-End Deployment Test **Setup:** 1. Save a test device connection (MikroTik/Linux) 2. Enable deployment feature flag 3. Configure LLM provider **Test Procedure:** ``` 1. Send chat message: "Deploy DHCP on [test-device]" 2. Verify detection: System recognizes as deployment request 3. Verify generation: Commands generated for DHCP 4. Review commands: Check if realistic and safe 5. Approve: Confirm the deployment 6. Monitor execution: Watch each command execute 7. Verify results: All commands succeeded 8. Check device: DHCP service actually running on test device ``` **Checklist:** - [ ] Chat system detects deployment request - [ ] Commands generate correctly for target device - [ ] User can review and approve - [ ] Commands execute on real device - [ ] Device state changes as expected - [ ] Results are tracked accurately --- ## Phase 7: Security Verification ### Step 7.1: Input Validation **Checklist:** - [ ] Empty message rejected - [ ] Oversized payloads rejected - [ ] Invalid JSON rejected - [ ] Missing required fields rejected - [ ] Invalid device IPs rejected ### Step 7.2: Command Safety **Checklist:** - [ ] Dangerous patterns detected (rm -rf, dd, reboot without safety) - [ ] Critical operations require rollback command - [ ] Permissions/credentials protected in logs - [ ] Suspicious commands flagged with warnings - [ ] User must explicitly approve high-risk operations ### Step 7.3: Audit & Logging **Checklist:** - [ ] All deployments logged with user/device/commands - [ ] All approvals logged with timestamp - [ ] All executions logged with results - [ ] All errors logged with context - [ ] Sensitive data (passwords) not logged - [ ] Logs retained for compliance period ### Step 7.4: Access Control **Checklist:** - [ ] User authentication required for deployment APIs - [ ] User can only see their own sessions - [ ] Admins can view all sessions (optional) - [ ] Devices can have per-user access controls - [ ] Deployment permissions can be role-based --- ## Phase 8: Deployment to Production ### Step 8.1: Pre-Production Checklist - [ ] All code reviewed and approved - [ ] All tests passing (unit + integration) - [ ] Security review completed - [ ] Documentation reviewed - [ ] Database migrations tested - [ ] Performance benchmarked - [ ] Error handling verified - [ ] Rollback procedure documented ### Step 8.2: Production Deployment ```bash # 1. Build Docker image docker build -t ai-mcp-gateway:deployment -f Dockerfile . # 2. Push to registry (if using one) docker push your-registry/ai-mcp-gateway:deployment # 3. Deploy with docker-compose docker-compose -f docker-compose.yml up -d # 4. Verify health curl http://localhost:3000/health # 5. Run smoke tests npm run test:smoke # 6. Monitor logs docker-compose logs -f gateway ``` **Checklist:** - [ ] Build successful - [ ] Image pushed (if applicable) - [ ] Container starts - [ ] Health checks pass - [ ] Smoke tests pass - [ ] No errors in logs ### Step 8.3: Post-Deployment Verification ```bash # Test in production curl -X POST http://prod-gateway/v1/deployments/check \ -H "Content-Type: application/json" \ -d '{"message": "Deploy DHCP on test-device"}' # Monitor for issues tail -f logs/deployment*.log # Check metrics curl http://prod-gateway/metrics | grep deployment ``` **Checklist:** - [ ] API endpoints responding - [ ] Logs showing normal operation - [ ] No error spikes - [ ] Performance acceptable - [ ] Database queries performant --- ## Phase 9: Documentation & Training ### Step 9.1: Documentation Verification - [ ] `DEPLOYMENT_VIA_CHAT.md` - Complete technical reference ✅ - [ ] `DEPLOYMENT_QUICK_START.md` - User guide ✅ - [ ] `DEPLOYMENT_IMPLEMENTATION_SUMMARY.md` - Overview ✅ - [ ] `DEPLOYMENT_DIAGRAMS.md` - Visual reference ✅ - [ ] API documentation - Updated in Postman/Swagger - [ ] Troubleshooting guide - Added to README **Checklist:** - [ ] All docs reviewed for accuracy - [ ] Examples tested and working - [ ] API examples updated with real URLs - [ ] Troubleshooting covers common issues - [ ] Team trained on feature ### Step 9.2: Knowledge Transfer - [ ] Document deployment workflow - [ ] Create runbooks for common deployments - [ ] Document rollback procedures - [ ] Create monitoring/alert rules - [ ] Record video walkthrough **Checklist:** - [ ] Team understands system - [ ] Support team can handle issues - [ ] Documentation maintained --- ## Phase 10: Monitoring & Maintenance ### Step 10.1: Setup Monitoring **Metrics to Track:** ``` - deployment_requests_total (counter) - deployment_success_rate (gauge 0-100) - deployment_duration_seconds (histogram) - command_execution_errors (counter) - session_cleanup_jobs (counter) ``` **Checklist:** - [ ] Metrics exported (Prometheus format) - [ ] Alerts configured for failures - [ ] Dashboard created for overview - [ ] Log aggregation configured ### Step 10.2: Scheduled Maintenance ```bash # Daily: Review logs and metrics # Weekly: Run health check tests # Monthly: Clean up old sessions # Quarterly: Review security # Yearly: Full system audit ``` **Checklist:** - [ ] Maintenance schedule set - [ ] Backup procedure documented - [ ] Disaster recovery tested - [ ] Performance optimization ongoing --- ## Final Sign-Off Checklist ### Code Quality - [ ] All 9 files created and validated - [ ] TypeScript compilation successful - [ ] ESLint passes with no warnings - [ ] Code follows project conventions ### Testing - [ ] 35+ unit tests passing - [ ] Coverage > 80% - [ ] Integration tests passing - [ ] E2E tests passing ### Documentation - [ ] 4 comprehensive documents created - [ ] Examples tested and accurate - [ ] API reference complete - [ ] Troubleshooting guide included ### Integration - [ ] Chat system integration complete - [ ] API routes registered - [ ] Terminal service integrated - [ ] Database/storage configured ### Security - [ ] Input validation verified - [ ] Command safety checks passing - [ ] Audit logging configured - [ ] Access controls enforced ### Deployment - [ ] Environment variables configured - [ ] Docker configuration updated - [ ] Database migrations applied - [ ] Production ready ### Sign-Off - [ ] **Development Team**: _________________ Date: _______ - [ ] **QA Team**: _________________ Date: _______ - [ ] **Security Review**: _________________ Date: _______ - [ ] **DevOps/Operations**: _________________ Date: _______ --- ## Post-Implementation Enhancements ### Planned Features (Future) 1. **Command Templates Library** - Pre-built DHCP, DNS, firewall templates - Community-contributed templates - Template validation & versioning 2. **Advanced Rollback** - Automatic rollback on failure - State snapshots before deployment - Rollback confirmation UI 3. **Scheduling** - Schedule deployments for off-peak hours - Approval queue & scheduling - Deployment batching 4. **Multi-Device Deployments** - Deploy to device groups - Staged rollout (1→5→10→all) - Progress tracking across devices 5. **Cost Analysis** - Estimate LLM cost per deployment - Track historical costs - Optimize for cost 6. **ML-Based Optimization** - Learn from successful deployments - Suggest optimizations - Anomaly detection --- **Created:** [DATE] **Last Updated:** [DATE] **Status:** ✅ Complete - Ready for Integration **Total Files:** 9 **Total Lines of Code:** ~3,200 lines TypeScript **Total Lines of Documentation:** ~1,400 lines Markdown **Test Coverage:** 35+ test cases across 7 suites

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/babasida246/ai-mcp-gateway'

If you have feedback or need assistance with the MCP directory API, please join our Discord server