mcp-ssh-manager 3.0.0 → 3.1.2
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.
- package/.claude/settings.local.json +10 -1
- package/CHANGELOG.md +63 -0
- package/CLAUDE.md +16 -0
- package/README.md +117 -4
- package/cli/commands/server.sh +27 -5
- package/cli/commands/tools.sh +603 -0
- package/cli/lib/config.sh +104 -14
- package/cli/lib/menu.sh +124 -0
- package/cli/ssh-manager +17 -7
- package/context-test.txt +1 -0
- package/docs/SOCIAL_MEDIA_ANNOUNCEMENT.md +385 -0
- package/docs/TOOL_MANAGEMENT.md +473 -0
- package/docs/TROUBLESHOOTING.md +143 -0
- package/package.json +5 -4
- package/scripts/validate.sh +12 -0
- package/src/backup-manager.js +12 -12
- package/src/command-aliases.js +16 -16
- package/src/config-loader.js +1 -1
- package/src/config.js +70 -0
- package/src/database-manager.js +38 -40
- package/src/deploy-helper.js +12 -13
- package/src/health-monitor.js +26 -26
- package/src/hooks-system.js +43 -43
- package/src/index.js +899 -841
- package/src/logger.js +53 -53
- package/src/profile-loader.js +14 -14
- package/src/server-aliases.js +11 -11
- package/src/server-groups.js +98 -97
- package/src/session-manager.js +59 -58
- package/src/ssh-key-manager.js +4 -3
- package/src/ssh-manager.js +46 -24
- package/src/tool-config-manager.js +434 -0
- package/src/tool-registry.js +196 -0
- package/src/tunnel-manager.js +98 -98
package/src/logger.js
CHANGED
|
@@ -40,20 +40,20 @@ class Logger {
|
|
|
40
40
|
// Set log level from environment variable
|
|
41
41
|
const envLevel = process.env.SSH_LOG_LEVEL?.toUpperCase() || 'INFO';
|
|
42
42
|
this.currentLevel = LOG_LEVELS[envLevel] ?? LOG_LEVELS.INFO;
|
|
43
|
-
|
|
43
|
+
|
|
44
44
|
// Enable verbose mode from environment
|
|
45
45
|
this.verbose = process.env.SSH_VERBOSE === 'true';
|
|
46
|
-
|
|
46
|
+
|
|
47
47
|
// Log file path
|
|
48
48
|
this.logFile = process.env.SSH_LOG_FILE || path.join(__dirname, '..', '.ssh-manager.log');
|
|
49
|
-
|
|
49
|
+
|
|
50
50
|
// Command history file
|
|
51
51
|
this.historyFile = path.join(__dirname, '..', '.ssh-command-history.json');
|
|
52
|
-
|
|
52
|
+
|
|
53
53
|
// Initialize command history
|
|
54
54
|
this.commandHistory = this.loadCommandHistory();
|
|
55
55
|
}
|
|
56
|
-
|
|
56
|
+
|
|
57
57
|
/**
|
|
58
58
|
* Load command history from file
|
|
59
59
|
*/
|
|
@@ -68,7 +68,7 @@ class Logger {
|
|
|
68
68
|
}
|
|
69
69
|
return [];
|
|
70
70
|
}
|
|
71
|
-
|
|
71
|
+
|
|
72
72
|
/**
|
|
73
73
|
* Save command to history
|
|
74
74
|
*/
|
|
@@ -81,46 +81,46 @@ class Logger {
|
|
|
81
81
|
duration: result.duration,
|
|
82
82
|
error: result.error
|
|
83
83
|
};
|
|
84
|
-
|
|
84
|
+
|
|
85
85
|
this.commandHistory.push(entry);
|
|
86
|
-
|
|
86
|
+
|
|
87
87
|
// Keep only last 1000 commands
|
|
88
88
|
if (this.commandHistory.length > 1000) {
|
|
89
89
|
this.commandHistory = this.commandHistory.slice(-1000);
|
|
90
90
|
}
|
|
91
|
-
|
|
91
|
+
|
|
92
92
|
try {
|
|
93
93
|
fs.writeFileSync(this.historyFile, JSON.stringify(this.commandHistory, null, 2));
|
|
94
94
|
} catch (error) {
|
|
95
95
|
// Ignore write errors
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
-
|
|
98
|
+
|
|
99
99
|
/**
|
|
100
100
|
* Format log message with timestamp and level
|
|
101
101
|
*/
|
|
102
102
|
formatMessage(level, message, data = {}) {
|
|
103
103
|
const timestamp = new Date().toISOString();
|
|
104
104
|
const levelName = Object.keys(LOG_LEVELS).find(key => LOG_LEVELS[key] === level) || 'INFO';
|
|
105
|
-
|
|
105
|
+
|
|
106
106
|
// Console format with colors
|
|
107
107
|
const consoleFormat = `${COLORS[levelName]}${ICONS[levelName]} [${timestamp}] [${levelName}]${COLORS.RESET} ${message}`;
|
|
108
|
-
|
|
108
|
+
|
|
109
109
|
// File format without colors
|
|
110
110
|
const fileFormat = `[${timestamp}] [${levelName}] ${message}`;
|
|
111
|
-
|
|
111
|
+
|
|
112
112
|
// Add data if present
|
|
113
113
|
let dataStr = '';
|
|
114
114
|
if (Object.keys(data).length > 0) {
|
|
115
115
|
dataStr = '\n ' + JSON.stringify(data, null, 2).replace(/\n/g, '\n ');
|
|
116
116
|
}
|
|
117
|
-
|
|
117
|
+
|
|
118
118
|
return {
|
|
119
119
|
console: consoleFormat + (this.verbose && dataStr ? dataStr : ''),
|
|
120
120
|
file: fileFormat + dataStr
|
|
121
121
|
};
|
|
122
122
|
}
|
|
123
|
-
|
|
123
|
+
|
|
124
124
|
/**
|
|
125
125
|
* Main log function
|
|
126
126
|
*/
|
|
@@ -129,12 +129,12 @@ class Logger {
|
|
|
129
129
|
if (level < this.currentLevel) {
|
|
130
130
|
return;
|
|
131
131
|
}
|
|
132
|
-
|
|
132
|
+
|
|
133
133
|
const formatted = this.formatMessage(level, message, data);
|
|
134
|
-
|
|
134
|
+
|
|
135
135
|
// Output to stderr for proper MCP logging
|
|
136
136
|
console.error(formatted.console);
|
|
137
|
-
|
|
137
|
+
|
|
138
138
|
// Also write to file
|
|
139
139
|
try {
|
|
140
140
|
fs.appendFileSync(this.logFile, formatted.file + '\n');
|
|
@@ -142,24 +142,24 @@ class Logger {
|
|
|
142
142
|
// Ignore file write errors
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
|
-
|
|
145
|
+
|
|
146
146
|
// Convenience methods
|
|
147
147
|
debug(message, data) {
|
|
148
148
|
this.log(LOG_LEVELS.DEBUG, message, data);
|
|
149
149
|
}
|
|
150
|
-
|
|
150
|
+
|
|
151
151
|
info(message, data) {
|
|
152
152
|
this.log(LOG_LEVELS.INFO, message, data);
|
|
153
153
|
}
|
|
154
|
-
|
|
154
|
+
|
|
155
155
|
warn(message, data) {
|
|
156
156
|
this.log(LOG_LEVELS.WARN, message, data);
|
|
157
157
|
}
|
|
158
|
-
|
|
158
|
+
|
|
159
159
|
error(message, data) {
|
|
160
160
|
this.log(LOG_LEVELS.ERROR, message, data);
|
|
161
161
|
}
|
|
162
|
-
|
|
162
|
+
|
|
163
163
|
/**
|
|
164
164
|
* Log SSH command execution
|
|
165
165
|
*/
|
|
@@ -169,90 +169,90 @@ class Logger {
|
|
|
169
169
|
command: this.verbose ? command : command.substring(0, 100) + (command.length > 100 ? '...' : ''),
|
|
170
170
|
cwd
|
|
171
171
|
};
|
|
172
|
-
|
|
172
|
+
|
|
173
173
|
if (this.verbose) {
|
|
174
|
-
this.debug(
|
|
174
|
+
this.debug('Executing SSH command', logData);
|
|
175
175
|
} else {
|
|
176
176
|
this.info(`SSH execute on ${server}`, { command: logData.command });
|
|
177
177
|
}
|
|
178
|
-
|
|
178
|
+
|
|
179
179
|
return Date.now(); // Return start time for duration calculation
|
|
180
180
|
}
|
|
181
|
-
|
|
181
|
+
|
|
182
182
|
/**
|
|
183
183
|
* Log SSH command result
|
|
184
184
|
*/
|
|
185
185
|
logCommandResult(server, command, startTime, result) {
|
|
186
186
|
const duration = Date.now() - startTime;
|
|
187
|
-
|
|
187
|
+
|
|
188
188
|
const resultData = {
|
|
189
189
|
success: !result.code,
|
|
190
190
|
duration: `${duration}ms`,
|
|
191
191
|
error: result.code ? result.stderr : undefined
|
|
192
192
|
};
|
|
193
|
-
|
|
193
|
+
|
|
194
194
|
// Save to history
|
|
195
195
|
this.saveCommandToHistory(command, server, resultData);
|
|
196
|
-
|
|
196
|
+
|
|
197
197
|
if (result.code) {
|
|
198
198
|
this.error(`Command failed on ${server}`, resultData);
|
|
199
199
|
} else if (this.verbose) {
|
|
200
200
|
this.debug(`Command completed on ${server}`, resultData);
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
|
-
|
|
203
|
+
|
|
204
204
|
/**
|
|
205
205
|
* Log SSH connection events
|
|
206
206
|
*/
|
|
207
207
|
logConnection(server, event, data = {}) {
|
|
208
208
|
const message = `SSH connection ${event}: ${server}`;
|
|
209
|
-
|
|
209
|
+
|
|
210
210
|
switch (event) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
211
|
+
case 'established':
|
|
212
|
+
this.info(message, data);
|
|
213
|
+
break;
|
|
214
|
+
case 'reused':
|
|
215
|
+
this.debug(message, data);
|
|
216
|
+
break;
|
|
217
|
+
case 'closed':
|
|
218
|
+
this.info(message, data);
|
|
219
|
+
break;
|
|
220
|
+
case 'failed':
|
|
221
|
+
this.error(message, data);
|
|
222
|
+
break;
|
|
223
|
+
default:
|
|
224
|
+
this.debug(message, data);
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
|
-
|
|
227
|
+
|
|
228
228
|
/**
|
|
229
229
|
* Log file transfer operations
|
|
230
230
|
*/
|
|
231
231
|
logTransfer(operation, server, source, destination, result = null) {
|
|
232
232
|
const data = { server, source, destination };
|
|
233
|
-
|
|
233
|
+
|
|
234
234
|
if (result) {
|
|
235
235
|
data.success = result.success;
|
|
236
236
|
data.size = result.size;
|
|
237
237
|
data.duration = result.duration;
|
|
238
238
|
}
|
|
239
|
-
|
|
239
|
+
|
|
240
240
|
const message = `File ${operation} ${result ? (result.success ? 'completed' : 'failed') : 'started'}`;
|
|
241
|
-
|
|
241
|
+
|
|
242
242
|
if (result && !result.success) {
|
|
243
243
|
this.error(message, data);
|
|
244
244
|
} else {
|
|
245
245
|
this.info(message, data);
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
|
-
|
|
248
|
+
|
|
249
249
|
/**
|
|
250
250
|
* Get command history
|
|
251
251
|
*/
|
|
252
252
|
getHistory(limit = 100) {
|
|
253
253
|
return this.commandHistory.slice(-limit);
|
|
254
254
|
}
|
|
255
|
-
|
|
255
|
+
|
|
256
256
|
/**
|
|
257
257
|
* Clear logs and history
|
|
258
258
|
*/
|
|
@@ -273,4 +273,4 @@ export const logger = new Logger();
|
|
|
273
273
|
|
|
274
274
|
// Export for convenience
|
|
275
275
|
export const { debug, info, warn, error } = logger;
|
|
276
|
-
export default logger;
|
|
276
|
+
export default logger;
|
package/src/profile-loader.js
CHANGED
|
@@ -21,7 +21,7 @@ export function getActiveProfileName() {
|
|
|
21
21
|
if (process.env.SSH_MANAGER_PROFILE) {
|
|
22
22
|
return process.env.SSH_MANAGER_PROFILE;
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
// 2. Check configuration file
|
|
26
26
|
if (fs.existsSync(PROFILE_CONFIG_FILE)) {
|
|
27
27
|
try {
|
|
@@ -33,7 +33,7 @@ export function getActiveProfileName() {
|
|
|
33
33
|
console.error(`Error reading profile config: ${error.message}`);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
// 3. Default to 'default' profile
|
|
38
38
|
return 'default';
|
|
39
39
|
}
|
|
@@ -44,12 +44,12 @@ export function getActiveProfileName() {
|
|
|
44
44
|
export function loadProfile(profileName = null) {
|
|
45
45
|
const name = profileName || getActiveProfileName();
|
|
46
46
|
const profilePath = path.join(PROFILES_DIR, `${name}.json`);
|
|
47
|
-
|
|
47
|
+
|
|
48
48
|
try {
|
|
49
49
|
if (fs.existsSync(profilePath)) {
|
|
50
50
|
const profileData = fs.readFileSync(profilePath, 'utf8');
|
|
51
51
|
const profile = JSON.parse(profileData);
|
|
52
|
-
|
|
52
|
+
|
|
53
53
|
console.error(`📦 Loaded profile: ${profile.name} - ${profile.description}`);
|
|
54
54
|
return profile;
|
|
55
55
|
} else {
|
|
@@ -67,7 +67,7 @@ export function loadProfile(profileName = null) {
|
|
|
67
67
|
*/
|
|
68
68
|
function loadDefaultProfile() {
|
|
69
69
|
const defaultPath = path.join(PROFILES_DIR, 'default.json');
|
|
70
|
-
|
|
70
|
+
|
|
71
71
|
try {
|
|
72
72
|
if (fs.existsSync(defaultPath)) {
|
|
73
73
|
const profileData = fs.readFileSync(defaultPath, 'utf8');
|
|
@@ -76,7 +76,7 @@ function loadDefaultProfile() {
|
|
|
76
76
|
} catch (error) {
|
|
77
77
|
console.error(`Error loading default profile: ${error.message}`);
|
|
78
78
|
}
|
|
79
|
-
|
|
79
|
+
|
|
80
80
|
// Return minimal profile if default doesn't exist
|
|
81
81
|
return {
|
|
82
82
|
name: 'minimal',
|
|
@@ -93,7 +93,7 @@ export function listProfiles() {
|
|
|
93
93
|
try {
|
|
94
94
|
const files = fs.readdirSync(PROFILES_DIR);
|
|
95
95
|
const profiles = [];
|
|
96
|
-
|
|
96
|
+
|
|
97
97
|
for (const file of files) {
|
|
98
98
|
if (file.endsWith('.json')) {
|
|
99
99
|
const profilePath = path.join(PROFILES_DIR, file);
|
|
@@ -112,7 +112,7 @@ export function listProfiles() {
|
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
|
-
|
|
115
|
+
|
|
116
116
|
return profiles;
|
|
117
117
|
} catch (error) {
|
|
118
118
|
console.error(`Error listing profiles: ${error.message}`);
|
|
@@ -130,7 +130,7 @@ export function setActiveProfile(profileName) {
|
|
|
130
130
|
if (!fs.existsSync(profilePath)) {
|
|
131
131
|
throw new Error(`Profile '${profileName}' does not exist`);
|
|
132
132
|
}
|
|
133
|
-
|
|
133
|
+
|
|
134
134
|
// Write to config file
|
|
135
135
|
fs.writeFileSync(PROFILE_CONFIG_FILE, profileName);
|
|
136
136
|
return true;
|
|
@@ -146,19 +146,19 @@ export function setActiveProfile(profileName) {
|
|
|
146
146
|
export function createProfile(name, config) {
|
|
147
147
|
try {
|
|
148
148
|
const profilePath = path.join(PROFILES_DIR, `${name}.json`);
|
|
149
|
-
|
|
149
|
+
|
|
150
150
|
// Check if profile already exists
|
|
151
151
|
if (fs.existsSync(profilePath)) {
|
|
152
152
|
throw new Error(`Profile '${name}' already exists`);
|
|
153
153
|
}
|
|
154
|
-
|
|
154
|
+
|
|
155
155
|
const profile = {
|
|
156
156
|
name: name,
|
|
157
157
|
description: config.description || `Custom profile: ${name}`,
|
|
158
158
|
commandAliases: config.commandAliases || {},
|
|
159
159
|
hooks: config.hooks || {}
|
|
160
160
|
};
|
|
161
|
-
|
|
161
|
+
|
|
162
162
|
fs.writeFileSync(profilePath, JSON.stringify(profile, null, 2));
|
|
163
163
|
return true;
|
|
164
164
|
} catch (error) {
|
|
@@ -172,7 +172,7 @@ export function createProfile(name, config) {
|
|
|
172
172
|
*/
|
|
173
173
|
export function mergeProfiles(baseProfileName, extensions) {
|
|
174
174
|
const baseProfile = loadProfile(baseProfileName);
|
|
175
|
-
|
|
175
|
+
|
|
176
176
|
return {
|
|
177
177
|
...baseProfile,
|
|
178
178
|
commandAliases: {
|
|
@@ -184,4 +184,4 @@ export function mergeProfiles(baseProfileName, extensions) {
|
|
|
184
184
|
...extensions.hooks
|
|
185
185
|
}
|
|
186
186
|
};
|
|
187
|
-
}
|
|
187
|
+
}
|
package/src/server-aliases.js
CHANGED
|
@@ -45,22 +45,22 @@ export function saveAliases(aliases) {
|
|
|
45
45
|
*/
|
|
46
46
|
export function resolveServerName(nameOrAlias, servers) {
|
|
47
47
|
const aliases = loadAliases();
|
|
48
|
-
|
|
48
|
+
|
|
49
49
|
// Check if it's an alias
|
|
50
50
|
if (aliases[nameOrAlias]) {
|
|
51
51
|
return aliases[nameOrAlias];
|
|
52
52
|
}
|
|
53
|
-
|
|
53
|
+
|
|
54
54
|
// Check if it's a direct server name
|
|
55
55
|
const normalizedName = nameOrAlias.toLowerCase();
|
|
56
56
|
if (servers[normalizedName]) {
|
|
57
57
|
return normalizedName;
|
|
58
58
|
}
|
|
59
|
-
|
|
59
|
+
|
|
60
60
|
// Try to find partial match
|
|
61
61
|
const serverNames = Object.keys(servers);
|
|
62
62
|
const matches = serverNames.filter(name => name.includes(normalizedName));
|
|
63
|
-
|
|
63
|
+
|
|
64
64
|
if (matches.length === 1) {
|
|
65
65
|
return matches[0];
|
|
66
66
|
} else if (matches.length > 1) {
|
|
@@ -68,7 +68,7 @@ export function resolveServerName(nameOrAlias, servers) {
|
|
|
68
68
|
`Ambiguous server name "${nameOrAlias}". Matches: ${matches.join(', ')}`
|
|
69
69
|
);
|
|
70
70
|
}
|
|
71
|
-
|
|
71
|
+
|
|
72
72
|
// Check if nameOrAlias contains a domain that matches a server
|
|
73
73
|
if (nameOrAlias.includes('.')) {
|
|
74
74
|
const matchingServer = serverNames.find(name => {
|
|
@@ -79,12 +79,12 @@ export function resolveServerName(nameOrAlias, servers) {
|
|
|
79
79
|
nameOrAlias.includes(serverHost)
|
|
80
80
|
);
|
|
81
81
|
});
|
|
82
|
-
|
|
82
|
+
|
|
83
83
|
if (matchingServer) {
|
|
84
84
|
return matchingServer;
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
-
|
|
87
|
+
|
|
88
88
|
return null;
|
|
89
89
|
}
|
|
90
90
|
|
|
@@ -93,7 +93,7 @@ export function resolveServerName(nameOrAlias, servers) {
|
|
|
93
93
|
*/
|
|
94
94
|
export function createDefaultAliases(servers) {
|
|
95
95
|
const aliases = {};
|
|
96
|
-
|
|
96
|
+
|
|
97
97
|
Object.entries(servers).forEach(([name, config]) => {
|
|
98
98
|
// Create short aliases for common patterns
|
|
99
99
|
if (name.includes('production')) {
|
|
@@ -105,7 +105,7 @@ export function createDefaultAliases(servers) {
|
|
|
105
105
|
} else if (name.includes('testing')) {
|
|
106
106
|
aliases['test'] = name;
|
|
107
107
|
}
|
|
108
|
-
|
|
108
|
+
|
|
109
109
|
// Create aliases from hostname patterns
|
|
110
110
|
const host = config.host;
|
|
111
111
|
if (host) {
|
|
@@ -116,7 +116,7 @@ export function createDefaultAliases(servers) {
|
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
});
|
|
119
|
-
|
|
119
|
+
|
|
120
120
|
return aliases;
|
|
121
121
|
}
|
|
122
122
|
|
|
@@ -147,4 +147,4 @@ export function listAliases() {
|
|
|
147
147
|
alias,
|
|
148
148
|
target
|
|
149
149
|
}));
|
|
150
|
-
}
|
|
150
|
+
}
|