@hheei/ssh-exec-mcp 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 hheei
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,162 @@
1
+ # SSH Exec
2
+
3
+ SSH Exec is an MCP server for non-interactive remote command execution and sshfs mounting over OpenSSH.
4
+
5
+ It can be used in two ways:
6
+
7
+ - as a Codex plugin
8
+ - as a standalone stdio MCP server for other clients such as `pi-agent`
9
+
10
+ It exposes two tools:
11
+
12
+ - `ssh_exec`
13
+ - `ssh_mount`
14
+
15
+ The server reuses OpenSSH ControlMaster connections, keeps session state hidden from the agent, and returns bounded command output with structured exit metadata.
16
+
17
+ ## Codex Install
18
+
19
+ Install the marketplace from GitHub:
20
+
21
+ ```bash
22
+ codex plugin marketplace add hheei/ssh-exec --ref main
23
+ ```
24
+
25
+ Install the plugin:
26
+
27
+ ```bash
28
+ codex plugin add ssh-exec@ssh-exec
29
+ ```
30
+
31
+ Start a new Codex thread after installation so the MCP tool is loaded.
32
+
33
+ ## Standalone MCP
34
+
35
+ You can also run SSH Exec directly as a stdio MCP server without the Codex plugin harness:
36
+
37
+ ```bash
38
+ bun ./ssh-exec-mcp.ts
39
+ ```
40
+
41
+ This gives other MCP clients a stable repo-root entrypoint instead of making them depend on the internal plugin path under `plugins/ssh-exec/...`.
42
+
43
+ ## bunx / npx
44
+
45
+ The repo is also packaged as a CLI so other agents can install it more directly:
46
+
47
+ ```bash
48
+ bunx @hheei/ssh-exec-mcp
49
+ ```
50
+
51
+ ```bash
52
+ npx @hheei/ssh-exec-mcp
53
+ ```
54
+
55
+ Current package behavior:
56
+
57
+ - `bunx @hheei/ssh-exec-mcp` works directly
58
+ - `npx @hheei/ssh-exec-mcp` works through a thin Node wrapper that launches `bun`
59
+ - for `npx`, Bun still needs to be installed on the machine
60
+
61
+ ## pi-agent Example
62
+
63
+ Example config is provided in [examples/pi-agent.mcp.json](./examples/pi-agent.mcp.json).
64
+
65
+ Typical config:
66
+
67
+ ```json
68
+ {
69
+ "mcpServers": {
70
+ "ssh-exec": {
71
+ "command": "bun",
72
+ "args": [
73
+ "/absolute/path/to/ssh-exec-mcp.ts"
74
+ ]
75
+ }
76
+ }
77
+ }
78
+ ```
79
+
80
+ Replace the path with your local checkout path.
81
+
82
+ If you install from npm instead of a local checkout, a typical config can also look like:
83
+
84
+ ```json
85
+ {
86
+ "mcpServers": {
87
+ "ssh-exec": {
88
+ "command": "npx",
89
+ "args": [
90
+ "-y",
91
+ "@hheei/ssh-exec-mcp"
92
+ ]
93
+ }
94
+ }
95
+ }
96
+ ```
97
+
98
+ Or with Bun:
99
+
100
+ ```json
101
+ {
102
+ "mcpServers": {
103
+ "ssh-exec": {
104
+ "command": "bunx",
105
+ "args": [
106
+ "@hheei/ssh-exec-mcp"
107
+ ]
108
+ }
109
+ }
110
+ }
111
+ ```
112
+
113
+ ## Requirements
114
+
115
+ - Bun
116
+ - OpenSSH client
117
+ - Existing SSH configuration with destination names resolvable by `ssh`
118
+ - `sshfs` if you want `ssh_mount`
119
+
120
+ ## Tools
121
+
122
+ ### `ssh_exec`
123
+
124
+ Runs a non-interactive command on a remote OpenSSH destination.
125
+
126
+ Input:
127
+
128
+ - `host`: OpenSSH destination, for example `prod` or `user@example.com`
129
+ - `command`: command passed to the remote shell by OpenSSH
130
+ - `timeout`: optional timeout in seconds, default `10`, clamped to `1..3600`
131
+
132
+ Output:
133
+
134
+ - text content containing the combined stdout/stderr tail or `(no output)`
135
+ - `structuredContent` with `host`, `exitCode`, `stdout`, `stderr`, `durationMs`, `truncated`, and output size metadata
136
+
137
+ Non-zero exits, timeouts, and SSH startup failures are returned as MCP tool errors when captured output is available.
138
+
139
+ ### `ssh_mount`
140
+
141
+ Mounts the remote host locally through `sshfs`.
142
+
143
+ Input:
144
+
145
+ - `host`: OpenSSH destination, for example `prod` or `user@example.com`
146
+
147
+ Output:
148
+
149
+ - compact success text with local mount path
150
+ - `structuredContent` with `host`, `localPath`, and mount `status`
151
+
152
+ ## Scope
153
+
154
+ SSH Exec intentionally does not expose interactive shell sessions, file upload/download commands, host discovery, or batch orchestration APIs beyond `ssh_exec` and `ssh_mount`.
155
+
156
+ ## Development
157
+
158
+ Run tests:
159
+
160
+ ```bash
161
+ bun test plugins/ssh-exec/scripts/*.test.ts
162
+ ```
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { spawn } from "node:child_process";
4
+ import { dirname, resolve } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+
7
+ const __dirname = dirname(fileURLToPath(import.meta.url));
8
+ const entrypoint = resolve(__dirname, "..", "ssh-exec-mcp.ts");
9
+ const bunBin = process.env.BUN_BIN || "bun";
10
+
11
+ const child = spawn(bunBin, [entrypoint, ...process.argv.slice(2)], {
12
+ stdio: "inherit",
13
+ });
14
+
15
+ child.on("error", (error) => {
16
+ if (error && "code" in error && error.code === "ENOENT") {
17
+ process.stderr.write(
18
+ [
19
+ "ssh-exec-mcp requires Bun at runtime.",
20
+ "Install Bun from https://bun.sh/ or set BUN_BIN to the Bun executable path.",
21
+ ].join("\n") + "\n",
22
+ );
23
+ process.exit(1);
24
+ return;
25
+ }
26
+
27
+ process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
28
+ process.exit(1);
29
+ });
30
+
31
+ child.on("exit", (code, signal) => {
32
+ if (signal) {
33
+ process.kill(process.pid, signal);
34
+ return;
35
+ }
36
+ process.exit(code ?? 1);
37
+ });
@@ -0,0 +1,10 @@
1
+ {
2
+ "mcpServers": {
3
+ "ssh-exec": {
4
+ "command": "bun",
5
+ "args": [
6
+ "/absolute/path/to/ssh-exec-mcp.ts"
7
+ ]
8
+ }
9
+ }
10
+ }
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@hheei/ssh-exec-mcp",
3
+ "version": "0.1.0",
4
+ "description": "MCP server for remote command execution and sshfs mounting over OpenSSH",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "homepage": "https://github.com/hheei/ssh-exec",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/hheei/ssh-exec.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/hheei/ssh-exec/issues"
14
+ },
15
+ "author": "hheei",
16
+ "bin": {
17
+ "ssh-exec-mcp": "bin/ssh-exec-mcp.js"
18
+ },
19
+ "files": [
20
+ "bin/",
21
+ "examples/",
22
+ "plugins/ssh-exec/",
23
+ "ssh-exec-mcp.ts",
24
+ "README.md",
25
+ "LICENSE"
26
+ ],
27
+ "keywords": [
28
+ "mcp",
29
+ "ssh",
30
+ "sshfs",
31
+ "openssh",
32
+ "remote",
33
+ "codex"
34
+ ]
35
+ }
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "ssh-exec",
3
+ "version": "0.1.0+codex.20260703175642",
4
+ "description": "Remote command execution and sshfs mounting over OpenSSH",
5
+ "author": {
6
+ "name": "hheei",
7
+ "url": "https://github.com/hheei"
8
+ },
9
+ "homepage": "https://github.com/hheei/ssh-exec",
10
+ "repository": "https://github.com/hheei/ssh-exec",
11
+ "license": "MIT",
12
+ "keywords": [
13
+ "ssh",
14
+ "mcp",
15
+ "codex",
16
+ "openssh",
17
+ "sshfs"
18
+ ],
19
+ "interface": {
20
+ "displayName": "SSH Exec",
21
+ "shortDescription": "Run remote commands and mount remote files over OpenSSH.",
22
+ "longDescription": "SSH Exec provides two tools: ssh_mount for mounting a remote host locally so Codex can use built-in file tools, and ssh_exec for remote commands such as inspection, verification, and service control.",
23
+ "developerName": "hheei",
24
+ "category": "Productivity",
25
+ "capabilities": [
26
+ "MCP",
27
+ "SSH"
28
+ ],
29
+ "websiteURL": "https://github.com/hheei/ssh-exec",
30
+ "defaultPrompt": "Use ssh_mount before editing remote files, then use ssh_exec to inspect or verify the remote host.",
31
+ "brandColor": "#111827",
32
+ "composerIcon": "./assets/icon.svg"
33
+ },
34
+ "mcpServers": "./.mcp.json"
35
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "mcpServers": {
3
+ "ssh-exec": {
4
+ "cwd": ".",
5
+ "command": "bun",
6
+ "args": [
7
+ "./scripts/ssh-exec-mcp.ts"
8
+ ]
9
+ }
10
+ }
11
+ }
@@ -0,0 +1,34 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" role="img" aria-label="SSH Exec plugin icon">
2
+ <rect x="28" y="40" width="200" height="176" rx="34" fill="#FFFFFF"/>
3
+ <rect x="28" y="40" width="200" height="176" rx="34" fill="none" stroke="#1D4ED8" stroke-width="14"/>
4
+ <path
5
+ d="M72 100l32 28-32 28"
6
+ fill="none"
7
+ stroke="#1D4ED8"
8
+ stroke-linecap="round"
9
+ stroke-linejoin="round"
10
+ stroke-width="16"
11
+ />
12
+ <path
13
+ d="M124 156h44"
14
+ fill="none"
15
+ stroke="#1D4ED8"
16
+ stroke-linecap="round"
17
+ stroke-width="16"
18
+ />
19
+ <circle cx="186" cy="88" r="18" fill="#1D4ED8"/>
20
+ <path
21
+ d="M186 70v14"
22
+ fill="none"
23
+ stroke="#FFFFFF"
24
+ stroke-linecap="round"
25
+ stroke-width="10"
26
+ />
27
+ <path
28
+ d="M176 88h20"
29
+ fill="none"
30
+ stroke="#FFFFFF"
31
+ stroke-linecap="round"
32
+ stroke-width="10"
33
+ />
34
+ </svg>
@@ -0,0 +1,69 @@
1
+ import { expect, test } from "bun:test";
2
+ import { OutputTailSink } from "./output-tail-sink";
3
+ import { MAX_OUTPUT_BYTES } from "./ssh-exec";
4
+
5
+ test("OutputTailSink retains only the last maxBytes bytes", () => {
6
+ const sink = new OutputTailSink(8);
7
+
8
+ sink.write(Buffer.from("12345"));
9
+ sink.write(Buffer.from("67890"));
10
+
11
+ expect(sink.dump()).toMatchObject({ text: "34567890", stdout: "34567890", stderr: "", truncated: true });
12
+ });
13
+
14
+ test("OutputTailSink reports untruncated small output", () => {
15
+ const sink = new OutputTailSink(MAX_OUTPUT_BYTES);
16
+
17
+ sink.write(Buffer.from("small output\n"));
18
+
19
+ expect(sink.dump()).toMatchObject({
20
+ text: "small output\n",
21
+ stdout: "small output\n",
22
+ stderr: "",
23
+ truncated: false,
24
+ totalBytes: Buffer.byteLength("small output\n"),
25
+ outputBytes: Buffer.byteLength("small output\n"),
26
+ });
27
+ });
28
+
29
+ test("OutputTailSink retains one combined tail across stdout and stderr", () => {
30
+ const sink = new OutputTailSink(10);
31
+
32
+ sink.write("stdout", "out-12345");
33
+ sink.write("stderr", "err-67890");
34
+
35
+ const dump = sink.dump();
36
+ expect(Buffer.byteLength(dump.text)).toBeLessThanOrEqual(10);
37
+ expect(dump).toMatchObject({
38
+ text: "5err-67890",
39
+ stdout: "5",
40
+ stderr: "err-67890",
41
+ truncated: true,
42
+ });
43
+ });
44
+
45
+ test("OutputTailSink preserves retained stdout and stderr order in combined output", () => {
46
+ const sink = new OutputTailSink(MAX_OUTPUT_BYTES);
47
+
48
+ sink.write("stdout", "out-1\n");
49
+ sink.write("stderr", "err-1\n");
50
+ sink.write("stdout", "out-2\n");
51
+ sink.write("stderr", "err-2\n");
52
+
53
+ expect(sink.dump()).toMatchObject({
54
+ text: "out-1\nerr-1\nout-2\nerr-2\n",
55
+ stdout: "out-1\nout-2\n",
56
+ stderr: "err-1\nerr-2\n",
57
+ truncated: false,
58
+ });
59
+ });
60
+
61
+ test("OutputTailSink truncates on UTF-8 boundaries", () => {
62
+ const sink = new OutputTailSink(4);
63
+
64
+ sink.write("stdout", "x🙂y");
65
+
66
+ const dump = sink.dump();
67
+ expect(dump.text).toBe("y");
68
+ expect(dump.text).not.toContain("\uFFFD");
69
+ });
@@ -0,0 +1,182 @@
1
+ export interface TailDump {
2
+ text: string;
3
+ stdout: string;
4
+ stderr: string;
5
+ truncated: boolean;
6
+ totalBytes: number;
7
+ outputBytes: number;
8
+ totalLines: number;
9
+ outputLines: number;
10
+ }
11
+
12
+ export type OutputSource = "stdout" | "stderr";
13
+
14
+ interface TailEntry {
15
+ source: OutputSource;
16
+ buffer: Buffer;
17
+ }
18
+
19
+ export class OutputTailSink {
20
+ private entries: TailEntry[] = [];
21
+ private didTruncate = false;
22
+ private retainedBytes = 0;
23
+ private writtenBytes = 0;
24
+ private writtenLines = 0;
25
+
26
+ constructor(private readonly maxBytes: number) {}
27
+
28
+ write(chunk: Uint8Array | string): void;
29
+ write(source: OutputSource, chunk: Uint8Array | string): void;
30
+ write(sourceOrChunk: OutputSource | Uint8Array | string, maybeChunk?: Uint8Array | string): void {
31
+ const source = maybeChunk === undefined ? "stdout" : (sourceOrChunk as OutputSource);
32
+ const chunk = maybeChunk === undefined ? (sourceOrChunk as Uint8Array | string) : maybeChunk;
33
+ const next = typeof chunk === "string" ? Buffer.from(chunk) : Buffer.from(chunk);
34
+ if (next.length === 0) return;
35
+
36
+ this.entries.push({ source, buffer: next });
37
+ this.retainedBytes += next.length;
38
+ this.writtenBytes += next.length;
39
+ this.writtenLines += countNewlines(next.toString("utf8"));
40
+ this.trim();
41
+ }
42
+
43
+ dump(): TailDump {
44
+ const combined: Buffer[] = [];
45
+ const stdoutBuffers: Buffer[] = [];
46
+ const stderrBuffers: Buffer[] = [];
47
+
48
+ for (const entry of this.entries) {
49
+ combined.push(entry.buffer);
50
+ if (entry.source === "stdout") {
51
+ stdoutBuffers.push(entry.buffer);
52
+ } else {
53
+ stderrBuffers.push(entry.buffer);
54
+ }
55
+ }
56
+
57
+ const text = Buffer.concat(combined).toString("utf8");
58
+ const stdout = Buffer.concat(stdoutBuffers).toString("utf8");
59
+ const stderr = Buffer.concat(stderrBuffers).toString("utf8");
60
+
61
+ return {
62
+ text,
63
+ stdout,
64
+ stderr,
65
+ truncated: this.didTruncate,
66
+ totalBytes: this.writtenBytes,
67
+ outputBytes: this.retainedBytes,
68
+ totalLines: this.writtenLines,
69
+ outputLines: countNewlines(text),
70
+ };
71
+ }
72
+
73
+ private trim(): void {
74
+ if (this.maxBytes <= 0) {
75
+ if (this.entries.length > 0) this.didTruncate = true;
76
+ this.entries = [];
77
+ this.retainedBytes = 0;
78
+ return;
79
+ }
80
+
81
+ if (this.retainedBytes <= this.maxBytes) {
82
+ return;
83
+ }
84
+
85
+ this.didTruncate = true;
86
+ this.rebuildTail();
87
+ }
88
+
89
+ private rebuildTail(): void {
90
+ const combined = Buffer.concat(this.entries.map((entry) => entry.buffer));
91
+ const safeStart = findUtf8TailStart(combined, this.maxBytes);
92
+ const sliced = combined.subarray(safeStart);
93
+
94
+ const rebuilt: TailEntry[] = [];
95
+ let offset = 0;
96
+ let retainedBytes = 0;
97
+
98
+ for (const entry of this.entries) {
99
+ const entryStart = offset;
100
+ const entryEnd = offset + entry.buffer.length;
101
+ offset = entryEnd;
102
+
103
+ if (entryEnd <= safeStart) continue;
104
+
105
+ const sliceStart = Math.max(safeStart, entryStart) - entryStart;
106
+ const sliceEnd = Math.min(combined.length, entryEnd) - entryStart;
107
+ const buffer = entry.buffer.subarray(sliceStart, sliceEnd);
108
+ if (buffer.length === 0) continue;
109
+
110
+ rebuilt.push({ source: entry.source, buffer });
111
+ retainedBytes += buffer.length;
112
+ }
113
+
114
+ this.entries = rebuilt.length > 0 || sliced.length === 0 ? rebuilt : [{ source: "stdout", buffer: sliced }];
115
+ this.retainedBytes = retainedBytes;
116
+ }
117
+ }
118
+
119
+ export async function readStreamTail(
120
+ stream: ReadableStream<Uint8Array> | null,
121
+ maxBytes: number,
122
+ ): Promise<TailDump> {
123
+ const sink = new OutputTailSink(maxBytes);
124
+ if (!stream) return sink.dump();
125
+
126
+ const reader = stream.getReader();
127
+ try {
128
+ while (true) {
129
+ const { done, value } = await reader.read();
130
+ if (done) break;
131
+ if (value) sink.write(value);
132
+ }
133
+ } finally {
134
+ reader.releaseLock();
135
+ }
136
+
137
+ return sink.dump();
138
+ }
139
+
140
+ function countNewlines(text: string): number {
141
+ let count = 0;
142
+ let index = text.indexOf("\n");
143
+ while (index !== -1) {
144
+ count += 1;
145
+ index = text.indexOf("\n", index + 1);
146
+ }
147
+ return count;
148
+ }
149
+
150
+ function findUtf8TailStart(buffer: Buffer, maxBytes: number): number {
151
+ if (buffer.length <= maxBytes) return 0;
152
+
153
+ let start = buffer.length - maxBytes;
154
+ while (start < buffer.length && (buffer[start] & 0xc0) === 0x80) {
155
+ start += 1;
156
+ }
157
+
158
+ while (start < buffer.length) {
159
+ const width = utf8SequenceWidth(buffer[start]);
160
+ if (width === 0) {
161
+ start += 1;
162
+ continue;
163
+ }
164
+ if (start + width <= buffer.length) {
165
+ return start;
166
+ }
167
+ start += 1;
168
+ while (start < buffer.length && (buffer[start] & 0xc0) === 0x80) {
169
+ start += 1;
170
+ }
171
+ }
172
+
173
+ return buffer.length;
174
+ }
175
+
176
+ function utf8SequenceWidth(byte: number): number {
177
+ if ((byte & 0x80) === 0) return 1;
178
+ if ((byte & 0xe0) === 0xc0) return 2;
179
+ if ((byte & 0xf0) === 0xe0) return 3;
180
+ if ((byte & 0xf8) === 0xf0) return 4;
181
+ return 0;
182
+ }