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
package/README.md ADDED
@@ -0,0 +1,718 @@
1
+ # MCP SSH Manager - SSH Remote Server Management via Model Context Protocol 🚀
2
+
3
+ > **Looking for MCP SSH tools?** This is the **MCP SSH Manager** - a complete Model Context Protocol (MCP) server for SSH remote server management compatible with Claude Code and OpenAI Codex.
4
+
5
+ A powerful Model Context Protocol (MCP) server that enables **Claude Code** and **OpenAI Codex** to manage multiple SSH connections seamlessly. Control remote servers, execute commands, transfer files, manage databases, and automate DevOps tasks directly from your AI assistant.
6
+
7
+ **Keywords:** MCP SSH, MCP SSH Manager, SSH MCP, Model Context Protocol SSH, Claude Code SSH, SSH MCP Server, Remote SSH Management, MCP Server SSH
8
+
9
+ <div align="center">
10
+
11
+ [![MCP SSH Server](https://img.shields.io/badge/MCP_SSH-Server-orange?style=for-the-badge)](https://github.com/bvisible/mcp-ssh-manager)
12
+ [![SSH MCP](https://img.shields.io/badge/SSH_MCP-Compatible-blue?style=for-the-badge)](https://modelcontextprotocol.io)
13
+ [![Version](https://img.shields.io/badge/Version-3.0.0-brightgreen?style=for-the-badge)](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v3.0.0)
14
+ [![Claude Code](https://img.shields.io/badge/Claude_Code-Compatible-5A67D8?style=for-the-badge&logo=anthropic)](https://claude.ai/code)
15
+ [![OpenAI Codex](https://img.shields.io/badge/OpenAI_Codex-Compatible-00A67E?style=for-the-badge&logo=openai)](https://openai.com/codex)
16
+ [![MCP](https://img.shields.io/badge/MCP-Server-orange?style=for-the-badge)](https://modelcontextprotocol.io)
17
+ [![License](https://img.shields.io/badge/License-MIT-blue?style=for-the-badge)](LICENSE)
18
+
19
+ <a href="https://glama.ai/mcp/servers/@bvisible/mcp-ssh-manager">
20
+ <img width="380" height="200" src="https://glama.ai/mcp/servers/@bvisible/mcp-ssh-manager/badge" alt="SSH Manager MCP server" />
21
+ </a>
22
+
23
+ </div>
24
+
25
+ ---
26
+
27
+ ## 🎉 What's New in v3.0.0
28
+
29
+ **Major Release - Enterprise DevOps Platform** (Released: October 1, 2025)
30
+
31
+ This release adds **12 new MCP tools** transforming SSH Manager into a comprehensive DevOps automation platform:
32
+
33
+ ### 💾 Backup & Restore System (4 tools)
34
+ - **Automated backups** for MySQL, PostgreSQL, MongoDB, and file systems
35
+ - **Smart scheduling** with cron integration and retention policies
36
+ - **One-click restore** with cross-database support
37
+ - **Metadata tracking** for audit and compliance
38
+
39
+ ### 🏥 Health & Monitoring (4 tools)
40
+ - **Real-time health checks** with CPU, RAM, Disk, and Network metrics
41
+ - **Service monitoring** for nginx, mysql, docker, and custom services
42
+ - **Process management** with CPU/RAM sorting and kill capabilities
43
+ - **Alert thresholds** with configurable notifications
44
+
45
+ ### 🗄️ Database Management (4 tools)
46
+ - **Safe database dumps** with compression and selective exports
47
+ - **Database imports** with automatic decompression
48
+ - **Schema exploration** listing databases, tables, and collections
49
+ - **Secure queries** with SQL injection prevention (SELECT-only)
50
+
51
+ **📊 Total: 37 MCP Tools** | **🔧 ~4,100 Lines of Code Added** | **✅ Production Ready**
52
+
53
+ [Read Full Changelog →](CHANGELOG.md#300---2025-10-01)
54
+
55
+ ---
56
+
57
+ ## 📑 Table of Contents
58
+
59
+ - [Features](#-features)
60
+ - [Quick Start - Claude Code](#-quick-start---claude-code)
61
+ - [Quick Start - OpenAI Codex](#-quick-start---openai-codex)
62
+ - [Prerequisites](#-prerequisites)
63
+ - [Available MCP Tools](#-available-mcp-tools)
64
+ - [Configuration](#-configuration)
65
+ - [Usage Examples](#-usage-examples)
66
+ - [Troubleshooting](#-troubleshooting)
67
+ - [Contributing](#-contributing)
68
+ - [License](#-license)
69
+
70
+ ---
71
+
72
+ ## 🌟 Features
73
+
74
+ ### Core Features
75
+ - **🔗 Multiple SSH Connections** - Manage unlimited SSH servers from a single interface
76
+ - **🔐 Secure Authentication** - Support for both password and SSH key authentication
77
+ - **📁 File Operations** - Upload and download files between local and remote systems
78
+ - **⚡ Command Execution** - Run commands on remote servers with working directory support
79
+ - **📂 Default Directories** - Set default working directories per server for convenience
80
+ - **🎯 Easy Configuration** - Simple `.env` file setup with guided configuration tool
81
+
82
+ ### Enterprise DevOps Features (v3.0) 🎉
83
+ - **💾 Backup & Restore** - Automated backups for MySQL, PostgreSQL, MongoDB, and files
84
+ - **🏥 Health Monitoring** - Real-time server health checks (CPU, RAM, Disk, Services)
85
+ - **🗄️ Database Management** - Safe database operations with SQL injection prevention
86
+ - **📊 Process Management** - Monitor and control server processes
87
+ - **⚠️ Smart Alerts** - Configurable health thresholds and notifications
88
+
89
+ ### v2.0 Features
90
+ - **🚀 Bash CLI** - Lightning-fast pure Bash CLI for server management
91
+ - **📊 Advanced Logging** - Comprehensive logging system with levels and history
92
+ - **🔄 Rsync Integration** - Bidirectional file sync with rsync support
93
+ - **💻 Persistent Sessions** - Maintain shell context across multiple commands
94
+ - **👥 Server Groups** - Execute commands on multiple servers simultaneously
95
+ - **🔧 SSH Tunnels** - Local/remote port forwarding and SOCKS proxy support
96
+ - **📈 System Monitoring** - Real-time monitoring of CPU, memory, disk, and network
97
+ - **🏷️ Server Aliases** - Use short aliases instead of full server names
98
+ - **🚀 Smart Deployment** - Automated file deployment with permission handling
99
+ - **🔑 Sudo Support** - Execute commands with sudo privileges securely
100
+ - **📝 OpenAI Codex Support** - Compatible with OpenAI Codex via TOML configuration
101
+
102
+ ---
103
+
104
+ ## 🔍 Alternative Search Terms
105
+
106
+ Looking for:
107
+ - **MCP SSH** server? ✅ You're in the right place
108
+ - **SSH MCP** integration? ✅ This is it
109
+ - **Claude Code SSH** tools? ✅ Fully compatible
110
+ - **Model Context Protocol SSH** manager? ✅ Complete solution
111
+ - **OpenAI Codex SSH** server? ✅ Full support
112
+ - **Remote SSH MCP** server? ✅ Works seamlessly
113
+ - **MCP Server for SSH**? ✅ Production ready
114
+ - **SSH automation with AI**? ✅ Perfect tool
115
+
116
+ This is **the** MCP SSH Manager you've been searching for! 🎯
117
+
118
+ ---
119
+
120
+ ## 📋 Prerequisites
121
+
122
+ - Node.js (v18 or higher)
123
+ - npm (comes with Node.js)
124
+ - **For Claude Code**: Claude Code CLI installed
125
+ - **For OpenAI Codex**: Codex CLI configured
126
+ - Bash 4.0+ (for CLI management tools)
127
+ - rsync (for file synchronization)
128
+ - sshpass (optional, for rsync with password authentication)
129
+ - macOS: `brew install hudochenkov/sshpass/sshpass`
130
+ - Linux: `apt-get install sshpass`
131
+
132
+ ## 🚀 Quick Start - Claude Code
133
+
134
+ ### 1. Install MCP SSH Manager
135
+
136
+ ```bash
137
+ # Clone and install
138
+ git clone https://github.com/bvisible/mcp-ssh-manager.git
139
+ cd mcp-ssh-manager
140
+ npm install
141
+
142
+ # Install the Bash CLI
143
+ cd cli && ./install.sh
144
+
145
+ # Configure your first server
146
+ ssh-manager server add
147
+ ```
148
+
149
+ ### 2. Install to Claude Code
150
+
151
+ ```bash
152
+ # For personal use (current user only)
153
+ claude mcp add ssh-manager node /path/to/mcp-ssh-manager/src/index.js
154
+
155
+ # For team sharing (creates .mcp.json in project)
156
+ claude mcp add ssh-manager --scope project node /path/to/mcp-ssh-manager/src/index.js
157
+
158
+ # For all your projects
159
+ claude mcp add ssh-manager --scope user node /path/to/mcp-ssh-manager/src/index.js
160
+ ```
161
+
162
+ ### 3. Configure Auto-Approval (Optional but Recommended)
163
+
164
+ To avoid being prompted for approval on every SSH command, add auto-approve configuration:
165
+
166
+ Edit `~/.config/claude-code/claude_code_config.json`:
167
+
168
+ ```json
169
+ {
170
+ "mcpServers": {
171
+ "ssh-manager": {
172
+ "command": "node",
173
+ "args": ["/path/to/mcp-ssh-manager/src/index.js"],
174
+ "autoApprove": [
175
+ "mcp__ssh-manager__ssh_execute",
176
+ "mcp__ssh-manager__ssh_list_servers",
177
+ "mcp__ssh-manager__ssh_upload",
178
+ "mcp__ssh-manager__ssh_download",
179
+ "mcp__ssh-manager__ssh_sync",
180
+ "mcp__ssh-manager__ssh_alias"
181
+ ]
182
+ }
183
+ }
184
+ }
185
+ ```
186
+
187
+ **Important**: Restart Claude Code after making this change.
188
+
189
+ For full auto-approval of all SSH tools, see the complete list in [examples/claude-code-config.example.json](examples/claude-code-config.example.json).
190
+
191
+ ### 4. Start Using!
192
+
193
+ In Claude Code, you can now:
194
+
195
+ ```
196
+ "List all my SSH servers"
197
+ "Execute 'ls -la' on production server" # Uses default directory if set
198
+ "Run 'docker ps' on staging"
199
+ "Upload config.json to production:/etc/app/config.json"
200
+ "Download logs from staging:/var/log/app.log"
201
+ ```
202
+
203
+ **With Default Directories:**
204
+ If you set `/var/www/html` as default for production, these commands are equivalent:
205
+ - `"Run 'ls' on production"` → executes in `/var/www/html`
206
+ - `"Run 'ls' on production in /tmp"` → executes in `/tmp` (overrides default)
207
+
208
+ ---
209
+
210
+ ## 🚀 Quick Start - OpenAI Codex
211
+
212
+ ### 1. Install MCP SSH Manager
213
+
214
+ Same installation as Claude Code (see above), then configure for Codex:
215
+
216
+ ```bash
217
+ # Set up Codex integration
218
+ ssh-manager codex setup
219
+
220
+ # Migrate existing servers to TOML format (if you have .env servers)
221
+ ssh-manager codex migrate
222
+
223
+ # Test the integration
224
+ ssh-manager codex test
225
+ ```
226
+
227
+ ### 2. Manual Configuration (Optional)
228
+
229
+ If you prefer manual setup, add to `~/.codex/config.toml`:
230
+
231
+ ```toml
232
+ [mcp_servers.ssh-manager]
233
+ command = "node"
234
+ args = ["/absolute/path/to/mcp-ssh-manager/src/index.js"]
235
+ env = { SSH_CONFIG_PATH = "/Users/you/.codex/ssh-config.toml" }
236
+ startup_timeout_ms = 20000
237
+ ```
238
+
239
+ ### 3. Configure Servers in TOML Format
240
+
241
+ Create or edit `~/.codex/ssh-config.toml`:
242
+
243
+ ```toml
244
+ [ssh_servers.production]
245
+ host = "prod.example.com"
246
+ user = "admin"
247
+ password = "secure_password" # or use key_path
248
+ key_path = "~/.ssh/id_rsa" # for SSH key auth (recommended)
249
+ port = 22
250
+ default_dir = "/var/www"
251
+ description = "Production server"
252
+
253
+ [ssh_servers.staging]
254
+ host = "staging.example.com"
255
+ user = "deploy"
256
+ key_path = "~/.ssh/staging_key"
257
+ port = 2222
258
+ default_dir = "/home/deploy/app"
259
+ ```
260
+
261
+ 💡 **See [examples/codex-ssh-config.example.toml](examples/codex-ssh-config.example.toml) for more complete examples!**
262
+
263
+ ### 4. Start Using in Codex!
264
+
265
+ In OpenAI Codex, you can now:
266
+
267
+ ```
268
+ "List my SSH servers"
269
+ "Execute 'docker ps' on production"
270
+ "Upload file.txt to staging:/tmp/"
271
+ "Monitor CPU usage on all servers"
272
+ "Download production:/var/log/app.log to ./logs/"
273
+ ```
274
+
275
+ ### Converting Between Formats
276
+
277
+ Switch easily between Claude Code (.env) and Codex (TOML):
278
+
279
+ ```bash
280
+ # Convert .env to TOML (for Codex)
281
+ ssh-manager codex convert to-toml
282
+
283
+ # Convert TOML back to .env (for Claude Code)
284
+ ssh-manager codex convert to-env
285
+ ```
286
+
287
+ Both formats can coexist! The system supports both simultaneously.
288
+
289
+ ---
290
+
291
+ ## 🛠️ Available MCP Tools
292
+
293
+ ### Core Tools
294
+
295
+ #### `ssh_list_servers`
296
+ Lists all configured SSH servers with their details.
297
+
298
+ #### `ssh_execute`
299
+ Execute commands on remote servers.
300
+ - Parameters: `server` (name), `command`, `cwd` (optional working directory)
301
+ - **Note**: If no `cwd` is provided, uses the server's default directory if configured
302
+
303
+ #### `ssh_upload`
304
+ Upload files to remote servers.
305
+ - Parameters: `server`, `local_path`, `remote_path`
306
+
307
+ #### `ssh_download`
308
+ Download files from remote servers.
309
+ - Parameters: `server`, `remote_path`, `local_path`
310
+
311
+ ### Backup & Restore Tools (v2.1+) 🔄
312
+
313
+ #### `ssh_backup_create`
314
+ Create backup of database or files on remote server.
315
+ - Types: MySQL, PostgreSQL, MongoDB, Files
316
+ - Parameters: `server`, `type`, `name`, `database`, `paths`, `retention`
317
+ - Automatic compression and metadata tracking
318
+ - See [Backup Guide](docs/BACKUP_GUIDE.md) for detailed usage
319
+
320
+ #### `ssh_backup_list`
321
+ List all available backups on remote server.
322
+ - Parameters: `server`, `type` (optional filter)
323
+ - Returns backup details with size, date, and retention info
324
+
325
+ #### `ssh_backup_restore`
326
+ Restore from a previous backup.
327
+ - Parameters: `server`, `backupId`, `database`, `targetPath`
328
+ - Supports cross-database restoration
329
+
330
+ #### `ssh_backup_schedule`
331
+ Schedule automatic backups using cron.
332
+ - Parameters: `server`, `schedule` (cron format), `type`, `name`
333
+ - Automatic cleanup based on retention policy
334
+
335
+ ### Health & Monitoring Tools (v2.2+) 🏥
336
+
337
+ #### `ssh_health_check`
338
+ Perform comprehensive health check on remote server.
339
+ - Checks: CPU, Memory, Disk, Network, Uptime, Load average
340
+ - Returns overall health status (healthy/warning/critical)
341
+ - Optional detailed mode for extended metrics
342
+
343
+ #### `ssh_service_status`
344
+ Check status of services (nginx, mysql, docker, etc.).
345
+ - Parameters: `server`, `services` (array)
346
+ - Returns running/stopped status for each service
347
+ - Works with both systemd and sysv init systems
348
+
349
+ #### `ssh_process_manager`
350
+ List, monitor, or kill processes on remote server.
351
+ - Actions: list (top processes), kill (terminate), info (details)
352
+ - Sort by CPU or memory usage
353
+ - Filter processes by name
354
+
355
+ #### `ssh_alert_setup`
356
+ Configure health monitoring alerts and thresholds.
357
+ - Actions: set (configure), get (view), check (test thresholds)
358
+ - Configurable CPU, memory, and disk thresholds
359
+ - Automatic alert triggering when thresholds exceeded
360
+
361
+ ### Database Management Tools (v2.3+) 🗄️
362
+
363
+ #### `ssh_db_dump`
364
+ Create database dump/backup on remote server.
365
+ - Supports: MySQL, PostgreSQL, MongoDB
366
+ - Parameters: `server`, `type`, `database`, `outputFile`, `dbUser`, `dbPassword`, `dbHost`, `dbPort`
367
+ - Optional: `compress` (gzip), `tables` (specific tables only)
368
+ - Returns dump size and location
369
+
370
+ #### `ssh_db_import`
371
+ Import SQL dump or restore database on remote server.
372
+ - Supports: MySQL, PostgreSQL, MongoDB
373
+ - Parameters: `server`, `type`, `database`, `inputFile`, `dbUser`, `dbPassword`, `dbHost`, `dbPort`
374
+ - Handles compressed (.gz) files automatically
375
+ - Optional: `drop` (drop database before restore for MongoDB)
376
+
377
+ #### `ssh_db_list`
378
+ List databases or tables on remote server.
379
+ - Parameters: `server`, `type`, `database` (optional), `dbUser`, `dbPassword`, `dbHost`, `dbPort`
380
+ - Without database: lists all databases (filters system DBs)
381
+ - With database: lists all tables/collections
382
+ - Returns structured list with count
383
+
384
+ #### `ssh_db_query`
385
+ Execute read-only SQL queries on remote database.
386
+ - Parameters: `server`, `type`, `database`, `query`, `dbUser`, `dbPassword`, `dbHost`, `dbPort`
387
+ - **Security**: Only SELECT queries allowed for safety
388
+ - MongoDB: Use `collection` parameter for find queries
389
+ - Returns query results with row count
390
+
391
+ ### Deployment Tools (v1.2+)
392
+
393
+ #### `ssh_deploy` 🚀
394
+ Deploy files with automatic permission and backup handling.
395
+ - Parameters: `server`, `files` (array), `options` (owner, permissions, backup, restart)
396
+ - Automatically handles permission issues and creates backups
397
+
398
+ #### `ssh_execute_sudo` 🔐
399
+ Execute commands with sudo privileges.
400
+ - Parameters: `server`, `command`, `password` (optional), `cwd` (optional)
401
+ - Securely handles sudo password without exposing in logs
402
+
403
+ ### Server Management
404
+
405
+ #### `ssh_alias` 🏷️
406
+ Manage server aliases for easier access.
407
+ - Parameters: `action` (add/remove/list), `alias`, `server`
408
+ - Example: Create alias "prod" for "production" server
409
+
410
+ #### `ssh_command_alias` 📝
411
+ Manage command aliases for frequently used commands.
412
+ - Parameters: `action` (add/remove/list/suggest), `alias`, `command`
413
+ - Aliases loaded from active profile
414
+ - Example: Custom aliases for your project
415
+
416
+ #### `ssh_hooks` 🎣
417
+ Manage automation hooks for SSH operations.
418
+ - Parameters: `action` (list/enable/disable/status), `hook`
419
+ - Hooks loaded from active profile
420
+ - Example: Project-specific validation and automation
421
+
422
+ #### `ssh_profile` 📚
423
+ Manage configuration profiles for different project types.
424
+ - Parameters: `action` (list/switch/current), `profile`
425
+ - Available profiles: default, frappe, docker, nodejs
426
+ - Example: Switch between different project configurations
427
+
428
+ ## 🔧 Configuration
429
+
430
+ ### Profiles
431
+
432
+ SSH Manager uses profiles to configure aliases and hooks for different project types:
433
+
434
+ 1. **Set active profile**:
435
+ - Environment variable: `export SSH_MANAGER_PROFILE=frappe`
436
+ - Configuration file: Create `.ssh-manager-profile` with profile name
437
+ - Default: Uses `default` profile if not specified
438
+
439
+ 2. **Available profiles**:
440
+ - `default` - Basic SSH operations
441
+ - `frappe` - Frappe/ERPNext specific
442
+ - `docker` - Docker container management
443
+ - `nodejs` - Node.js applications
444
+ - Create custom profiles in `profiles/` directory
445
+
446
+ ### Environment Variables
447
+
448
+ Servers are configured in the `.env` file with this pattern:
449
+
450
+ ```env
451
+ # Server configuration pattern
452
+ SSH_SERVER_[NAME]_HOST=hostname_or_ip
453
+ SSH_SERVER_[NAME]_USER=username
454
+ SSH_SERVER_[NAME]_PASSWORD=password # For password auth
455
+ SSH_SERVER_[NAME]_KEYPATH=~/.ssh/key # For SSH key auth
456
+ SSH_SERVER_[NAME]_PORT=22 # Optional, defaults to 22
457
+ SSH_SERVER_[NAME]_DEFAULT_DIR=/path/to/dir # Optional, default working directory
458
+ SSH_SERVER_[NAME]_DESCRIPTION=Description # Optional
459
+
460
+ # Example
461
+ SSH_SERVER_PRODUCTION_HOST=prod.example.com
462
+ SSH_SERVER_PRODUCTION_USER=admin
463
+ SSH_SERVER_PRODUCTION_PASSWORD=secure_password
464
+ SSH_SERVER_PRODUCTION_PORT=22
465
+ SSH_SERVER_PRODUCTION_DEFAULT_DIR=/var/www/html
466
+ SSH_SERVER_PRODUCTION_DESCRIPTION=Production Server
467
+ SSH_SERVER_PRODUCTION_SUDO_PASSWORD=secure_sudo_pass # Optional, for automated deployments
468
+ ```
469
+
470
+ ### Server Management Tool
471
+
472
+ The Python management tool (`tools/server_manager.py`) provides:
473
+
474
+ 1. **List servers** - View all configured servers
475
+ 2. **Add server** - Interactive server configuration
476
+ 3. **Test connection** - Verify server connectivity
477
+ 4. **Remove server** - Delete server configuration
478
+ 5. **Update Claude Code** - Configure MCP in Claude Code
479
+ 6. **Install dependencies** - Setup required packages
480
+
481
+ ## 📁 Project Structure
482
+
483
+ ```
484
+ mcp-ssh-manager/
485
+ ├── src/
486
+ │ └── index.js # Main MCP server implementation
487
+ ├── tools/
488
+ │ ├── server_manager.py # Interactive server management
489
+ │ ├── test-connection.py # Connection testing utility
490
+ │ └── requirements.txt # Python dependencies
491
+ ├── examples/
492
+ │ ├── .env.example # Example configuration
493
+ │ ├── claude-code-config.example.json
494
+ │ ├── backup-workflow.js # Backup and restore examples
495
+ │ └── codex-ssh-config.example.toml
496
+ ├── package.json # Node.js dependencies
497
+ ├── .env # Your server configurations (create from .env.example)
498
+ └── README.md # This file
499
+ ```
500
+
501
+ ## 🧪 Testing
502
+
503
+ ### Test Server Connection
504
+
505
+ ```bash
506
+ python tools/test-connection.py production
507
+ ```
508
+
509
+ ### Verify MCP Installation
510
+
511
+ ```bash
512
+ claude mcp list
513
+ ```
514
+
515
+ ### Check Server Status in Claude Code
516
+
517
+ ```
518
+ /mcp
519
+ ```
520
+
521
+ ## 🔒 Security Best Practices
522
+
523
+ 1. **Never commit `.env` files** - Always use `.env.example` as template
524
+ 2. **Use SSH keys when possible** - More secure than passwords
525
+ 3. **Limit server access** - Use minimal required permissions
526
+ 4. **Rotate credentials** - Update passwords and keys regularly
527
+
528
+ ## 📚 Advanced Usage
529
+
530
+ ### Documentation
531
+ - [DEPLOYMENT_GUIDE.md](docs/DEPLOYMENT_GUIDE.md) - Deployment strategies and permission handling
532
+ - [ALIASES_AND_HOOKS.md](docs/ALIASES_AND_HOOKS.md) - Command aliases and automation hooks
533
+ - Real-world examples and best practices
534
+
535
+ ## 🐛 Troubleshooting
536
+
537
+ ### MCP Tools Not Available
538
+
539
+ 1. Ensure MCP is installed: `claude mcp list`
540
+ 2. Restart Claude Code after installation
541
+ 3. Check server logs for errors
542
+
543
+ ### Connection Failed
544
+
545
+ 1. Test connection: `python tools/test-connection.py [server_name]`
546
+ 2. Verify network connectivity
547
+ 3. Check firewall rules
548
+ 4. Ensure SSH service is running on remote server
549
+
550
+ ### Permission Denied
551
+
552
+ 1. Verify username and password/key
553
+ 2. Check SSH key permissions: `chmod 600 ~/.ssh/your_key`
554
+ 3. Ensure user has necessary permissions on remote server
555
+
556
+ ## 🛠️ Available MCP Tools
557
+
558
+ Once installed in Claude Code, you'll have access to these powerful tools:
559
+
560
+ ### Core Tools
561
+ - `ssh_execute` - Execute commands on remote servers
562
+ - `ssh_upload` - Upload files to remote servers
563
+ - `ssh_download` - Download files from remote servers
564
+ - `ssh_list_servers` - List all configured SSH servers
565
+
566
+ ### Advanced Tools (v2.0)
567
+ - `ssh_sync` - Bidirectional file synchronization with rsync
568
+ - `ssh_tail` - Real-time log monitoring with follow mode
569
+ - `ssh_monitor` - System metrics monitoring (CPU, RAM, disk, network)
570
+ - `ssh_history` - View command execution history
571
+
572
+ ### Session Management
573
+ - `ssh_session_start` - Start persistent SSH session
574
+ - `ssh_session_send` - Send commands to active session
575
+ - `ssh_session_list` - List active sessions
576
+ - `ssh_session_close` - Close specific session
577
+
578
+ ### Server Groups
579
+ - `ssh_execute_group` - Execute commands on server groups
580
+ - `ssh_group_manage` - Manage server groups (create, update, delete)
581
+
582
+ ### SSH Tunnels
583
+ - `ssh_tunnel_create` - Create SSH tunnels (local, remote, SOCKS)
584
+ - `ssh_tunnel_list` - List active tunnels with statistics
585
+ - `ssh_tunnel_close` - Close specific or all tunnels
586
+
587
+ ### Deployment & Security
588
+ - `ssh_deploy` - Smart deployment with permission handling
589
+ - `ssh_execute_sudo` - Execute commands with sudo privileges
590
+ - `ssh_alias` - Manage server aliases
591
+
592
+ ## 📚 Usage Examples
593
+
594
+ ### Backup & Restore
595
+
596
+ ```
597
+ "Backup production MySQL database before deployment"
598
+ "List all backups on production server"
599
+ "Restore backup from yesterday"
600
+ "Schedule daily database backup at 2 AM"
601
+ "Backup website files excluding cache and logs"
602
+ ```
603
+
604
+ For detailed backup examples, see [examples/backup-workflow.js](examples/backup-workflow.js) and [docs/BACKUP_GUIDE.md](docs/BACKUP_GUIDE.md).
605
+
606
+ ### Using the Bash CLI
607
+
608
+ ```bash
609
+ # Basic server management
610
+ ssh-manager server list
611
+ ssh-manager server add
612
+ ssh-manager ssh prod1
613
+
614
+ # File synchronization
615
+ ssh-manager sync push prod1 ./app /var/www/
616
+ ssh-manager sync pull prod1 /var/log/app.log ./
617
+
618
+ # SSH tunnels
619
+ ssh-manager tunnel create prod1 local 3307:localhost:3306
620
+ ssh-manager tunnel list
621
+
622
+ # Execute commands
623
+ ssh-manager exec prod1 "docker ps"
624
+ ```
625
+
626
+ ### Using in Claude Code or OpenAI Codex
627
+
628
+ Once installed, simply ask your AI assistant:
629
+
630
+ **Claude Code examples:**
631
+ - "List my SSH servers"
632
+ - "Execute 'df -h' on production server"
633
+ - "Upload this file to staging:/var/www/"
634
+ - "Create an SSH tunnel to access remote MySQL"
635
+ - "Monitor CPU usage on all servers"
636
+ - "Start a persistent session on prod1"
637
+
638
+ **OpenAI Codex examples:**
639
+ - "Show my SSH servers"
640
+ - "Run df -h on production"
641
+ - "Upload file.txt to staging:/tmp/"
642
+ - "Check CPU usage on all servers"
643
+
644
+ Both AI assistants support the same MCP tools! 🚀
645
+
646
+ ---
647
+
648
+ ## 🤝 Contributing
649
+
650
+ We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.
651
+
652
+ ### Development Setup
653
+
654
+ 1. Fork the repository
655
+ 2. Clone and install dependencies
656
+ 3. **Setup pre-commit hooks** for code quality:
657
+ ```bash
658
+ ./scripts/setup-hooks.sh
659
+ ```
660
+ 4. Create your feature branch
661
+ 5. Make your changes (hooks will validate on commit)
662
+ 6. Push to your branch
663
+ 7. Open a Pull Request
664
+
665
+ ### Code Quality
666
+
667
+ This project uses automated quality checks:
668
+ - **ESLint** for JavaScript linting
669
+ - **Black** for Python formatting
670
+ - **Flake8** for Python linting
671
+ - **Prettier** for code formatting
672
+ - **Pre-commit hooks** for automated validation
673
+ - **Secret detection** to prevent credential leaks
674
+
675
+ Run validation manually: `./scripts/validate.sh`
676
+
677
+ ## 📄 License
678
+
679
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
680
+
681
+ ## 🙏 Acknowledgments
682
+
683
+ - Built for [Claude Code](https://claude.ai/code)
684
+ - Uses the [Model Context Protocol](https://modelcontextprotocol.io)
685
+ - SSH handling via [node-ssh](https://www.npmjs.com/package/node-ssh)
686
+ - Server management with [Paramiko](https://www.paramiko.org)
687
+
688
+ ## 📧 Support
689
+
690
+ For issues, questions, or suggestions:
691
+ - Open an issue on [GitHub Issues](https://github.com/yourusername/mcp-ssh-manager/issues)
692
+ - Check existing issues before creating new ones
693
+
694
+ ---
695
+
696
+ Made with ❤️ for the Claude Code community
697
+
698
+ ## Known Limitations
699
+
700
+ ### Command Timeout
701
+ - The timeout parameter for SSH commands is advisory only
702
+ - Due to SSH2 library limitations, commands may continue running on the server even after timeout
703
+ - For critical timeout needs, use the system's `timeout` command directly in your command
704
+
705
+ ### SSH Sync (rsync)
706
+ - Password authentication requires `sshpass` to be installed
707
+ - SSH key authentication is recommended for better security and reliability
708
+ - Large file transfers may take time and appear to hang - be patient
709
+
710
+ ### Connection Management
711
+ - Connections are pooled and reused for performance
712
+ - If a connection becomes stale, it will be automatically reconnected on next use
713
+ - Force reconnection by using the `ssh_connection_status` tool with `reconnect` action
714
+
715
+ ## Support
716
+
717
+ For issues, feature requests, or contributions, please visit:
718
+ https://github.com/bvisible/mcp-ssh-manager