mcp-ssh-server-tool 2.0.0 → 2.0.1

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 (3) hide show
  1. package/index.js +40 -34
  2. package/package.json +4 -2
  3. package/ssh_manager.js +1 -1
package/index.js CHANGED
@@ -5,75 +5,78 @@ const sshManager = new SSHConnectionManager();
5
5
  const tools = [
6
6
  {
7
7
  name: 'ssh_connect',
8
- description: 'Establish an SSH connection. Returns session_id for subsequent commands.',
8
+ description: '建立 SSH 连接(仅在需要连续执行多个命令时使用,单次执行请使用 ssh_exec)',
9
9
  inputSchema: {
10
10
  type: 'object',
11
11
  properties: {
12
- host: { type: 'string', description: 'Server hostname or IP' },
13
- port: { type: 'number', description: 'SSH port (default: 22)', default: 22 },
14
- username: { type: 'string', description: 'SSH username' },
15
- password: { type: 'string', description: 'Password (for password auth)' },
16
- auth_type: { type: 'string', enum: ['password', 'public_key'], description: 'Auth type' },
17
- private_key_path: { type: 'string', description: 'Path to private key' },
18
- passphrase: { type: 'string', description: 'Passphrase for private key' },
19
- timeout: { type: 'number', description: 'Timeout in seconds (default: 10)', default: 10 },
12
+ host: { type: 'string', description: '服务器地址或 IP' },
13
+ port: { type: 'number', description: 'SSH 端口(默认: 22', default: 22 },
14
+ username: { type: 'string', description: 'SSH 用户名' },
15
+ password: { type: 'string', description: '密码(密码认证时必填)' },
16
+ auth_type: { type: 'string', enum: ['password', 'public_key'], description: '认证方式' },
17
+ private_key_path: { type: 'string', description: '私钥路径(公钥认证时使用,二选一)' },
18
+ private_key_content: { type: 'string', description: '私钥文本内容(公钥认证时使用,二选一)' },
19
+ passphrase: { type: 'string', description: '私钥密码(可选)' },
20
+ timeout: { type: 'number', description: '超时时间(秒,默认: 10)', default: 10 },
20
21
  },
21
22
  required: ['host', 'username'],
22
23
  },
23
24
  },
24
25
  {
25
26
  name: 'ssh_exec',
26
- description: 'Execute command(s) on SSH server. Supports direct mode (host/username) or session mode (session_id).',
27
+ description: '【推荐】执行 SSH 命令。单次执行直接传入 host/username/password 会自动连接、执行、断开。多次连续执行时才需要先用 ssh_connect 获取 session_id',
27
28
  inputSchema: {
28
29
  type: 'object',
29
30
  properties: {
30
- host: { type: 'string', description: 'Server hostname (use for direct execution)' },
31
- port: { type: 'number', description: 'SSH port', default: 22 },
32
- username: { type: 'string', description: 'SSH username' },
33
- password: { type: 'string', description: 'Password' },
34
- auth_type: { type: 'string', enum: ['password', 'public_key'], description: 'Auth type' },
35
- private_key_path: { type: 'string', description: 'Path to private key' },
36
- passphrase: { type: 'string', description: 'Passphrase for private key' },
37
- timeout: { type: 'number', description: 'Timeout in seconds', default: 10 },
38
- session_id: { type: 'string', description: 'Session ID from ssh_connect (use for session mode)' },
39
- command: { type: 'string', description: 'Command to execute' },
40
- commands: { type: 'array', items: { type: 'string' }, description: 'Multiple commands to execute sequentially' },
31
+ host: { type: 'string', description: '服务器地址(单次执行时必填)' },
32
+ port: { type: 'number', description: 'SSH 端口(默认: 22)', default: 22 },
33
+ username: { type: 'string', description: 'SSH 用户名(单次执行时必填)' },
34
+ password: { type: 'string', description: '密码(单次执行时必填)' },
35
+ auth_type: { type: 'string', enum: ['password', 'public_key'], description: '认证方式(默认: password)', default: 'password' },
36
+ private_key_path: { type: 'string', description: '私钥路径(公钥认证时使用,二选一)' },
37
+ private_key_content: { type: 'string', description: '私钥文本内容(公钥认证时使用,二选一)' },
38
+ passphrase: { type: 'string', description: '私钥密码' },
39
+ timeout: { type: 'number', description: '超时时间(秒)', default: 10 },
40
+ session_id: { type: 'string', description: '会话 ID(连续执行多命令时使用,先调用 ssh_connect 获取)' },
41
+ command: { type: 'string', description: '要执行的命令(单个命令)' },
42
+ commands: { type: 'array', items: { type: 'string' }, description: '要执行的命令列表(多个命令按顺序执行)' },
41
43
  },
42
44
  },
43
45
  },
44
46
  {
45
47
  name: 'ssh_disconnect',
46
- description: 'Close an SSH session',
48
+ description: '关闭 SSH 会话(使用 ssh_connect 后需要手动断开)',
47
49
  inputSchema: {
48
50
  type: 'object',
49
51
  properties: {
50
- session_id: { type: 'string', description: 'Session ID to disconnect' },
52
+ session_id: { type: 'string', description: '要断开的会话 ID'},
51
53
  },
52
54
  required: ['session_id'],
53
55
  },
54
56
  },
55
57
  {
56
58
  name: 'ssh_test',
57
- description: 'Quick connection test. Connects, executes a test command, and disconnects.',
59
+ description: '快速测试 SSH 连接。连接成功后执行测试命令,然后自动断开。',
58
60
  inputSchema: {
59
61
  type: 'object',
60
62
  properties: {
61
- host: { type: 'string', description: 'Server hostname' },
62
- port: { type: 'number', description: 'SSH port', default: 22 },
63
- username: { type: 'string', description: 'SSH username' },
64
- password: { type: 'string', description: 'Password' },
65
- auth_type: { type: 'string', enum: ['password', 'public_key'], description: 'Auth type' },
66
- private_key_path: { type: 'string', description: 'Path to private key' },
67
- passphrase: { type: 'string', description: 'Passphrase' },
68
- timeout: { type: 'number', description: 'Timeout in seconds', default: 10 },
69
- test_command: { type: 'string', description: 'Test command (default: echo test)', default: 'echo test' },
63
+ host: { type: 'string', description: '服务器地址' },
64
+ port: { type: 'number', description: 'SSH 端口', default: 22 },
65
+ username: { type: 'string', description: 'SSH 用户名' },
66
+ password: { type: 'string', description: '密码' },
67
+ auth_type: { type: 'string', enum: ['password', 'public_key'], description: '认证方式' },
68
+ private_key_path: { type: 'string', description: '私钥路径(公钥认证时使用,二选一)' },
69
+ private_key_content: { type: 'string', description: '私钥文本内容(公钥认证时使用,二选一)' },
70
+ passphrase: { type: 'string', description: '私钥密码' },
71
+ timeout: { type: 'number', description: '超时时间(秒)', default: 10 },
72
+ test_command: { type: 'string', description: '测试命令(默认: echo test)', default: 'echo test' },
70
73
  },
71
74
  required: ['host', 'username'],
72
75
  },
73
76
  },
74
77
  {
75
78
  name: 'ssh_list_sessions',
76
- description: 'List active SSH sessions',
79
+ description: '列出当前活跃的 SSH 会话',
77
80
  inputSchema: { type: 'object', properties: {} },
78
81
  },
79
82
  ];
