@mgsoftwarebv/mg-dashboard-mcp 3.5.0 → 3.6.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/dist/index.js CHANGED
@@ -1372,6 +1372,8 @@ var TOOL_MODULE_MAP = {
1372
1372
  "sftp-delete": "ssh_servers",
1373
1373
  "docker-list": "ssh_servers",
1374
1374
  "docker-logs": "ssh_servers",
1375
+ "docker-exec": "ssh_servers",
1376
+ "docker-compose": "ssh_servers",
1375
1377
  "db-discover": "ssh_servers",
1376
1378
  "db-tables": "ssh_servers",
1377
1379
  "db-describe": "ssh_servers",
@@ -1819,6 +1821,28 @@ async function attemptVercelSync(appName, environment, knownStageId) {
1819
1821
  return `Vercel sync error: ${msg}`;
1820
1822
  }
1821
1823
  }
1824
+ function posixQuote(arg) {
1825
+ if (arg === "") return "''";
1826
+ if (/^[A-Za-z0-9._\/=:@%+\-]+$/.test(arg)) return arg;
1827
+ return "'" + arg.replace(/'/g, "'\\''") + "'";
1828
+ }
1829
+ function buildPosixCommand(command, args2) {
1830
+ const program = /^[A-Za-z0-9._\/\- ]+$/.test(command) ? command : posixQuote(command);
1831
+ if (args2.length === 0) return program;
1832
+ return `${program} ${args2.map(posixQuote).join(" ")}`;
1833
+ }
1834
+ function buildPowerShellEncodedCommand(command, args2) {
1835
+ const psSingleQuote = (s) => "'" + s.replace(/'/g, "''") + "'";
1836
+ let psExpr;
1837
+ if (args2.length === 0) {
1838
+ psExpr = command;
1839
+ } else {
1840
+ psExpr = `& ${psSingleQuote(command)} ${args2.map(psSingleQuote).join(" ")}`;
1841
+ }
1842
+ const utf16 = Buffer.from(psExpr, "utf16le");
1843
+ const b64 = utf16.toString("base64");
1844
+ return `powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -EncodedCommand ${b64}`;
1845
+ }
1822
1846
  var SSH_PROXY_SERVER_ID = "03659d55-e194-400d-b82a-bf6457371ded";
1823
1847
  var _proxyConnCache = null;
1824
1848
  async function getProxyConnection() {
@@ -1838,7 +1862,7 @@ async function getProxyConnection() {
1838
1862
  }
1839
1863
  async function getServerConnection(serverId) {
1840
1864
  assertServerAccess(serverId);
1841
- const { data, error } = await supabase.from("ssh_server").select("hostname, port, username, password_encrypted, ssh_key_encrypted, ssh_key_passphrase_encrypted, allowed_ssh_ips").eq("id", serverId).single();
1865
+ const { data, error } = await supabase.from("ssh_server").select("hostname, port, username, password_encrypted, ssh_key_encrypted, ssh_key_passphrase_encrypted, allowed_ssh_ips, os_type").eq("id", serverId).single();
1842
1866
  if (error || !data) throw new Error(`Server not found: ${serverId}`);
1843
1867
  if (!encryptionKey) throw new Error("ENCRYPTION_KEY required to decrypt server credentials");
1844
1868
  const conn = {
@@ -1851,10 +1875,11 @@ async function getServerConnection(serverId) {
1851
1875
  };
1852
1876
  const needsProxy = data.allowed_ssh_ips !== null && serverId !== SSH_PROXY_SERVER_ID;
1853
1877
  const proxy = needsProxy ? await getProxyConnection() : void 0;
1854
- return { conn, proxy };
1878
+ const os = data.os_type === "windows" ? "windows" : "linux";
1879
+ return { conn, proxy, os };
1855
1880
  }
1856
- async function sshExec(opts, command, proxy) {
1857
- if (proxy) return sshExecViaProxy(proxy, opts, command);
1881
+ async function sshExec(opts, command, proxy, options) {
1882
+ if (proxy) return sshExecViaProxy(proxy, opts, command, options);
1858
1883
  return new Promise((resolve) => {
1859
1884
  const ssh = new Client();
1860
1885
  let stdout = "";
@@ -1893,6 +1918,9 @@ async function sshExec(opts, command, proxy) {
1893
1918
  resolve({ stdout, stderr, exitCode: code ?? 0 });
1894
1919
  }
1895
1920
  });
1921
+ if (options?.stdin !== void 0) {
1922
+ stream.end(options.stdin);
1923
+ }
1896
1924
  });
1897
1925
  });
1898
1926
  ssh.on("error", (err) => {
@@ -1913,7 +1941,7 @@ async function sshExec(opts, command, proxy) {
1913
1941
  });
1914
1942
  });
1915
1943
  }
