mcp-ssh-manager 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/.claude/settings.local.json +87 -0
  2. package/.flake8 +15 -0
  3. package/.hooks-config.json +131 -0
  4. package/.pre-commit-config.yaml +105 -0
  5. package/CHANGELOG.md +137 -0
  6. package/CLAUDE.md +190 -0
  7. package/CONTRIBUTING.md +114 -0
  8. package/DESCRIPTION +1 -0
  9. package/INSTALLATION.md +180 -0
  10. package/LICENSE +21 -0
  11. package/QUICKSTART.md +77 -0
  12. package/README.md +718 -0
  13. package/cli/README.md +286 -0
  14. package/cli/build.sh +199 -0
  15. package/cli/commands/server.sh +284 -0
  16. package/cli/demo.sh +107 -0
  17. package/cli/install.sh +164 -0
  18. package/cli/lib/colors.sh +174 -0
  19. package/cli/lib/config.sh +284 -0
  20. package/cli/lib/menu.sh +430 -0
  21. package/cli/migrate.sh +168 -0
  22. package/cli/ssh-manager +525 -0
  23. package/docs/ALIASES_AND_HOOKS.md +285 -0
  24. package/docs/BACKUP_GUIDE.md +500 -0
  25. package/docs/DEPLOYMENT_GUIDE.md +241 -0
  26. package/docs/SEO.md +257 -0
  27. package/examples/backup-workflow.js +481 -0
  28. package/examples/claude-code-config.example.json +40 -0
  29. package/examples/codex-ssh-config.example.toml +71 -0
  30. package/examples/deploy-workflow.py +183 -0
  31. package/glama.json +6 -0
  32. package/package.json +85 -0
  33. package/profiles/README.md +40 -0
  34. package/profiles/default.json +52 -0
  35. package/profiles/docker.json +62 -0
  36. package/profiles/frappe.json +107 -0
  37. package/profiles/nodejs.json +63 -0
  38. package/pyproject.toml +17 -0
  39. package/scripts/setup-hooks.sh +60 -0
  40. package/scripts/validate.sh +76 -0
  41. package/src/backup-manager.js +469 -0
  42. package/src/command-aliases.js +151 -0
  43. package/src/config-loader.js +281 -0
  44. package/src/database-manager.js +555 -0
  45. package/src/deploy-helper.js +176 -0
  46. package/src/health-monitor.js +428 -0
  47. package/src/hooks-system.js +327 -0
  48. package/src/index.js +4499 -0
  49. package/src/logger.js +276 -0
  50. package/src/profile-loader.js +187 -0
  51. package/src/server-aliases.js +150 -0
  52. package/src/server-groups.js +409 -0
  53. package/src/session-manager.js +410 -0
  54. package/src/ssh-key-manager.js +378 -0
  55. package/src/ssh-manager.js +435 -0
  56. package/src/tunnel-manager.js +576 -0
