ssh-client-mcp-server 1.3.0 → 1.3.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.
- package/dist/index.js.map +1 -1
- package/package.json +11 -8
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["SSHClient"],"sources":["../src/config.ts","../src/index.ts"],"sourcesContent":["import { type Either, Left, List, Option, Right } from \"functype\"\nimport { Fs, Path, Platform } from \"functype-os\"\nimport { type ConnectConfig } from \"ssh2\"\n\nexport type ArgvConfig = Readonly<Record<string, string>>\n\nexport const parseArgv = (args: ReadonlyArray<string>): ArgvConfig =>\n List(args).fold<Record<string, string>>({}, (acc, arg) => {\n const match = arg.match(/^--([^=]+)=(.*)$/)\n return match ? { ...acc, [match[1]]: match[2] } : acc\n })\n\n// If --user is omitted, fall back to the OS-reported username (`whoami`-style).\nexport const effectiveUser = (argv: ArgvConfig): Option<string> =>\n Option(argv.user).or(Platform.userInfo().map((info) => info.username))\n\nexport const validateConfig = (config: ArgvConfig): Either<string, void> => {\n const errors = List.of(\n config.host ? Option.none<string>() : Option(\"Missing required --host\"),\n effectiveUser(config).fold(\n () => Option(\"Missing --user (and OS user unavailable)\"),\n (_) => Option.none<string>(),\n ),\n config.port && isNaN(Number(config.port)) ? Option(\"Invalid --port\") : Option.none<string>(),\n ).flatMap((o) => o.toList())\n\n return errors.isEmpty\n ? Right<string, void>(undefined)\n : Left<string, void>(`Configuration error:\\n${errors.toArray().join(\"\\n\")}`)\n}\n\nexport const resolveAuth = async (\n password: Option<string>,\n keyPath: Option<string>,\n): Promise<Either<string, Partial<ConnectConfig>>> => {\n if (password.isSome()) {\n return Right<string, Partial<ConnectConfig>>({ password: password.value })\n }\n if (keyPath.isSome()) {\n const expandResult = Path.expand(keyPath.value)\n if (expandResult.isLeft()) {\n return Left<string, Partial<ConnectConfig>>(\n `Invalid SSH key path ${keyPath.value}: ${expandResult.value.message}`,\n )\n }\n const expanded = expandResult.value\n const result = await Fs.readFile(expanded)\n return result.fold<Either<string, Partial<ConnectConfig>>>(\n (err) => Left<string, Partial<ConnectConfig>>(`Failed to read SSH key ${expanded}: ${err.message}`),\n (contents) => Right<string, Partial<ConnectConfig>>({ privateKey: contents }),\n )\n }\n return Right<string, Partial<ConnectConfig>>({})\n}\n","#!/usr/bin/env node\n\nimport { Option } from \"functype\"\nimport { createServer, UserError } from \"somamcp\"\nimport { Client as SSHClient, type ConnectConfig } from \"ssh2\"\nimport { z } from \"zod\"\n\nimport { effectiveUser, parseArgv, resolveAuth, validateConfig } from \"./config.js\"\n\n// Example: node dist/index.js --host=1.2.3.4 --port=22 --user=root --password=pass --key=~/.ssh/id_rsa\n\nconst execSshCommand = (sshConfig: ConnectConfig, command: string): Promise<string> =>\n new Promise((resolve, reject) => {\n const conn = new SSHClient()\n conn.on(\"ready\", () => {\n conn.exec(command, (err, stream) => {\n if (err) {\n reject(new UserError(`SSH exec error: ${err.message}`))\n conn.end()\n return\n }\n const stdoutChunks: Buffer[] = []\n const stderrChunks: Buffer[] = []\n stream.on(\"close\", (code: number) => {\n conn.end()\n const stdout = Buffer.concat(stdoutChunks).toString()\n const stderr = Buffer.concat(stderrChunks).toString()\n if (stderr) {\n reject(new UserError(`Error (code ${code}):\\n${stderr}`))\n } else {\n resolve(stdout)\n }\n })\n stream.on(\"data\", (data: Buffer) => {\n stdoutChunks.push(data)\n })\n stream.stderr.on(\"data\", (data: Buffer) => {\n stderrChunks.push(data)\n })\n })\n })\n conn.on(\"error\", (err) => {\n reject(new UserError(`SSH connection error: ${err.message}`))\n })\n conn.connect(sshConfig)\n })\n\nasync function main() {\n const argv = parseArgv(process.argv.slice(2))\n\n validateConfig(argv).fold(\n (err) => {\n console.error(err)\n process.exit(1)\n },\n () => undefined,\n )\n\n const { host } = argv\n const user = effectiveUser(argv).orThrow(new Error(\"user unavailable after validation\"))\n const port = Option(argv.port).map(Number).orElse(22)\n const password = Option(argv.password)\n const keyPath = Option(argv.key)\n\n const authResult = await resolveAuth(password, keyPath)\n const authConfig = authResult.fold<Partial<ConnectConfig>>(\n (err) => {\n console.error(err)\n process.exit(1)\n },\n (cfg) => cfg,\n )\n\n const sshConfig: ConnectConfig = { host, port, username: user, ...authConfig }\n\n const server = createServer({\n name: \"ssh-client-mcp-server\",\n version: \"1.2.0\",\n instructions: \"Execute shell commands on a remote host over SSH.\",\n })\n\n server.addTool({\n name: \"exec\",\n description: \"Execute a shell command on the remote SSH server and return the output.\",\n parameters: z.object({\n command: z.string().min(1).describe(\"Shell command to execute on the remote SSH server\"),\n }),\n execute: async ({ command }) => execSshCommand(sshConfig, command),\n })\n\n await server.start({ transportType: \"stdio\" })\n console.error(\"SSH MCP Server running on stdio\")\n\n const shutdown = async () => {\n await server.stop()\n process.exit(0)\n }\n process.on(\"SIGINT\", () => void shutdown())\n process.on(\"SIGTERM\", () => void shutdown())\n}\n\nmain().catch((error) => {\n console.error(\"Fatal error in main():\", error)\n process.exit(1)\n})\n"],"mappings":";sOAMA,MAAa,EAAa,GACxB,EAAK,EAAK,CAAC,KAA6B,EAAE,EAAG,EAAK,IAAQ,CACxD,IAAM,EAAQ,EAAI,MAAM,mBAAmB,CAC3C,OAAO,EAAQ,CAAE,GAAG,GAAM,EAAM,IAAK,EAAM,GAAI,CAAG,GAClD,CAGS,EAAiB,GAC5B,EAAO,EAAK,KAAK,CAAC,GAAG,EAAS,UAAU,CAAC,IAAK,GAAS,EAAK,SAAS,CAAC,CAE3D,EAAkB,GAA6C,CAC1E,IAAM,EAAS,EAAK,GAClB,EAAO,KAAO,EAAO,MAAc,CAAG,EAAO,0BAA0B,CACvE,EAAc,EAAO,CAAC,SACd,EAAO,2CAA2C,CACvD,GAAM,EAAO,MAAc,CAC7B,CACD,EAAO,MAAQ,MAAM,OAAO,EAAO,KAAK,CAAC,CAAG,EAAO,iBAAiB,CAAG,EAAO,MAAc,CAC7F,CAAC,QAAS,GAAM,EAAE,QAAQ,CAAC,CAE5B,OAAO,EAAO,QACV,EAAoB,IAAA,GAAU,CAC9B,EAAmB,yBAAyB,EAAO,SAAS,CAAC,KAAK;EAAK,GAAG,EAGnE,EAAc,MACzB,EACA,IACoD,CACpD,GAAI,EAAS,QAAQ,CACnB,OAAO,EAAsC,CAAE,SAAU,EAAS,MAAO,CAAC,CAE5E,GAAI,EAAQ,QAAQ,CAAE,CACpB,IAAM,EAAe,EAAK,OAAO,EAAQ,MAAM,CAC/C,GAAI,EAAa,QAAQ,CACvB,OAAO,EACL,wBAAwB,EAAQ,MAAM,IAAI,EAAa,MAAM,UAC9D,CAEH,IAAM,EAAW,EAAa,MAE9B,
|
|
1
|
+
{"version":3,"file":"index.js","names":["SSHClient"],"sources":["../src/config.ts","../src/index.ts"],"sourcesContent":["import { type Either, Left, List, Option, Right } from \"functype\"\nimport { Fs, Path, Platform } from \"functype-os\"\nimport { type ConnectConfig } from \"ssh2\"\n\nexport type ArgvConfig = Readonly<Record<string, string>>\n\nexport const parseArgv = (args: ReadonlyArray<string>): ArgvConfig =>\n List(args).fold<Record<string, string>>({}, (acc, arg) => {\n const match = arg.match(/^--([^=]+)=(.*)$/)\n return match ? { ...acc, [match[1]]: match[2] } : acc\n })\n\n// If --user is omitted, fall back to the OS-reported username (`whoami`-style).\nexport const effectiveUser = (argv: ArgvConfig): Option<string> =>\n Option(argv.user).or(Platform.userInfo().map((info) => info.username))\n\nexport const validateConfig = (config: ArgvConfig): Either<string, void> => {\n const errors = List.of(\n config.host ? Option.none<string>() : Option(\"Missing required --host\"),\n effectiveUser(config).fold(\n () => Option(\"Missing --user (and OS user unavailable)\"),\n (_) => Option.none<string>(),\n ),\n config.port && isNaN(Number(config.port)) ? Option(\"Invalid --port\") : Option.none<string>(),\n ).flatMap((o) => o.toList())\n\n return errors.isEmpty\n ? Right<string, void>(undefined)\n : Left<string, void>(`Configuration error:\\n${errors.toArray().join(\"\\n\")}`)\n}\n\nexport const resolveAuth = async (\n password: Option<string>,\n keyPath: Option<string>,\n): Promise<Either<string, Partial<ConnectConfig>>> => {\n if (password.isSome()) {\n return Right<string, Partial<ConnectConfig>>({ password: password.value })\n }\n if (keyPath.isSome()) {\n const expandResult = Path.expand(keyPath.value)\n if (expandResult.isLeft()) {\n return Left<string, Partial<ConnectConfig>>(\n `Invalid SSH key path ${keyPath.value}: ${expandResult.value.message}`,\n )\n }\n const expanded = expandResult.value\n const result = await Fs.readFile(expanded)\n return result.fold<Either<string, Partial<ConnectConfig>>>(\n (err) => Left<string, Partial<ConnectConfig>>(`Failed to read SSH key ${expanded}: ${err.message}`),\n (contents) => Right<string, Partial<ConnectConfig>>({ privateKey: contents }),\n )\n }\n return Right<string, Partial<ConnectConfig>>({})\n}\n","#!/usr/bin/env node\n\nimport { Option } from \"functype\"\nimport { createServer, UserError } from \"somamcp\"\nimport { Client as SSHClient, type ConnectConfig } from \"ssh2\"\nimport { z } from \"zod\"\n\nimport { effectiveUser, parseArgv, resolveAuth, validateConfig } from \"./config.js\"\n\n// Example: node dist/index.js --host=1.2.3.4 --port=22 --user=root --password=pass --key=~/.ssh/id_rsa\n\nconst execSshCommand = (sshConfig: ConnectConfig, command: string): Promise<string> =>\n new Promise((resolve, reject) => {\n const conn = new SSHClient()\n conn.on(\"ready\", () => {\n conn.exec(command, (err, stream) => {\n if (err) {\n reject(new UserError(`SSH exec error: ${err.message}`))\n conn.end()\n return\n }\n const stdoutChunks: Buffer[] = []\n const stderrChunks: Buffer[] = []\n stream.on(\"close\", (code: number) => {\n conn.end()\n const stdout = Buffer.concat(stdoutChunks).toString()\n const stderr = Buffer.concat(stderrChunks).toString()\n if (stderr) {\n reject(new UserError(`Error (code ${code}):\\n${stderr}`))\n } else {\n resolve(stdout)\n }\n })\n stream.on(\"data\", (data: Buffer) => {\n stdoutChunks.push(data)\n })\n stream.stderr.on(\"data\", (data: Buffer) => {\n stderrChunks.push(data)\n })\n })\n })\n conn.on(\"error\", (err) => {\n reject(new UserError(`SSH connection error: ${err.message}`))\n })\n conn.connect(sshConfig)\n })\n\nasync function main() {\n const argv = parseArgv(process.argv.slice(2))\n\n validateConfig(argv).fold(\n (err) => {\n console.error(err)\n process.exit(1)\n },\n () => undefined,\n )\n\n const { host } = argv\n const user = effectiveUser(argv).orThrow(new Error(\"user unavailable after validation\"))\n const port = Option(argv.port).map(Number).orElse(22)\n const password = Option(argv.password)\n const keyPath = Option(argv.key)\n\n const authResult = await resolveAuth(password, keyPath)\n const authConfig = authResult.fold<Partial<ConnectConfig>>(\n (err) => {\n console.error(err)\n process.exit(1)\n },\n (cfg) => cfg,\n )\n\n const sshConfig: ConnectConfig = { host, port, username: user, ...authConfig }\n\n const server = createServer({\n name: \"ssh-client-mcp-server\",\n version: \"1.2.0\",\n instructions: \"Execute shell commands on a remote host over SSH.\",\n })\n\n server.addTool({\n name: \"exec\",\n description: \"Execute a shell command on the remote SSH server and return the output.\",\n parameters: z.object({\n command: z.string().min(1).describe(\"Shell command to execute on the remote SSH server\"),\n }),\n execute: async ({ command }) => execSshCommand(sshConfig, command),\n })\n\n await server.start({ transportType: \"stdio\" })\n console.error(\"SSH MCP Server running on stdio\")\n\n const shutdown = async () => {\n await server.stop()\n process.exit(0)\n }\n process.on(\"SIGINT\", () => void shutdown())\n process.on(\"SIGTERM\", () => void shutdown())\n}\n\nmain().catch((error) => {\n console.error(\"Fatal error in main():\", error)\n process.exit(1)\n})\n"],"mappings":";sOAMA,MAAa,EAAa,GACxB,EAAK,EAAK,CAAC,KAA6B,EAAE,EAAG,EAAK,IAAQ,CACxD,IAAM,EAAQ,EAAI,MAAM,mBAAmB,CAC3C,OAAO,EAAQ,CAAE,GAAG,GAAM,EAAM,IAAK,EAAM,GAAI,CAAG,GAClD,CAGS,EAAiB,GAC5B,EAAO,EAAK,KAAK,CAAC,GAAG,EAAS,UAAU,CAAC,IAAK,GAAS,EAAK,SAAS,CAAC,CAE3D,EAAkB,GAA6C,CAC1E,IAAM,EAAS,EAAK,GAClB,EAAO,KAAO,EAAO,MAAc,CAAG,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AAO,MAAM,CACnB,QAAQ,KAAK,EAAE,EAEjB,QAAQ,GAAG,aAAgB,KAAK,GAAU,CAAC,CAC3C,QAAQ,GAAG,cAAiB,KAAK,GAAU,CAAC,CAG9C,GAAM,CAAC,MAAO,GAAU,CACtB,QAAQ,MAAM,yBAA0B,EAAM,CAC9C,QAAQ,KAAK,EAAE,EACf"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ssh-client-mcp-server",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.1",
|
|
5
5
|
"description": "MCP server that exposes SSH command execution to LLMs. Built on SomaMCP with functional config parsing (functype), path expansion (~, $VAR), and OS-user fallback.",
|
|
6
6
|
"author": "Jordan Burke <jordan.burke@gmail.com>",
|
|
7
7
|
"homepage": "https://github.com/jordanburke/ssh-client-mcp-server#readme",
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"typescript",
|
|
28
28
|
"cli"
|
|
29
29
|
],
|
|
30
|
+
"mcpName": "io.github.jordanburke/ssh-client-mcp-server",
|
|
30
31
|
"engines": {
|
|
31
32
|
"node": ">=22"
|
|
32
33
|
},
|
|
@@ -62,21 +63,23 @@
|
|
|
62
63
|
"build": "ts-builds build",
|
|
63
64
|
"dev": "ts-builds dev",
|
|
64
65
|
"inspect": "pnpm build && npx @modelcontextprotocol/inspector dist/index.js",
|
|
65
|
-
"
|
|
66
|
+
"check:versions": "tsx scripts/check-versions.ts",
|
|
67
|
+
"prepublishOnly": "pnpm check:versions && pnpm validate"
|
|
66
68
|
},
|
|
67
69
|
"prettier": "ts-builds/prettier",
|
|
68
70
|
"dependencies": {
|
|
69
|
-
"functype": "^0.60.
|
|
71
|
+
"functype": "^0.60.3",
|
|
70
72
|
"functype-os": "^0.60.0",
|
|
71
|
-
"somamcp": "^1.0.
|
|
73
|
+
"somamcp": "^1.0.6",
|
|
72
74
|
"ssh2": "^1.17.0",
|
|
73
|
-
"zod": "^4.3
|
|
75
|
+
"zod": "^4.4.3"
|
|
74
76
|
},
|
|
75
77
|
"devDependencies": {
|
|
76
78
|
"@types/node": "^24.12.2",
|
|
77
79
|
"@types/ssh2": "^1.15.5",
|
|
78
|
-
"ts-builds": "^2.7.
|
|
79
|
-
"tsdown": "^0.21.
|
|
80
|
+
"ts-builds": "^2.7.2",
|
|
81
|
+
"tsdown": "^0.21.10",
|
|
82
|
+
"tsx": "^4.21.0"
|
|
80
83
|
},
|
|
81
|
-
"packageManager": "pnpm@10.33.
|
|
84
|
+
"packageManager": "pnpm@10.33.3+sha512.a19744364a7e248b92657a4ca5973f9354d21caf982579674b1c539f32c7420c47138ad8b1254df07aba9bc782d9b3029e3db34d5dbff974326eb74dac8ff489"
|
|
82
85
|
}
|