@cloudgrid-io/mcp 0.4.3 → 0.4.4
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/package.json +2 -1
- package/src/tools.js +45 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudgrid-io/mcp",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"description": "MCP server for CloudGrid. Two editions: a local stdio server (full toolset) and a hosted web server (light, CLI-free toolset) over MCP Streamable HTTP.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"test:auth": "node test/auth.test.mjs"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
+
"@cloudgrid-io/cli": "^0.9.20",
|
|
28
29
|
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
29
30
|
"express": "^4.22.2",
|
|
30
31
|
"zod": "^3.23.0"
|
package/src/tools.js
CHANGED
|
@@ -9,10 +9,11 @@
|
|
|
9
9
|
// The difference is injected as a `ctx` object, so the tool logic is written once.
|
|
10
10
|
|
|
11
11
|
import { execFile } from "node:child_process";
|
|
12
|
+
import { createRequire } from "node:module";
|
|
12
13
|
import { promisify } from "node:util";
|
|
13
14
|
import { readFile } from "node:fs/promises";
|
|
14
15
|
import { readFileSync, existsSync, statSync } from "node:fs";
|
|
15
|
-
import { basename, resolve } from "node:path";
|
|
16
|
+
import { basename, dirname, resolve, join } from "node:path";
|
|
16
17
|
import { z } from "zod";
|
|
17
18
|
import { newLoginCode, buildLoginUrl, pollStatusOnce, decodeJwt } from "./auth.js";
|
|
18
19
|
|
|
@@ -74,15 +75,52 @@ function resolveCwd(cwd) {
|
|
|
74
75
|
return abs;
|
|
75
76
|
}
|
|
76
77
|
|
|
78
|
+
// Resolve the bundled CLI entry point from this package's own node_modules.
|
|
79
|
+
// Returns the absolute path to the JS entry, or null if unresolvable.
|
|
80
|
+
function resolveBundledCli() {
|
|
81
|
+
try {
|
|
82
|
+
const require = createRequire(import.meta.url);
|
|
83
|
+
const pkgPath = require.resolve("@cloudgrid-io/cli/package.json");
|
|
84
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
85
|
+
const bin = pkg.bin && pkg.bin.cloudgrid;
|
|
86
|
+
if (!bin) return null;
|
|
87
|
+
return join(dirname(pkgPath), bin);
|
|
88
|
+
} catch {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
77
93
|
async function runCloudgrid(args, opts = {}) {
|
|
78
94
|
const cwd = resolveCwd(opts.cwd);
|
|
95
|
+
const execOpts = {
|
|
96
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
97
|
+
timeout: 10 * 60 * 1000,
|
|
98
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
99
|
+
...(cwd ? { cwd } : {}),
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// 1. Try the bundled CLI (node <cliEntry> ...args)
|
|
103
|
+
const bundled = resolveBundledCli();
|
|
104
|
+
if (bundled) {
|
|
105
|
+
try {
|
|
106
|
+
const { stdout, stderr } = await execFileAsync(
|
|
107
|
+
process.execPath,
|
|
108
|
+
[bundled, ...args],
|
|
109
|
+
execOpts,
|
|
110
|
+
);
|
|
111
|
+
return (stdout || stderr || "").trim() || "Done.";
|
|
112
|
+
} catch (err) {
|
|
113
|
+
const detail = [err && err.stdout, err && err.stderr, err && err.message]
|
|
114
|
+
.filter(Boolean)
|
|
115
|
+
.join("\n")
|
|
116
|
+
.trim();
|
|
117
|
+
throw new Error(detail || "cloudgrid command failed");
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// 2. Fallback: global `cloudgrid` on PATH
|
|
79
122
|
try {
|
|
80
|
-
const { stdout, stderr } = await execFileAsync("cloudgrid", args,
|
|
81
|
-
maxBuffer: 16 * 1024 * 1024,
|
|
82
|
-
timeout: 10 * 60 * 1000,
|
|
83
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
84
|
-
...(cwd ? { cwd } : {}),
|
|
85
|
-
});
|
|
123
|
+
const { stdout, stderr } = await execFileAsync("cloudgrid", args, execOpts);
|
|
86
124
|
return (stdout || stderr || "").trim() || "Done.";
|
|
87
125
|
} catch (err) {
|
|
88
126
|
if (err && err.code === "ENOENT") {
|