@@ -0,0 +1,481 @@
1
+ /**
2
+ * Backup Workflow Examples for MCP SSH Manager
3
+ *
4
+ * This file demonstrates various backup and restore workflows
5
+ * that can be executed through Claude Code or OpenAI Codex.
6
+ */
7
+
8
+ // ============================================================================
9
+ // EXAMPLE 1: Simple MySQL Backup Before Deployment
10
+ // ============================================================================
11
+
12
+ /*
13
+ User: "Backup production database before deployment"
14
+
15
+ AI executes:
16
+ */
17
+ const mysqlBackup = {
18
+ tool: 'ssh_backup_create',
19
+ params: {
20
+ server: 'production',
21
+ type: 'mysql',
22
+ name: 'pre-deployment',
23
+ database: 'myapp_prod',
24
+ dbUser: 'backup_user',
25
+ dbPassword: process.env.DB_PASSWORD, // From environment
26
+ retention: 7 // Keep for 7 days
27
+ }
28
+ };
29
+
30
+ // Response:
31
+ // {
32
+ // "success": true,
33
+ // "backup_id": "mysql_pre-deployment_2025-10-01T10-30-45-000Z_abc123de",
34
+ // "size_human": "50.00 MB",
35
+ // "location": "/var/backups/ssh-manager/mysql_pre-deployment_2025-10-01T10-30-45-000Z_abc123de.gz"
36
+ // }
37
+
38
+ // ============================================================================
39
+ // EXAMPLE 2: PostgreSQL Backup with Custom Retention
40
+ // ============================================================================
41
+
42
+ /*
43
+ User: "Create PostgreSQL backup and keep it for 30 days"
44
+ */
45
+ const postgresBackup = {
46
+ tool: 'ssh_backup_create',
47
+ params: {
48
+ server: 'staging',
49
+ type: 'postgresql',
50
+ name: 'monthly-backup',
51
+ database: 'analytics_db',
52
+ dbUser: 'postgres',
53
+ dbPassword: process.env.PG_PASSWORD,
54
+ retention: 30, // Keep for 30 days
55
+ compress: true
56
+ }
57
+ };
58
+
59
+ // ============================================================================
60
+ // EXAMPLE 3: Files Backup with Exclusions
61
+ // ============================================================================
62
+
63
+ /*
64
+ User: "Backup website files excluding cache and logs"
65
+ */
66
+ const filesBackup = {
67
+ tool: 'ssh_backup_create',
68
+ params: {
69
+ server: 'web01',
70
+ type: 'files',
71
+ name: 'website-files',
72
+ paths: [
73
+ '/var/www/html',
74
+ '/etc/nginx',
75
+ '/home/deploy/config'
76
+ ],
77
+ exclude: [
78
+ 'cache/*',
79
+ '*.log',
80
+ 'node_modules/',
81
+ '*.tmp'
82
+ ],
83
+ retention: 14
84
+ }
85
+ };
86
+
87
+ // ============================================================================
88
+ // EXAMPLE 4: MongoDB Backup
89
+ // ============================================================================
90
+
91
+ /*
92
+ User: "Backup MongoDB user database"
93
+ */
94
+ const mongoBackup = {
95
+ tool: 'ssh_backup_create',
96
+ params: {
97
+ server: 'mongodb01',
98
+ type: 'mongodb',
99
+ name: 'users-db',
100
+ database: 'users',
101
+ dbHost: 'localhost',
102
+ dbPort: 27017,
103
+ dbUser: 'admin',
104
+ dbPassword: process.env.MONGO_PASSWORD,
105
+ retention: 7
106
+ }
107
+ };
108
+
109
+ // ============================================================================
110
+ // EXAMPLE 5: List All Backups
111
+ // ============================================================================
112
+
113
+ /*
114
+ User: "Show me all MySQL backups on production"
115
+ */
116
+ const listBackups = {
117
+ tool: 'ssh_backup_list',
118
+ params: {
119
+ server: 'production',
120
+ type: 'mysql' // Optional: filter by type
121
+ }
122
+ };
123
+
124
+ // Response:
125
+ // {
126
+ // "success": true,
127
+ // "count": 5,
128
+ // "backups": [
129
+ // {
130
+ // "id": "mysql_pre-deployment_2025-10-01T10-30-45-000Z_abc123de",
131
+ // "type": "mysql",
132
+ // "created_at": "2025-10-01T10:30:45.000Z",
133
+ // "database": "myapp_prod",
134
+ // "size_human": "50.00 MB",
135
+ // "retention_days": 7
136
+ // }
137
+ // ]
138
+ // }
139
+
140
+ // ============================================================================
141
+ // EXAMPLE 6: Restore from Backup
142
+ // ============================================================================
143
+
144
+ /*
145
+ User: "Restore the latest production backup"
146
+ */
147
+
148
+ // Step 1: List backups to find the ID
149
+ const listFirst = {
150
+ tool: 'ssh_backup_list',
151
+ params: {
152
+ server: 'production',
153
+ type: 'mysql'
154
+ }
155
+ };
156
+
157
+ // Step 2: Restore using the backup ID
158
+ const restoreBackup = {
159
+ tool: 'ssh_backup_restore',
160
+ params: {
161
+ server: 'production',
162
+ backupId: 'mysql_pre-deployment_2025-10-01T10-30-45-000Z_abc123de',
163
+ database: 'myapp_prod', // Can restore to different database
164
+ dbUser: 'restore_user',
165
+ dbPassword: process.env.DB_PASSWORD
166
+ }
167
+ };
168
+
169
+ // ============================================================================
170
+ // EXAMPLE 7: Schedule Daily Backups
171
+ // ============================================================================
172
+
173
+ /*
174
+ User: "Schedule daily MySQL backup at 2 AM"
175
+ */
176
+ const scheduleDaily = {
177
+ tool: 'ssh_backup_schedule',
178
+ params: {
179
+ server: 'production',
180
+ schedule: '0 2 * * *', // Daily at 2 AM
181
+ type: 'mysql',
182
+ name: 'daily-prod',
183
+ database: 'myapp_prod',
184
+ retention: 7 // Keep last 7 days
185
+ }
186
+ };
187
+
188
+ // ============================================================================
189
+ // EXAMPLE 8: Schedule Weekly Full Backup
190
+ // ============================================================================
191
+
192
+ /*
193
+ User: "Schedule weekly full backup every Sunday at midnight"
194
+ */
195
+ const scheduleWeekly = {
196
+ tool: 'ssh_backup_schedule',
197
+ params: {
198
+ server: 'production',
199
+ schedule: '0 0 * * 0', // Sunday at midnight
200
+ type: 'mysql',
201
+ name: 'weekly-full',
202
+ database: 'myapp_prod',
203
+ retention: 30 // Keep for 4 weeks
204
+ }
205
+ };
206
+
207
+ // ============================================================================
208
+ // EXAMPLE 9: Multi-Server Backup Strategy
209
+ // ============================================================================
210
+
211
+ /*
212
+ User: "Backup all production databases"
213
+ */
214
+
215
+ // Production MySQL
216
+ const prodMysql = {
217
+ tool: 'ssh_backup_create',
218
+ params: {
219
+ server: 'prod-mysql',
220
+ type: 'mysql',
221
+ name: 'prod-mysql-backup',
222
+ database: 'main_db'
223
+ }
224
+ };
225
+
226
+ // Production PostgreSQL
227
+ const prodPostgres = {
228
+ tool: 'ssh_backup_create',
229
+ params: {
230
+ server: 'prod-postgres',
231
+ type: 'postgresql',
232
+ name: 'prod-pg-backup',
233
+ database: 'analytics'
234
+ }
235
+ };
236
+
237
+ // Production MongoDB
238
+ const prodMongo = {
239
+ tool: 'ssh_backup_create',
240
+ params: {
241
+ server: 'prod-mongo',
242
+ type: 'mongodb',
243
+ name: 'prod-mongo-backup',
244
+ database: 'sessions'
245
+ }
246
+ };
247
+
248
+ // ============================================================================
249
+ // EXAMPLE 10: Pre-Deployment Workflow
250
+ // ============================================================================
251
+
252
+ /*
253
+ Complete deployment workflow with backup safety net
254
+ */
255
+
256
+ async function preDeploymentWorkflow() {
257
+ // Step 1: Create backup
258
+ console.log("Creating pre-deployment backup...");
259
+ const backup = await createBackup({
260
+ server: 'production',
261
+ type: 'mysql',
262
+ name: 'pre-deploy',
263
+ database: 'myapp_prod'
264
+ });
265
+
266
+ console.log(`Backup created: ${backup.backup_id}`);
267
+
268
+ // Step 2: Deploy changes
269
+ console.log("Deploying new version...");
270
+ await deploy({
271
+ server: 'production',
272
+ branch: 'main'
273
+ });
274
+
275
+ // Step 3: Run health check
276
+ console.log("Running health checks...");
277
+ const health = await healthCheck({
278
+ server: 'production'
279
+ });
280
+
281
+ // Step 4: If deployment fails, restore backup
282
+ if (!health.success) {
283
+ console.error("Deployment failed! Rolling back...");
284
+ await restoreBackup({
285
+ server: 'production',
286
+ backupId: backup.backup_id
287
+ });
288
+ console.log("Rollback completed");
289
+ } else {
290
+ console.log("Deployment successful!");
291
+ }
292
+ }
293
+
294
+ // ============================================================================
295
+ // EXAMPLE 11: Disaster Recovery Workflow
296
+ // ============================================================================
297
+
298
+ /*
299
+ User: "Recover production database from yesterday's backup"
300
+ */
301
+
302
+ async function disasterRecovery() {
303
+ // Step 1: List all backups
304
+ const backups = await listBackups({
305
+ server: 'production',
306
+ type: 'mysql'
307
+ });
308
+
309
+ // Step 2: Find yesterday's backup
310
+ const yesterday = new Date();
311
+ yesterday.setDate(yesterday.getDate() - 1);
312
+
313
+ const yesterdayBackup = backups.backups.find(b => {
314
+ const backupDate = new Date(b.created_at);
315
+ return backupDate.toDateString() === yesterday.toDateString();
316
+ });
317
+
318
+ if (!yesterdayBackup) {
319
+ throw new Error("No backup found from yesterday");
320
+ }
321
+
322
+ // Step 3: Restore
323
+ console.log(`Restoring backup: ${yesterdayBackup.id}`);
324
+ await restoreBackup({
325
+ server: 'production',
326
+ backupId: yesterdayBackup.id
327
+ });
328
+
329
+ console.log("Recovery completed successfully");
330
+ }
331
+
332
+ // ============================================================================
333
+ // EXAMPLE 12: Backup to Remote Storage (S3)
334
+ // ============================================================================
335
+
336
+ /*
337
+ User: "Backup database and upload to S3"
338
+ */
339
+
340
+ async function backupToS3() {
341
+ // Step 1: Create local backup
342
+ const backup = await createBackup({
343
+ server: 'production',
344
+ type: 'mysql',
345
+ name: 'prod-db',
346
+ database: 'myapp_prod'
347
+ });
348
+
349
+ // Step 2: Download backup from server
350
+ await downloadFile({
351
+ server: 'production',
352
+ remotePath: backup.location,
353
+ localPath: '/tmp/backup.gz'
354
+ });
355
+
356
+ // Step 3: Upload to S3 (requires AWS CLI on local machine)
357
+ await executeLocal(
358
+ `aws s3 cp /tmp/backup.gz s3://my-backups/${backup.backup_id}.gz`
359
+ );
360
+
361
+ // Step 4: Clean up local file
362
+ await executeLocal('rm /tmp/backup.gz');
363
+
364
+ console.log(`Backup uploaded to S3: s3://my-backups/${backup.backup_id}.gz`);
365
+ }
366
+
367
+ // ============================================================================
368
+ // EXAMPLE 13: Compliance Backup (90-day retention)
369
+ // ============================================================================
370
+
371
+ /*
372
+ User: "Create compliance backup with 90-day retention"
373
+ */
374
+ const complianceBackup = {
375
+ tool: 'ssh_backup_create',
376
+ params: {
377
+ server: 'production',
378
+ type: 'mysql',
379
+ name: 'compliance-q4-2025',
380
+ database: 'financial_data',
381
+ retention: 90, // 90 days for compliance
382
+ compress: true
383
+ }
384
+ };
385
+
386
+ // Schedule monthly compliance backups
387
+ const monthlyCompliance = {
388
+ tool: 'ssh_backup_schedule',
389
+ params: {
390
+ server: 'production',
391
+ schedule: '0 3 1 * *', // 1st of each month at 3 AM
392
+ type: 'mysql',
393
+ name: 'monthly-compliance',
394
+ database: 'financial_data',
395
+ retention: 365 // Keep for 1 year
396
+ }
397
+ };
398
+
399
+ // ============================================================================
400
+ // CRON SCHEDULE REFERENCE
401
+ // ============================================================================
402
+
403
+ /*
404
+ Common cron schedules:
405
+
406
+ Daily:
407
+ - "0 2 * * *" // Every day at 2 AM
408
+ - "0 0 * * *" // Every day at midnight
409
+
410
+ Hourly:
411
+ - "0 * * * *" // Every hour at minute 0
412
+ - "0 */6 * * *" // Every 6 hours
413
+
414
+ Weekly:
415
+ - "0 0 * * 0" // Every Sunday at midnight
416
+ - "0 3 * * 1" // Every Monday at 3 AM
417
+
418
+ Monthly:
419
+ - "0 0 1 * *" // 1st of month at midnight
420
+ - "0 2 15 * *" // 15th of month at 2 AM
421
+
422
+ Weekdays:
423
+ - "0 1 * * 1-5" // Mon-Fri at 1 AM
424
+
425
+ Custom:
426
+ - "*/30 * * * *" // Every 30 minutes
427
+ - "0 */4 * * *" // Every 4 hours
428
+ - "0 9-17 * * *" // Every hour from 9 AM to 5 PM
429
+ */
430
+
431
+ // ============================================================================
432
+ // NOTES
433
+ // ============================================================================
434
+
435
+ /*
436
+ Best Practices:
437
+
438
+ 1. Security:
439
+ - Store passwords in environment variables
440
+ - Use SSH keys for authentication
441
+ - Restrict backup directory permissions (chmod 700)
442
+ - Encrypt sensitive backups
443
+
444
+ 2. Testing:
445
+ - Test restore procedures monthly
446
+ - Verify backup integrity
447
+ - Document recovery times
448
+ - Keep runbooks updated
449
+
450
+ 3. Monitoring:
451
+ - Set up alerts for backup failures
452
+ - Monitor disk space
453
+ - Track backup sizes and durations
454
+ - Review retention policies quarterly
455
+
456
+ 4. Storage:
457
+ - Implement 3-2-1 backup rule
458
+ - Consider cloud storage (S3, GCS, Azure)
459
+ - Monitor backup costs
460
+ - Clean up old backups
461
+
462
+ 5. Compliance:
463
+ - Follow regulatory retention requirements
464
+ - Encrypt backups at rest
465
+ - Maintain audit logs
466
+ - Test disaster recovery procedures
467
+ */
468
+
469
+ module.exports = {
470
+ mysqlBackup,
471
+ postgresBackup,
472
+ filesBackup,
473
+ mongoBackup,
474
+ listBackups,
475
+ restoreBackup,
476
+ scheduleDaily,
477
+ complianceBackup,
478
+ preDeploymentWorkflow,
479
+ disasterRecovery,
480
+ backupToS3
481
+ };
@@ -0,0 +1,40 @@
1
+ {
2
+ "apiKey": "your-anthropic-api-key-here",
3
+ "mcpServers": {
4
+ "ssh-manager": {
5
+ "command": "node",
6
+ "args": ["/path/to/mcp-ssh-manager/src/index.js"],
7
+ "autoApprove": [
8
+ "mcp__ssh-manager__ssh_execute",
9
+ "mcp__ssh-manager__ssh_list_servers",
10
+ "mcp__ssh-manager__ssh_upload",
11
+ "mcp__ssh-manager__ssh_download",
12
+ "mcp__ssh-manager__ssh_sync",
13
+ "mcp__ssh-manager__ssh_alias",
14
+ "mcp__ssh-manager__ssh_deploy",
15
+ "mcp__ssh-manager__ssh_execute_sudo",
16
+ "mcp__ssh-manager__ssh_tunnel_create",
17
+ "mcp__ssh-manager__ssh_tunnel_list",
18
+ "mcp__ssh-manager__ssh_tunnel_close",
19
+ "mcp__ssh-manager__ssh_session_start",
20
+ "mcp__ssh-manager__ssh_session_send",
21
+ "mcp__ssh-manager__ssh_session_list",
22
+ "mcp__ssh-manager__ssh_session_close",
23
+ "mcp__ssh-manager__ssh_execute_group",
24
+ "mcp__ssh-manager__ssh_group_manage",
25
+ "mcp__ssh-manager__ssh_tail",
26
+ "mcp__ssh-manager__ssh_monitor",
27
+ "mcp__ssh-manager__ssh_history",
28
+ "mcp__ssh-manager__ssh_connection_status",
29
+ "mcp__ssh-manager__ssh_key_manage",
30
+ "mcp__ssh-manager__ssh_command_alias",
31
+ "mcp__ssh-manager__ssh_hooks",
32
+ "mcp__ssh-manager__ssh_profile"
33
+ ]
34
+ },
35
+ "example-other-server": {
36
+ "command": "npx",
37
+ "args": ["-y", "@modelcontextprotocol/server-memory"]
38
+ }
39
+ }
40
+ }
@@ -0,0 +1,71 @@
1
+ # OpenAI Codex SSH Configuration Example
2
+ # Place this file at: ~/.codex/ssh-config.toml
3
+ #
4
+ # This file contains SSH server configurations for MCP SSH Manager
5
+ # when used with OpenAI Codex.
6
+ #
7
+ # For Claude Code users: Use .env format instead (see .env.example)
8
+
9
+ # Production Server Example (using SSH key - RECOMMENDED)
10
+ [ssh_servers.production]
11
+ host = "prod.example.com"
12
+ user = "admin"
13
+ key_path = "~/.ssh/id_rsa" # Path to SSH private key
14
+ port = 22 # Optional, defaults to 22
15
+ default_dir = "/var/www/html" # Optional, default working directory
16
+ description = "Production web server" # Optional description
17
+ sudo_password = "sudo_pass" # Optional, for automated deployments
18
+
19
+ # Staging Server Example (using password authentication)
20
+ [ssh_servers.staging]
21
+ host = "staging.example.com"
22
+ user = "deploy"
23
+ password = "secure_password" # Use SSH keys instead when possible
24
+ port = 2222 # Custom SSH port
25
+ default_dir = "/home/deploy/app"
26
+ description = "Staging environment"
27
+
28
+ # Database Server Example
29
+ [ssh_servers.db_server]
30
+ host = "192.168.1.100"
31
+ user = "dbadmin"
32
+ key_path = "~/.ssh/db_key"
33
+ port = 22
34
+ default_dir = "/var/lib/mysql"
35
+ description = "MySQL database server"
36
+
37
+ # Development Server Example (minimal configuration)
38
+ [ssh_servers.dev]
39
+ host = "dev.example.com"
40
+ user = "developer"
41
+ key_path = "~/.ssh/dev_key"
42
+
43
+ # Docker Host Example
44
+ [ssh_servers.docker_host]
45
+ host = "docker.example.com"
46
+ user = "docker"
47
+ key_path = "~/.ssh/docker_key"
48
+ default_dir = "/opt/docker"
49
+ description = "Docker container host"
50
+
51
+ # Multiple Environment Examples
52
+ [ssh_servers.app_prod]
53
+ host = "app-prod.example.com"
54
+ user = "ubuntu"
55
+ key_path = "~/.ssh/aws_prod_key"
56
+ default_dir = "/var/www/myapp"
57
+ description = "App production server"
58
+
59
+ [ssh_servers.app_staging]
60
+ host = "app-staging.example.com"
61
+ user = "ubuntu"
62
+ key_path = "~/.ssh/aws_staging_key"
63
+ default_dir = "/var/www/myapp"
64
+ description = "App staging server"
65
+
66
+ # Notes:
67
+ # 1. key_path is RECOMMENDED over password for better security
68
+ # 2. Paths starting with ~ will be expanded to your home directory
69
+ # 3. default_dir is optional but recommended for convenience
70
+ # 4. sudo_password should only be used for trusted automation scenarios
71
+ # 5. All server names are case-insensitive and normalized to lowercase