@@ -127,6 +130,7 @@ async function handleRequest(request) {
127
130
  username: toolArgs.username,
128
131
  password: toolArgs.password,
129
132
  privateKeyPath: toolArgs.private_key_path,
133
+ privateKeyContent: toolArgs.private_key_content,
130
134
  passphrase: toolArgs.passphrase,
131
135
  timeout: toolArgs.timeout,
132
136
  });
@@ -150,6 +154,7 @@ async function handleRequest(request) {
150
154
  username: toolArgs.username,
151
155
  password: toolArgs.password,
152
156
  privateKeyPath: toolArgs.private_key_path,
157
+ privateKeyContent: toolArgs.private_key_content,
153
158
  passphrase: toolArgs.passphrase,
154
159
  timeout: toolArgs.timeout,
155
160
  });
@@ -196,6 +201,7 @@ async function handleRequest(request) {
196
201
  username: toolArgs.username,
197
202
  password: toolArgs.password,
198
203
  privateKeyPath: toolArgs.private_key_path,
204
+ privateKeyContent: toolArgs.private_key_content,
199
205
  passphrase: toolArgs.passphrase,
200
206
  timeout: toolArgs.timeout,
201
207
  });
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "mcp-ssh-server-tool",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "MCP Server for SSH connections and remote command execution",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
- "bin": "bin/cli.js",
7
+ "bin": {
8
+ "mcp-ssh-server-tool": "bin/cli.js"
9
+ },
8
10
  "scripts": {
9
11
  "start": "node index.js"
10
12
  },
package/ssh_manager.js CHANGED
@@ -26,7 +26,7 @@ class SSHConnectionManager {
26
26
  port: options.port || 22,
27
27
  username: options.username,
28
28
  password: options.password,
29
- privateKey: options.privateKeyPath ? this._readPrivateKey(options.privateKeyPath) : undefined,
29
+ privateKey: options.privateKeyContent || (options.privateKeyPath ? this._readPrivateKey(options.privateKeyPath) : undefined),
30
30
  passphrase: options.passphrase,
31
31
  readyTimeout: (options.timeout || 10) * 1000,
32
32
  keepaliveInterval: 0,