@zero-gravity/zero-gravity 0.0.0-stage → 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/CHANGELOG.md +29 -0
- package/LICENSE +21 -0
- package/README.md +50 -2
- package/THIRD-PARTY-NOTICES.md +100 -0
- package/dist/adv-context-SLTP32JQ.js +36 -0
- package/dist/advanced-EPLZB6DG.js +164 -0
- package/dist/agents-JYRQHH7R.js +181 -0
- package/dist/chat-AEHVCKXX.js +47 -0
- package/dist/chunk-2OH5KHWO.js +112 -0
- package/dist/chunk-2ZYSAYMJ.js +108 -0
- package/dist/chunk-4BZ4IXTO.js +161 -0
- package/dist/chunk-4ITJY25Z.js +144 -0
- package/dist/chunk-4JBLZQAQ.js +65 -0
- package/dist/chunk-6QLYRU3N.js +28 -0
- package/dist/chunk-7TACFVY2.js +57 -0
- package/dist/chunk-AY36KJTH.js +3023 -0
- package/dist/chunk-BJABQO7S.js +378 -0
- package/dist/chunk-C2GFK4JP.js +387 -0
- package/dist/chunk-CDC2K2KP.js +47 -0
- package/dist/chunk-DKCCXMSE.js +27 -0
- package/dist/chunk-FC3UOHOO.js +194 -0
- package/dist/chunk-FIASMDLX.js +216 -0
- package/dist/chunk-GMVDCQVW.js +88 -0
- package/dist/chunk-JQYZX56A.js +231 -0
- package/dist/chunk-JU5PGDOD.js +138 -0
- package/dist/chunk-JUZP5SXD.js +309 -0
- package/dist/chunk-KGA7VWQG.js +70 -0
- package/dist/chunk-L7VNR5LM.js +407 -0
- package/dist/chunk-LOSXCWHU.js +145 -0
- package/dist/chunk-NVC433AX.js +24 -0
- package/dist/chunk-QH27MDJM.js +248 -0
- package/dist/chunk-QUC5URWQ.js +708 -0
- package/dist/chunk-R2CPYTSP.js +31 -0
- package/dist/chunk-R5KQACGR.js +2833 -0
- package/dist/chunk-R6DONQKN.js +153 -0
- package/dist/chunk-RIX4S3J7.js +4747 -0
- package/dist/chunk-SZKAZ2VN.js +35 -0
- package/dist/chunk-T6DDNE3W.js +1338 -0
- package/dist/chunk-U4URD6TU.js +4605 -0
- package/dist/chunk-U5UIUB6L.js +51 -0
- package/dist/chunk-UMC77TR3.js +79 -0
- package/dist/chunk-UQURXFAE.js +80 -0
- package/dist/chunk-VBG7T7XY.js +1703 -0
- package/dist/chunk-VCCMJIAG.js +326 -0
- package/dist/chunk-VS375NYD.js +91 -0
- package/dist/chunk-WANZOLI5.js +1073 -0
- package/dist/chunk-WUF3TVAE.js +51 -0
- package/dist/chunk-XCWLFZSM.js +149 -0
- package/dist/chunk-YJEUXO5I.js +76 -0
- package/dist/chunk-YR6RCC6Y.js +894 -0
- package/dist/chunk-ZQFAX275.js +35 -0
- package/dist/config-ELG4FQ3K.js +30 -0
- package/dist/config-IEWRCG7R.js +50 -0
- package/dist/doctor-ZZC2D3RW.js +357 -0
- package/dist/ext-context-RIMZMEPB.js +37 -0
- package/dist/index.js +20 -0
- package/dist/init-UB3E47KM.js +22 -0
- package/dist/integrations-HW4VTLN4.js +183 -0
- package/dist/main-RAWWT22W.js +115 -0
- package/dist/mcp-SWD4SO35.js +232 -0
- package/dist/mcp-context-PM5FY665.js +28 -0
- package/dist/memory-QQ54GRCN.js +128 -0
- package/dist/memory-session-R6DGT6CS.js +14 -0
- package/dist/memory-summary-4P26B2ZY.js +18 -0
- package/dist/plugins-VUGTEUNV.js +166 -0
- package/dist/providers-O3WOVP5Q.js +417 -0
- package/dist/report-DDIZ6BLF.js +28 -0
- package/dist/sec-context-VQHW6TOZ.js +15 -0
- package/dist/security-SAYW4LU4.js +95 -0
- package/dist/sessions-CL6CRNQL.js +160 -0
- package/dist/skills-7KDGTTKX.js +126 -0
- package/dist/version-6E6A23B3.js +13 -0
- package/package.json +70 -4
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
McpServerSchema,
|
|
4
|
+
mcpServerName
|
|
5
|
+
} from "./chunk-QH27MDJM.js";
|
|
6
|
+
import {
|
|
7
|
+
looksLikeSecretValue,
|
|
8
|
+
redactSecrets
|
|
9
|
+
} from "./chunk-WUF3TVAE.js";
|
|
10
|
+
|
|
11
|
+
// src/mcp/errors.ts
|
|
12
|
+
var McpError = class extends Error {
|
|
13
|
+
code;
|
|
14
|
+
hint;
|
|
15
|
+
constructor(code, message, hint) {
|
|
16
|
+
super(redactSecrets(message));
|
|
17
|
+
this.name = "McpError";
|
|
18
|
+
this.code = code;
|
|
19
|
+
this.hint = hint === void 0 ? void 0 : redactSecrets(hint);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
function toMcpError(err, fallback = "protocol") {
|
|
23
|
+
if (err instanceof McpError) return err;
|
|
24
|
+
const e = err;
|
|
25
|
+
const raw = typeof e?.message === "string" ? e.message : "unknown error";
|
|
26
|
+
const msg = redactSecrets(raw).replace(/\s+/g, " ").slice(0, 300);
|
|
27
|
+
if (e?.name === "AbortError" || /abort/i.test(msg)) return new McpError("cancelled", "The request was cancelled.");
|
|
28
|
+
if (e?.name === "UnauthorizedError" || /\b401\b|unauthori[sz]ed/i.test(msg)) return new McpError("auth-required", "The server asked for authentication.", "Reconnect it with: zg mcp connect <server> (OAuth), or check the credential variable.");
|
|
29
|
+
if (/\b403\b|forbidden/i.test(msg)) return new McpError("auth-failed", "The server refused access (forbidden).", "Check the account, scopes and permissions you granted.");
|
|
30
|
+
if (e?.code === "ENOENT" || /ENOENT/.test(msg)) return new McpError("missing-executable", "The server program was not found.", "Install it, or check the command with: zg mcp inspect <server>");
|
|
31
|
+
if (e?.code === -32001 || /timed? ?out/i.test(msg)) return new McpError("timeout", "The server did not answer in time.");
|
|
32
|
+
if (/connection closed|closed/i.test(msg) && fallback !== "closed") return new McpError("closed", "The server connection closed.");
|
|
33
|
+
return new McpError(fallback, msg);
|
|
34
|
+
}
|
|
35
|
+
function describeMcpError(err) {
|
|
36
|
+
const e = err instanceof McpError ? err : toMcpError(err);
|
|
37
|
+
return e.hint ? `${e.message} ${e.hint}` : e.message;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// src/mcp/config.ts
|
|
41
|
+
var SHELL_CHARS = /[;|&$`<>(){}*?!"'\n\r]/;
|
|
42
|
+
var WORD_BREAKERS = /[\s\\]/;
|
|
43
|
+
var ABSOLUTE_PATH = /^(?:\/|[A-Za-z]:[\\/]|\\\\)/;
|
|
44
|
+
var isPlainCommand = (c) => !SHELL_CHARS.test(c) && (!WORD_BREAKERS.test(c) || ABSOLUTE_PATH.test(c));
|
|
45
|
+
function validateServerName(name) {
|
|
46
|
+
const r = mcpServerName.safeParse(name);
|
|
47
|
+
if (!r.success) throw new McpError("invalid-config", `"${name.slice(0, 50)}" is not a valid server name: ${r.error.issues[0]?.message ?? "invalid"}.`);
|
|
48
|
+
return r.data;
|
|
49
|
+
}
|
|
50
|
+
var LOCAL_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]", "::1"]);
|
|
51
|
+
function validateServerUrl(raw) {
|
|
52
|
+
let u;
|
|
53
|
+
try {
|
|
54
|
+
u = new URL(raw);
|
|
55
|
+
} catch {
|
|
56
|
+
throw new McpError("invalid-config", "The server URL is not a valid URL.");
|
|
57
|
+
}
|
|
58
|
+
if (u.protocol !== "https:" && !(u.protocol === "http:" && LOCAL_HOSTS.has(u.hostname))) {
|
|
59
|
+
throw new McpError("invalid-config", "The server URL must use https (plain http is only allowed for localhost).", "Streamable HTTP servers on the internet must use TLS.");
|
|
60
|
+
}
|
|
61
|
+
if (u.username !== "" || u.password !== "") throw new McpError("invalid-config", "The server URL must not contain a user name or password.", "Use an environment variable for the credential instead.");
|
|
62
|
+
for (const [k, v] of u.searchParams) {
|
|
63
|
+
if (looksLikeSecretValue(v) || /(key|secret|token|passw|auth)/i.test(k)) throw new McpError("invalid-config", "The server URL must not carry a credential in its query string.", "Use an environment variable reference instead.");
|
|
64
|
+
}
|
|
65
|
+
if (u.hash !== "") u.hash = "";
|
|
66
|
+
return u.toString();
|
|
67
|
+
}
|
|
68
|
+
function validateServer(input) {
|
|
69
|
+
const parsed = McpServerSchema.safeParse(input);
|
|
70
|
+
if (!parsed.success) throw new McpError("invalid-config", `Invalid server settings: ${parsed.error.issues.slice(0, 3).map((i) => `${i.path.join(".") || "server"}: ${i.message}`).join("; ")}`);
|
|
71
|
+
const v = parsed.data;
|
|
72
|
+
if (v.command !== void 0) {
|
|
73
|
+
if (!isPlainCommand(v.command)) throw new McpError("invalid-config", "The command must be one program name or path, with no spaces or shell characters.", "Put arguments in --arg options. zg starts servers without a shell.");
|
|
74
|
+
}
|
|
75
|
+
for (const [k, h] of [...Object.entries(v.env), ...v.credentialEnv ? [["credentialEnv", v.credentialEnv]] : []]) {
|
|
76
|
+
if (looksLikeSecretValue(h) || looksLikeSecretValue(k)) throw new McpError("invalid-config", "An environment setting holds what looks like a credential instead of a variable NAME. It was not saved.", "Give the NAME of a variable in your own environment (zg never stores values).");
|
|
77
|
+
}
|
|
78
|
+
for (const a of v.args) {
|
|
79
|
+
if (looksLikeSecretValue(a)) throw new McpError("invalid-config", "An argument looks like a credential. It was not saved.", "Pass secrets through an environment variable reference (--env NAME=HOSTVAR).");
|
|
80
|
+
if (a.includes("\0")) throw new McpError("invalid-config", "An argument contains an invalid character.");
|
|
81
|
+
}
|
|
82
|
+
if (v.url !== void 0) return { ...v, url: validateServerUrl(v.url) };
|
|
83
|
+
return v;
|
|
84
|
+
}
|
|
85
|
+
function addServer(s, name, server, opts = {}) {
|
|
86
|
+
const n = validateServerName(name);
|
|
87
|
+
if (s.servers[n] && opts.replace !== true) throw new McpError("exists", `A server named "${n}" already exists. Nothing was changed.`, "Choose another name, or remove it first: zg mcp remove " + n);
|
|
88
|
+
return { ...s, servers: { ...s.servers, [n]: validateServer(server) } };
|
|
89
|
+
}
|
|
90
|
+
function getServer(s, name) {
|
|
91
|
+
const v = s.servers[name];
|
|
92
|
+
if (!v) throw new McpError("unknown-server", `No MCP server named "${name.slice(0, 50)}".`, "List them with: zg mcp list");
|
|
93
|
+
return v;
|
|
94
|
+
}
|
|
95
|
+
function updateServer(s, name, patch) {
|
|
96
|
+
const cur = getServer(s, name);
|
|
97
|
+
return { ...s, servers: { ...s.servers, [name]: validateServer({ ...cur, ...patch }) } };
|
|
98
|
+
}
|
|
99
|
+
function removeServer(s, name) {
|
|
100
|
+
getServer(s, name);
|
|
101
|
+
const { [name]: _gone, ...rest } = s.servers;
|
|
102
|
+
void _gone;
|
|
103
|
+
return { ...s, servers: rest };
|
|
104
|
+
}
|
|
105
|
+
function setToolPolicy(s, server, tool, policy) {
|
|
106
|
+
const cur = getServer(s, server);
|
|
107
|
+
const toolPolicy = { ...cur.toolPolicy };
|
|
108
|
+
if (policy === null) delete toolPolicy[tool];
|
|
109
|
+
else toolPolicy[tool] = policy;
|
|
110
|
+
return updateServer(s, server, { toolPolicy });
|
|
111
|
+
}
|
|
112
|
+
function safeUrl(raw) {
|
|
113
|
+
try {
|
|
114
|
+
const u = new URL(raw);
|
|
115
|
+
u.username = "";
|
|
116
|
+
u.password = "";
|
|
117
|
+
for (const k of [...u.searchParams.keys()]) u.searchParams.set(k, "\u2026");
|
|
118
|
+
return redactSecrets(u.toString());
|
|
119
|
+
} catch {
|
|
120
|
+
return "(invalid url)";
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function describeTarget(v) {
|
|
124
|
+
if (v.transport === "http") return safeUrl(v.url ?? "");
|
|
125
|
+
return redactSecrets([v.command ?? "", ...v.args].join(" ")).slice(0, 300);
|
|
126
|
+
}
|
|
127
|
+
function describeServerLines(name, v) {
|
|
128
|
+
const lines = [`${name} [${v.transport}] ${v.enabled ? "enabled" : "disabled"}${v.integration ? ` (integration: ${v.integration})` : ""}`, ` target: ${describeTarget(v)}`];
|
|
129
|
+
const env = Object.entries(v.env);
|
|
130
|
+
if (env.length > 0) lines.push(` env (names only): ${env.map(([k, h]) => k === h ? k : `${k}<-${h}`).join(", ")}`);
|
|
131
|
+
lines.push(` auth: ${v.authMethod}${v.credentialEnv ? ` (variable ${v.credentialEnv})` : ""}`);
|
|
132
|
+
if (v.projectPath) lines.push(` only in project: ${v.projectPath}`);
|
|
133
|
+
const tp = Object.entries(v.toolPolicy);
|
|
134
|
+
if (tp.length > 0) lines.push(` tool decisions: ${tp.map(([t, p]) => `${t}=${p}`).join(", ")}`);
|
|
135
|
+
return lines;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export {
|
|
139
|
+
McpError,
|
|
140
|
+
toMcpError,
|
|
141
|
+
describeMcpError,
|
|
142
|
+
validateServerName,
|
|
143
|
+
validateServerUrl,
|
|
144
|
+
validateServer,
|
|
145
|
+
addServer,
|
|
146
|
+
getServer,
|
|
147
|
+
updateServer,
|
|
148
|
+
removeServer,
|
|
149
|
+
setToolPolicy,
|
|
150
|
+
safeUrl,
|
|
151
|
+
describeTarget,
|
|
152
|
+
describeServerLines
|
|
153
|
+
};
|