1916
- function sshExecViaProxy(proxyOpts, targetOpts, command) {
1944
+ function sshExecViaProxy(proxyOpts, targetOpts, command, options) {
1917
1945
  return new Promise((resolve) => {
1918
1946
  const proxyClient = new Client();
1919
1947
  let done = false;
@@ -1967,6 +1995,9 @@ function sshExecViaProxy(proxyOpts, targetOpts, command) {
1967
1995
  resolve({ stdout, stderr, exitCode: code ?? 0 });
1968
1996
  }
1969
1997
  });
1998
+ if (options?.stdin !== void 0) {
1999
+ stream.end(options.stdin);
2000
+ }
1970
2001
  });
1971
2002
  });
1972
2003
  targetClient.on("error", (targetErr) => {
@@ -2091,8 +2122,22 @@ function assertWritablePath(path) {
2091
2122
  }
2092
2123
  }
2093
2124
  }
2094
- async function sftpReaddir(opts, dirPath, proxy) {
2095
- const safe = sanitizePath(dirPath);
2125
+ function globToRegExp(pattern) {
2126
+ let re = "";
2127
+ for (const c of pattern) {
2128
+ if (c === "*") re += ".*";
2129
+ else if (c === "?") re += ".";
2130
+ else if (/[.+^${}()|[\]\\]/.test(c)) re += "\\" + c;
2131
+ else re += c;
2132
+ }
2133
+ return new RegExp(`^${re}$`);
2134
+ }
2135
+ async function sftpReaddir(opts, dirPath, proxy, options) {
2136
+ const recursive = options?.recursive === true;
2137
+ const maxDepth = Math.max(1, Math.min(20, options?.maxDepth ?? 5));
2138
+ const maxResults = Math.max(1, Math.min(5e4, options?.maxResults ?? 5e3));
2139
+ const matcher = options?.pattern ? globToRegExp(options.pattern) : null;
2140
+ const rootSafe = sanitizePath(dirPath);
2096
2141
  let cleanup;
2097
2142
  try {
2098
2143
  const { client, cleanup: c } = await connectSshClient(opts, proxy, 3e4);
@@ -2102,7 +2147,7 @@ async function sftpReaddir(opts, dirPath, proxy) {
2102
2147
  cleanup?.();
2103
2148
  resolve("Error: timeout");
2104
2149
  cleanup = void 0;
2105
- }, 3e4);
2150
+ }, 6e4);
2106
2151
  client.sftp((err, sftp) => {
2107
2152
  if (err) {
2108
2153
  clearTimeout(timer);
@@ -2111,24 +2156,48 @@ async function sftpReaddir(opts, dirPath, proxy) {
2111
2156
  resolve(`Error: ${err.message}`);
2112
2157
  return;
2113
2158
  }
2114
- sftp.readdir(safe, (err2, list) => {
2115
- clearTimeout(timer);
2116
- if (err2) {
2117
- cleanup?.();
2118
- cleanup = void 0;
2119
- resolve(`Error: ${err2.message}`);
2120
- return;
2121
- }
2122
- const entries = list.map((item) => {
2123
- const mode = item.attrs.mode || 0;
2124
- const isDir = (mode & 61440) === 16384;
2125
- const size = item.attrs.size || 0;
2126
- const mtime = item.attrs.mtime ? new Date(item.attrs.mtime * 1e3).toISOString() : "";
2127
- return `${isDir ? "d" : "-"} ${String(size).padStart(10)} ${mtime} ${item.filename}`;
2159
+ const lines = [];
2160
+ let truncated = false;
2161
+ const readOne = (path, depth) => new Promise((resolveOne) => {
2162
+ sftp.readdir(path, (err2, list) => {
2163
+ if (err2) {
2164
+ lines.push(`! error reading ${path}: ${err2.message}`);
2165
+ return resolveOne();
2166
+ }
2167
+ const subdirs = [];
2168
+ for (const item of list) {
2169
+ if (lines.length >= maxResults) {
2170
+ truncated = true;
2171
+ break;
2172
+ }
2173
+ const mode = item.attrs.mode || 0;
2174
+ const isDir = (mode & 61440) === 16384;
2175
+ const size = item.attrs.size || 0;
2176
+ const mtime = item.attrs.mtime ? new Date(item.attrs.mtime * 1e3).toISOString() : "";
2177
+ const fullPath = path === "/" ? `/${item.filename}` : `${path}/${item.filename}`;
2178
+ const include = !matcher || matcher.test(item.filename);
2179
+ if (include) {
2180
+ const display = recursive ? fullPath : item.filename;
2181
+ lines.push(`${isDir ? "d" : "-"} ${String(size).padStart(10)} ${mtime} ${display}`);
2182
+ }
2183
+ if (isDir && recursive && depth < maxDepth) subdirs.push(fullPath);
2184
+ }
2185
+ if (truncated || subdirs.length === 0) return resolveOne();
2186
+ (async () => {
2187
+ for (const sub of subdirs) {
2188
+ if (truncated) break;
2189
+ await readOne(sub, depth + 1);
2190
+ }
2191
+ resolveOne();
2192
+ })();
2128
2193
  });
2194
+ });
2195
+ readOne(rootSafe, 1).then(() => {
2196
+ clearTimeout(timer);
2129
2197
  cleanup?.();
2130
2198
  cleanup = void 0;
2131
- resolve(entries.join("\n"));
2199
+ if (truncated) lines.push(`... (truncated at ${maxResults} entries; raise maxResults or narrow path/pattern)`);
2200
+ resolve(lines.length ? lines.join("\n") : "No entries");
2132
2201
  });
2133
2202
  });
2134
2203
  });
@@ -2552,12 +2621,15 @@ var TOOLS = [
2552
2621
  },
2553
2622
  {
2554
2623
  name: "ssh-execute",
2555
- description: "Execute a shell command on a remote server via SSH. Some dangerous commands are blocked for safety.",
2624
+ description: 'Execute a command on a remote server via SSH. OS-aware: automatically wraps in bash on linux servers and `powershell -EncodedCommand` (UTF-16LE base64) on windows servers, so $, #, quotes, spaces inside `args` are never re-interpreted by a shell. Some dangerous commands are blocked. Use `list-servers` first to see each server\'s os_type.\nTwo ways to invoke (use `args` for anything with passwords or special chars):\n- Quick: `command` only, e.g. `command: "df -h"` (raw shell string, OS-dispatched but caller-quoted).\n- Safe: `command` + `args[]`, e.g. `command: "mysql"`, `args: ["-u", "root", "-p$tr@nge#pwd", "-e", "SELECT 1"]` \u2014 every arg is quoted/encoded for the target OS.\n`stdin` lets you pipe data into the remote process (queries, scripts, secrets) without putting it on the command line.',
2556
2625
  inputSchema: {
2557
2626
  type: "object",
2558
2627
  properties: {
2559
2628
  serverId: { type: "string", description: "UUID of the SSH server" },
2560
- command: { type: "string", description: "Shell command to execute" },
2629
+ command: { type: "string", description: 'Program/command to run (e.g. "mysql", "Get-Service", "df"). Required.' },
2630
+ args: { type: "array", items: { type: "string" }, description: "Optional argv list. When provided, each entry is safely quoted/encoded for the target OS." },
2631
+ stdin: { type: "string", description: "Optional data piped to the remote process stdin (use for SQL queries, scripts, secrets \u2014 anything you do NOT want on the command line)." },
2632
+ shell: { type: "string", enum: ["auto", "bash", "powershell"], description: `Override shell selection (default "auto" uses the server's os_type).` },
2561
2633
  timeout: { type: "number", description: "Timeout in milliseconds (default: 60000)" }
2562
2634
  },
2563
2635
  required: ["serverId", "command"]
@@ -2565,12 +2637,16 @@ var TOOLS = [
2565
2637
  },
2566
2638
  {
2567
2639
  name: "sftp-list",
2568
- description: "List files and directories at a given path on a remote server via SFTP.",
2640
+ description: 'List files and directories on a remote server via SFTP. Supports recursive traversal and glob filtering, eliminating the need to fall back on `ssh-execute "find ..."`.',
2569
2641
  inputSchema: {
2570
2642
  type: "object",
2571
2643
  properties: {
2572
2644
  serverId: { type: "string", description: "UUID of the SSH server" },
2573
- path: { type: "string", description: "Directory path to list (default: /)" }
2645
+ path: { type: "string", description: "Directory path to list (default: /)" },
2646
+ recursive: { type: "boolean", description: "Walk into subdirectories (default false)" },
2647
+ maxDepth: { type: "number", description: "Maximum recursion depth (1-20, default 5)" },
2648
+ pattern: { type: "string", description: 'Glob pattern to filter filenames (e.g. "*.conf", "wp-*.php"). Matches basename only.' },
2649
+ maxResults: { type: "number", description: "Cap total entries returned (default 5000, max 50000)" }
2574
2650
  },
2575
2651
  required: ["serverId"]
2576
2652
  }
@@ -2615,28 +2691,66 @@ var TOOLS = [
2615
2691
  },
2616
2692
  {
2617
2693
  name: "docker-list",
2618
- description: "List all Docker containers on a remote server (running and stopped).",
2694
+ description: "List Docker containers on a remote server. Adds the docker-compose project label as the last column so you can immediately see which compose project a container belongs to.",
2619
2695
  inputSchema: {
2620
2696
  type: "object",
2621
2697
  properties: {
2622
- serverId: { type: "string", description: "UUID of the SSH server" }
2698
+ serverId: { type: "string", description: "UUID of the SSH server" },
2699
+ format: { type: "string", enum: ["table", "json"], description: "Output format: human table (default) or NDJSON (one JSON object per line, includes labels)." },
2700
+ composeOnly: { type: "boolean", description: "Only show containers that have a docker-compose project label." }
2623
2701
  },
2624
2702
  required: ["serverId"]
2625
2703
  }
2626
2704
  },
2627
2705
  {
2628
2706
  name: "docker-logs",
2629
- description: "Get recent logs from a Docker container.",
2707
+ description: "Get logs from a Docker container. Supports time-window (`since`) and server-side `grep` to keep responses small. Always merges stderr into stdout.",
2630
2708
  inputSchema: {
2631
2709
  type: "object",
2632
2710
  properties: {
2633
2711
  serverId: { type: "string", description: "UUID of the SSH server" },
2634
2712
  containerName: { type: "string", description: "Container name or ID" },
2635
- lines: { type: "number", description: "Number of log lines to retrieve (default: 100)" }
2713
+ lines: { type: "number", description: "Number of log lines to retrieve (default: 100)" },
2714
+ since: { type: "string", description: 'Time window, e.g. "10m", "2h", "24h", or an absolute "2026-05-09T10:00:00".' },
2715
+ grep: { type: "string", description: "Case-insensitive regex/literal filter applied server-side (saves tokens for noisy containers)." }
2636
2716
  },
2637
2717
  required: ["serverId", "containerName"]
2638
2718
  }
2639
2719
  },
2720
+ {
2721
+ name: "docker-exec",
2722
+ description: 'Run a command inside a running Docker container. `args[]` are quoted safely (no shell-escape hell with $ or quotes). Optional `stdin` pipes data into the container process (for SQL, scripts, etc.). Use this instead of `ssh-execute "docker exec ..."`.',
2723
+ inputSchema: {
2724
+ type: "object",
2725
+ properties: {
2726
+ serverId: { type: "string", description: "UUID of the SSH server" },
2727
+ container: { type: "string", description: "Container name or ID" },
2728
+ command: { type: "string", description: 'Program to run inside the container (e.g. "psql", "wp", "node").' },
2729
+ args: { type: "array", items: { type: "string" }, description: "Argument list, each safely quoted." },
2730
+ stdin: { type: "string", description: "Optional data piped to the container process stdin." },
2731
+ workdir: { type: "string", description: "Working directory inside the container (-w)." },
2732
+ user: { type: "string", description: "User to run as inside the container (-u)." },
2733
+ timeout: { type: "number", description: "Timeout in milliseconds (default: 60000)" }
2734
+ },
2735
+ required: ["serverId", "container", "command"]
2736
+ }
2737
+ },
2738
+ {
2739
+ name: "docker-compose",
2740
+ description: 'Run a docker-compose action against a project on a remote server. Replaces the common `ssh-execute "cd /opt/x && docker compose ..."` pattern. Action enum keeps the surface tiny.',
2741
+ inputSchema: {
2742
+ type: "object",
2743
+ properties: {
2744
+ serverId: { type: "string", description: "UUID of the SSH server" },
2745
+ projectPath: { type: "string", description: "Absolute path to the directory containing docker-compose.yml." },
2746
+ action: { type: "string", enum: ["up", "down", "restart", "logs", "ps", "pull", "build"], description: "Compose action." },
2747
+ service: { type: "string", description: 'Optional service name to scope the action to (e.g. "studio"). Omit to act on the whole project.' },
2748
+ tail: { type: "number", description: "For `logs`: number of lines (default 200)." },
2749
+ timeout: { type: "number", description: "Timeout in milliseconds (default: 120000 \u2014 compose ops can be slow)." }
2750
+ },
2751
+ required: ["serverId", "projectPath", "action"]
2752
+ }
2753
+ },
2640
2754
  {
2641
2755
  name: "db-discover",
2642
2756
  description: "Scan /var/www on a server for web applications (WordPress, PrestaShop, Laravel, .env) and list their database credentials. Use this first to find available sites before running other db-* tools.",
@@ -2888,10 +3002,22 @@ async function executeToolCall(name, a, _serverId) {
2888
3002
  case "ssh-execute": {
2889
3003
  const command = String(a.command);
2890
3004
  assertSafeCommand(command);
2891
- const { conn, proxy } = await getServerConnection(String(a.serverId));
3005
+ const args2 = Array.isArray(a.args) ? a.args.map(String) : void 0;
3006
+ const stdin = typeof a.stdin === "string" ? a.stdin : void 0;
3007
+ const shellOverride = typeof a.shell === "string" ? a.shell : "auto";
3008
+ const { conn, proxy, os } = await getServerConnection(String(a.serverId));
2892
3009
  if (a.timeout) conn.timeout = Number(a.timeout);
2893
- const result = await sshExec(conn, command, proxy);
2894
- const output = [`Exit code: ${result.exitCode}`];
3010
+ const shell = shellOverride === "auto" ? os === "windows" ? "powershell" : "bash" : shellOverride;
3011
+ let finalCmd;
3012
+ if (args2 && args2.length > 0) {
3013
+ finalCmd = shell === "powershell" ? buildPowerShellEncodedCommand(command, args2) : buildPosixCommand(command, args2);
3014
+ } else if (shell === "powershell" && !/^powershell\b/i.test(command.trim())) {
3015
+ finalCmd = buildPowerShellEncodedCommand(command, []);
3016
+ } else {
3017
+ finalCmd = command;
3018
+ }
3019
+ const result = await sshExec(conn, finalCmd, proxy, stdin !== void 0 ? { stdin } : void 0);
3020
+ const output = [`Exit code: ${result.exitCode} (os: ${os}, shell: ${shell})`];
2895
3021
  if (result.stdout) output.push(`--- stdout ---
2896
3022
  ${result.stdout}`);
2897
3023
  if (result.stderr) output.push(`--- stderr ---
@@ -2901,7 +3027,12 @@ ${result.stderr}`);
2901
3027
  // ----- SFTP -----
2902
3028
  case "sftp-list": {
2903
3029
  const { conn, proxy } = await getServerConnection(String(a.serverId));
2904
- const listing = await sftpReaddir(conn, String(a.path || "/"), proxy);
3030
+ const listing = await sftpReaddir(conn, String(a.path || "/"), proxy, {
3031
+ recursive: a.recursive === true,
3032
+ maxDepth: typeof a.maxDepth === "number" ? a.maxDepth : void 0,
3033
+ pattern: typeof a.pattern === "string" ? a.pattern : void 0,
3034
+ maxResults: typeof a.maxResults === "number" ? a.maxResults : void 0
3035
+ });
2905
3036
  return { content: [{ type: "text", text: listing }] };
2906
3037
  }
2907
3038
  case "sftp-read": {
@@ -2922,16 +3053,109 @@ ${result.stderr}`);
2922
3053
  }
2923
3054
  // ----- Docker -----
2924
3055
  case "docker-list": {
3056
+ const format = a.format === "json" ? "json" : "table";
3057
+ const composeOnly = a.composeOnly === true;
3058
+ const filterArg = composeOnly ? ' --filter "label=com.docker.compose.project"' : "";
3059
+ const fmtArg = format === "json" ? ` --format '{{json .}}'` : (
3060
+ // Add the compose project as the last column. Docker's --format
3061
+ // template language uses {{ index .Labels "key" }} for label lookup.
3062
+ ` --format 'table {{.Names}} {{.Image}} {{.Status}} {{.Ports}} {{ index .Labels "com.docker.compose.project" }}'`
3063
+ );
3064
+ const cmd = `docker ps -a${filterArg}${fmtArg}`;
2925
3065
  const { conn, proxy } = await getServerConnection(String(a.serverId));
2926
- const result = await sshExec(conn, 'docker ps -a --format "table {{.Names}} {{.Image}} {{.Status}} {{.Ports}}"', proxy);
3066
+ const result = await sshExec(conn, cmd, proxy);
2927
3067
  return { content: [{ type: "text", text: result.exitCode === 0 ? result.stdout : `Error: ${result.stderr}` }] };
2928
3068
  }
2929
3069
  case "docker-logs": {
2930
3070
  const container = String(a.containerName).replace(/[^a-zA-Z0-9._-]/g, "");
2931
3071
  const lines = Number(a.lines) || 100;
3072
+ const sinceRaw = typeof a.since === "string" ? a.since.trim() : "";
3073
+ const grepRaw = typeof a.grep === "string" ? a.grep : "";
3074
+ let sinceArg = "";
3075
+ if (sinceRaw) {
3076
+ if (!/^\d+[smhd]$/i.test(sinceRaw) && !/^\d{4}-\d{2}-\d{2}/.test(sinceRaw)) {
3077
+ return { content: [{ type: "text", text: 'Error: invalid `since` format (expected e.g. "10m", "2h", or ISO timestamp)' }] };
3078
+ }
3079
+ sinceArg = ` --since ${posixQuote(sinceRaw)}`;
3080
+ }
3081
+ const grepSuffix = grepRaw ? ` | grep -i -E ${posixQuote(grepRaw)}` : "";
3082
+ const cmd = `docker logs --tail ${lines}${sinceArg} ${container} 2>&1${grepSuffix}`;
2932
3083
  const { conn, proxy } = await getServerConnection(String(a.serverId));
2933
- const result = await sshExec(conn, `docker logs --tail ${lines} ${container} 2>&1`, proxy);
2934
- return { content: [{ type: "text", text: result.exitCode === 0 ? result.stdout : `Error: ${result.stderr}` }] };
3084
+ const result = await sshExec(conn, cmd, proxy);
3085
+ if (result.exitCode !== 0 && !(grepRaw && result.exitCode === 1)) {
3086
+ return { content: [{ type: "text", text: `Error (exit ${result.exitCode}): ${result.stderr || result.stdout}` }] };
3087
+ }
3088
+ return { content: [{ type: "text", text: result.stdout || "(no log lines matched)" }] };
3089
+ }
3090
+ case "docker-exec": {
3091
+ const container = String(a.container).replace(/[^a-zA-Z0-9._-]/g, "");
3092
+ if (!container) return { content: [{ type: "text", text: "Error: invalid container name" }] };
3093
+ const command = String(a.command);
3094
+ const args2 = Array.isArray(a.args) ? a.args.map(String) : [];
3095
+ const stdin = typeof a.stdin === "string" ? a.stdin : void 0;
3096
+ const workdir = typeof a.workdir === "string" && a.workdir ? ["-w", a.workdir] : [];
3097
+ const user = typeof a.user === "string" && a.user ? ["-u", a.user] : [];
3098
+ const stdinFlag = stdin !== void 0 ? ["-i"] : [];
3099
+ const dockerArgs = [...stdinFlag, ...workdir, ...user, container, command, ...args2];
3100
+ const fullCmd = buildPosixCommand("docker", ["exec", ...dockerArgs]);
3101
+ const { conn, proxy } = await getServerConnection(String(a.serverId));
3102
+ if (a.timeout) conn.timeout = Number(a.timeout);
3103
+ const result = await sshExec(conn, fullCmd, proxy, stdin !== void 0 ? { stdin } : void 0);
3104
+ const output = [`Exit code: ${result.exitCode}`];
3105
+ if (result.stdout) output.push(`--- stdout ---
3106
+ ${result.stdout}`);
3107
+ if (result.stderr) output.push(`--- stderr ---
3108
+ ${result.stderr}`);
3109
+ return { content: [{ type: "text", text: output.join("\n") }] };
3110
+ }
3111
+ case "docker-compose": {
3112
+ const projectPath = String(a.projectPath);
3113
+ if (!projectPath || !projectPath.startsWith("/")) {
3114
+ return { content: [{ type: "text", text: "Error: projectPath must be an absolute path" }] };
3115
+ }
3116
+ const action = String(a.action);
3117
+ const allowedActions = ["up", "down", "restart", "logs", "ps", "pull", "build"];
3118
+ if (!allowedActions.includes(action)) {
3119
+ return { content: [{ type: "text", text: `Error: invalid action (allowed: ${allowedActions.join(", ")})` }] };
3120
+ }
3121
+ const service = typeof a.service === "string" && a.service ? a.service : "";
3122
+ const tail = Number(a.tail) > 0 ? Number(a.tail) : 200;
3123
+ let composeArgs;
3124
+ switch (action) {
3125
+ case "up":
3126
+ composeArgs = service ? ["up", "-d", service] : ["up", "-d"];
3127
+ break;
3128
+ case "down":
3129
+ composeArgs = service ? ["down", service] : ["down"];
3130
+ break;
3131
+ case "restart":
3132
+ composeArgs = service ? ["restart", service] : ["restart"];
3133
+ break;
3134
+ case "logs":
3135
+ composeArgs = service ? ["logs", "--no-color", `--tail=${tail}`, service] : ["logs", "--no-color", `--tail=${tail}`];
3136
+ break;
3137
+ case "ps":
3138
+ composeArgs = service ? ["ps", service] : ["ps"];
3139
+ break;
3140
+ case "pull":
3141
+ composeArgs = service ? ["pull", service] : ["pull"];
3142
+ break;
3143
+ case "build":
3144
+ composeArgs = service ? ["build", service] : ["build"];
3145
+ break;
3146
+ default:
3147
+ composeArgs = [];
3148
+ }
3149
+ const composeCmd = buildPosixCommand("docker", ["compose", ...composeArgs]);
3150
+ const fullCmd = `cd ${posixQuote(projectPath)} && ${composeCmd} 2>&1`;
3151
+ const { conn, proxy } = await getServerConnection(String(a.serverId));
3152
+ conn.timeout = Number(a.timeout) > 0 ? Number(a.timeout) : 12e4;
3153
+ const result = await sshExec(conn, fullCmd, proxy);
3154
+ const output = [`Exit code: ${result.exitCode} (compose ${action}${service ? ` ${service}` : ""} @ ${projectPath})`];
3155
+ if (result.stdout) output.push(result.stdout);
3156
+ if (result.stderr) output.push(`--- stderr ---
3157
+ ${result.stderr}`);
3158
+ return { content: [{ type: "text", text: output.join("\n") }] };
2935
3159
  }
2936
3160
  // ----- Database -----
2937
3161
  case "db-discover": {