mcp-ssh-server-tool 1.0.4 → 1.0.6
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/index.js +107 -11
- package/package.json +3 -6
package/index.js
CHANGED
|
@@ -248,20 +248,51 @@ const tools = [
|
|
|
248
248
|
},
|
|
249
249
|
{
|
|
250
250
|
name: 'ssh_exec',
|
|
251
|
-
description: 'Execute a command on an active
|
|
251
|
+
description: 'Execute a command on an SSH session. Use session_id if you have an active session, or provide host/username/password to connect directly.',
|
|
252
252
|
inputSchema: {
|
|
253
253
|
type: 'object',
|
|
254
254
|
properties: {
|
|
255
255
|
session_id: {
|
|
256
256
|
type: 'string',
|
|
257
|
-
description: 'The SSH session ID from ssh_connect',
|
|
257
|
+
description: 'The SSH session ID from ssh_connect (optional if providing host/username/password)',
|
|
258
258
|
},
|
|
259
259
|
command: {
|
|
260
260
|
type: 'string',
|
|
261
261
|
description: 'The command to execute',
|
|
262
262
|
},
|
|
263
|
+
host: {
|
|
264
|
+
type: 'string',
|
|
265
|
+
description: 'Server hostname (optional, used if session_id not provided)',
|
|
266
|
+
},
|
|
267
|
+
port: {
|
|
268
|
+
type: 'number',
|
|
269
|
+
description: 'SSH port (default: 22)',
|
|
270
|
+
default: 22,
|
|
271
|
+
},
|
|
272
|
+
username: {
|
|
273
|
+
type: 'string',
|
|
274
|
+
description: 'SSH username (optional)',
|
|
275
|
+
},
|
|
276
|
+
password: {
|
|
277
|
+
type: 'string',
|
|
278
|
+
description: 'SSH password (optional)',
|
|
279
|
+
},
|
|
280
|
+
auth_type: {
|
|
281
|
+
type: 'string',
|
|
282
|
+
enum: ['password', 'public_key'],
|
|
283
|
+
description: 'Authentication type (default: password)',
|
|
284
|
+
default: 'password',
|
|
285
|
+
},
|
|
286
|
+
private_key_path: {
|
|
287
|
+
type: 'string',
|
|
288
|
+
description: 'Private key path (for public_key auth)',
|
|
289
|
+
},
|
|
290
|
+
passphrase: {
|
|
291
|
+
type: 'string',
|
|
292
|
+
description: 'Passphrase for private key',
|
|
293
|
+
},
|
|
263
294
|
},
|
|
264
|
-
required: ['
|
|
295
|
+
required: ['command'],
|
|
265
296
|
},
|
|
266
297
|
},
|
|
267
298
|
{
|
|
@@ -394,9 +425,38 @@ function handleRequest(request) {
|
|
|
394
425
|
}
|
|
395
426
|
|
|
396
427
|
if (name === 'ssh_exec') {
|
|
397
|
-
|
|
398
|
-
if (
|
|
399
|
-
execResult.
|
|
428
|
+
// 如果有 session_id,使用现有会话
|
|
429
|
+
if (toolArgs.session_id) {
|
|
430
|
+
const execResult = sshManager.execCommand(toolArgs.session_id, toolArgs.command);
|
|
431
|
+
if (execResult && typeof execResult.then === 'function') {
|
|
432
|
+
execResult.then((result) => {
|
|
433
|
+
send({
|
|
434
|
+
jsonrpc: '2.0',
|
|
435
|
+
id,
|
|
436
|
+
result: {
|
|
437
|
+
content: [
|
|
438
|
+
{
|
|
439
|
+
type: 'text',
|
|
440
|
+
text: JSON.stringify(result),
|
|
441
|
+
},
|
|
442
|
+
],
|
|
443
|
+
},
|
|
444
|
+
});
|
|
445
|
+
}).catch((err) => {
|
|
446
|
+
send({
|
|
447
|
+
jsonrpc: '2.0',
|
|
448
|
+
id,
|
|
449
|
+
result: {
|
|
450
|
+
content: [
|
|
451
|
+
{
|
|
452
|
+
type: 'text',
|
|
453
|
+
text: JSON.stringify({ success: false, error: err.message }),
|
|
454
|
+
},
|
|
455
|
+
],
|
|
456
|
+
},
|
|
457
|
+
});
|
|
458
|
+
});
|
|
459
|
+
} else {
|
|
400
460
|
send({
|
|
401
461
|
jsonrpc: '2.0',
|
|
402
462
|
id,
|
|
@@ -404,12 +464,29 @@ function handleRequest(request) {
|
|
|
404
464
|
content: [
|
|
405
465
|
{
|
|
406
466
|
type: 'text',
|
|
407
|
-
text: JSON.stringify(
|
|
467
|
+
text: JSON.stringify(execResult),
|
|
408
468
|
},
|
|
409
469
|
],
|
|
410
470
|
},
|
|
411
471
|
});
|
|
412
|
-
}
|
|
472
|
+
}
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// 如果没有 session_id,但提供了认证参数,直接连接、执行、断开
|
|
477
|
+
if (toolArgs.host && toolArgs.username) {
|
|
478
|
+
const connResult = await sshManager.connect({
|
|
479
|
+
host: toolArgs.host,
|
|
480
|
+
port: toolArgs.port,
|
|
481
|
+
username: toolArgs.username,
|
|
482
|
+
authType: toolArgs.auth_type || 'password',
|
|
483
|
+
password: toolArgs.password,
|
|
484
|
+
privateKeyPath: toolArgs.private_key_path,
|
|
485
|
+
passphrase: toolArgs.passphrase,
|
|
486
|
+
timeout: toolArgs.timeout,
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
if (!connResult.success) {
|
|
413
490
|
send({
|
|
414
491
|
jsonrpc: '2.0',
|
|
415
492
|
id,
|
|
@@ -417,13 +494,17 @@ function handleRequest(request) {
|
|
|
417
494
|
content: [
|
|
418
495
|
{
|
|
419
496
|
type: 'text',
|
|
420
|
-
text: JSON.stringify(
|
|
497
|
+
text: JSON.stringify(connResult),
|
|
421
498
|
},
|
|
422
499
|
],
|
|
423
500
|
},
|
|
424
501
|
});
|
|
425
|
-
|
|
426
|
-
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
const execResult = await sshManager.execCommand(connResult.sessionId, toolArgs.command);
|
|
506
|
+
sshManager.disconnect(connResult.sessionId);
|
|
507
|
+
|
|
427
508
|
send({
|
|
428
509
|
jsonrpc: '2.0',
|
|
429
510
|
id,
|
|
@@ -436,7 +517,22 @@ function handleRequest(request) {
|
|
|
436
517
|
],
|
|
437
518
|
},
|
|
438
519
|
});
|
|
520
|
+
return;
|
|
439
521
|
}
|
|
522
|
+
|
|
523
|
+
// 既没有 session_id 也没有认证参数
|
|
524
|
+
send({
|
|
525
|
+
jsonrpc: '2.0',
|
|
526
|
+
id,
|
|
527
|
+
result: {
|
|
528
|
+
content: [
|
|
529
|
+
{
|
|
530
|
+
type: 'text',
|
|
531
|
+
text: JSON.stringify({ success: false, error: 'Either session_id or host/username is required' }),
|
|
532
|
+
},
|
|
533
|
+
],
|
|
534
|
+
},
|
|
535
|
+
});
|
|
440
536
|
return;
|
|
441
537
|
}
|
|
442
538
|
|
package/package.json
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-ssh-server-tool",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "MCP Server for SSH connections and remote command execution",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"bin":
|
|
8
|
-
"mcp-ssh-server-tool": "./bin/cli.js"
|
|
9
|
-
},
|
|
7
|
+
"bin": "bin/cli.js",
|
|
10
8
|
"scripts": {
|
|
11
|
-
"start": "node index.js"
|
|
12
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
|
+
"start": "node index.js"
|
|
13
10
|
},
|
|
14
11
|
"keywords": ["mcp", "ssh", "server", "mcp-server", "remote-execution"],
|
|
15
12
|
"author": "",
|