@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,1338 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
CATEGORIES,
|
|
4
|
+
PromptManager,
|
|
5
|
+
ResourceManager
|
|
6
|
+
} from "./chunk-2OH5KHWO.js";
|
|
7
|
+
import {
|
|
8
|
+
classifyTool,
|
|
9
|
+
createHttpTransport,
|
|
10
|
+
createStdioTransport,
|
|
11
|
+
resolveCommand
|
|
12
|
+
} from "./chunk-2ZYSAYMJ.js";
|
|
13
|
+
import {
|
|
14
|
+
atomicWriteFile,
|
|
15
|
+
readTextFileIfExists
|
|
16
|
+
} from "./chunk-U5UIUB6L.js";
|
|
17
|
+
import {
|
|
18
|
+
VERSION
|
|
19
|
+
} from "./chunk-GMVDCQVW.js";
|
|
20
|
+
import {
|
|
21
|
+
McpError,
|
|
22
|
+
addServer,
|
|
23
|
+
describeMcpError,
|
|
24
|
+
describeTarget,
|
|
25
|
+
getServer,
|
|
26
|
+
removeServer,
|
|
27
|
+
setToolPolicy,
|
|
28
|
+
toMcpError,
|
|
29
|
+
updateServer,
|
|
30
|
+
validateServer,
|
|
31
|
+
validateServerName
|
|
32
|
+
} from "./chunk-R6DONQKN.js";
|
|
33
|
+
import {
|
|
34
|
+
ZgError
|
|
35
|
+
} from "./chunk-FC3UOHOO.js";
|
|
36
|
+
import {
|
|
37
|
+
looksLikeSecretValue,
|
|
38
|
+
redactSecrets
|
|
39
|
+
} from "./chunk-WUF3TVAE.js";
|
|
40
|
+
|
|
41
|
+
// src/mcp/auth.ts
|
|
42
|
+
import { randomBytes } from "crypto";
|
|
43
|
+
import http from "http";
|
|
44
|
+
import path from "path";
|
|
45
|
+
import { rm } from "fs/promises";
|
|
46
|
+
var TokenStore = class {
|
|
47
|
+
#dir;
|
|
48
|
+
constructor(configDir) {
|
|
49
|
+
this.#dir = path.join(configDir, "mcp", "auth");
|
|
50
|
+
}
|
|
51
|
+
file(server) {
|
|
52
|
+
if (!/^[a-z0-9][a-z0-9_-]{0,39}$/.test(server)) throw new McpError("invalid-config", "Invalid server name.");
|
|
53
|
+
return path.join(this.#dir, `${server}.json`);
|
|
54
|
+
}
|
|
55
|
+
async read(server) {
|
|
56
|
+
try {
|
|
57
|
+
const t = await readTextFileIfExists(this.file(server));
|
|
58
|
+
return t ? JSON.parse(t) : {};
|
|
59
|
+
} catch {
|
|
60
|
+
return {};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async write(server, data) {
|
|
64
|
+
await atomicWriteFile(this.file(server), JSON.stringify(data));
|
|
65
|
+
}
|
|
66
|
+
async update(server, patch) {
|
|
67
|
+
await this.write(server, { ...await this.read(server), ...patch });
|
|
68
|
+
}
|
|
69
|
+
/** Revocation locally: the credentials are deleted. (Revoking at the service itself is done in that service's settings.) */
|
|
70
|
+
async remove(server) {
|
|
71
|
+
const had = (await this.read(server)).tokens !== void 0 || (await this.read(server)).clientInformation !== void 0;
|
|
72
|
+
await rm(this.file(server), { force: true });
|
|
73
|
+
return had;
|
|
74
|
+
}
|
|
75
|
+
async hasTokens(server) {
|
|
76
|
+
return (await this.read(server)).tokens !== void 0;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
var FileOAuthProvider = class {
|
|
80
|
+
#store;
|
|
81
|
+
#server;
|
|
82
|
+
#redirect;
|
|
83
|
+
#onUrl;
|
|
84
|
+
#state = null;
|
|
85
|
+
constructor(store, server, redirectUrl, onUrl) {
|
|
86
|
+
this.#store = store;
|
|
87
|
+
this.#server = server;
|
|
88
|
+
this.#redirect = redirectUrl;
|
|
89
|
+
this.#onUrl = onUrl;
|
|
90
|
+
}
|
|
91
|
+
get redirectUrl() {
|
|
92
|
+
return this.#redirect;
|
|
93
|
+
}
|
|
94
|
+
get clientMetadata() {
|
|
95
|
+
return { client_name: "ZERO GRAVITY (zg)", redirect_uris: [this.#redirect], grant_types: ["authorization_code", "refresh_token"], response_types: ["code"], token_endpoint_auth_method: "none" };
|
|
96
|
+
}
|
|
97
|
+
state() {
|
|
98
|
+
this.#state = randomBytes(32).toString("hex");
|
|
99
|
+
return this.#state;
|
|
100
|
+
}
|
|
101
|
+
expectedState() {
|
|
102
|
+
return this.#state;
|
|
103
|
+
}
|
|
104
|
+
async clientInformation() {
|
|
105
|
+
return (await this.#store.read(this.#server)).clientInformation;
|
|
106
|
+
}
|
|
107
|
+
async saveClientInformation(i) {
|
|
108
|
+
await this.#store.update(this.#server, { clientInformation: i });
|
|
109
|
+
}
|
|
110
|
+
async tokens() {
|
|
111
|
+
return (await this.#store.read(this.#server)).tokens;
|
|
112
|
+
}
|
|
113
|
+
async saveTokens(t) {
|
|
114
|
+
await this.#store.update(this.#server, { tokens: t });
|
|
115
|
+
}
|
|
116
|
+
redirectToAuthorization(url) {
|
|
117
|
+
this.#onUrl?.(url.toString());
|
|
118
|
+
}
|
|
119
|
+
async saveCodeVerifier(v) {
|
|
120
|
+
await this.#store.update(this.#server, { codeVerifier: v });
|
|
121
|
+
}
|
|
122
|
+
async codeVerifier() {
|
|
123
|
+
const v = (await this.#store.read(this.#server)).codeVerifier;
|
|
124
|
+
if (!v) throw new McpError("auth-failed", "The sign-in was not started from this computer.");
|
|
125
|
+
return v;
|
|
126
|
+
}
|
|
127
|
+
async invalidateCredentials(scope) {
|
|
128
|
+
const cur = await this.#store.read(this.#server);
|
|
129
|
+
if (scope === "all") return void await this.#store.remove(this.#server);
|
|
130
|
+
if (scope === "tokens") delete cur.tokens;
|
|
131
|
+
if (scope === "client") delete cur.clientInformation;
|
|
132
|
+
if (scope === "verifier") delete cur.codeVerifier;
|
|
133
|
+
await this.#store.write(this.#server, cur);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
function parseCallback(input, expectedState) {
|
|
137
|
+
let params;
|
|
138
|
+
const t = input.trim();
|
|
139
|
+
try {
|
|
140
|
+
params = new URL(t).searchParams;
|
|
141
|
+
} catch {
|
|
142
|
+
params = new URLSearchParams(t.replace(/^\?/, ""));
|
|
143
|
+
}
|
|
144
|
+
const err = params.get("error");
|
|
145
|
+
if (err) throw new McpError("auth-failed", `The service refused the sign-in (${err.replace(/[^\w.-]/g, "").slice(0, 60)}).`);
|
|
146
|
+
const code = params.get("code");
|
|
147
|
+
const state = params.get("state");
|
|
148
|
+
if (!expectedState || state !== expectedState) throw new McpError("auth-failed", "The sign-in answer did not match this request (state check failed), so it was ignored.", "Start again: zg mcp connect <server>");
|
|
149
|
+
if (!code) throw new McpError("auth-failed", "The sign-in answer had no authorization code.");
|
|
150
|
+
return { code };
|
|
151
|
+
}
|
|
152
|
+
function waitForCallback(server, expectedState, signal) {
|
|
153
|
+
return new Promise((resolve, reject) => {
|
|
154
|
+
const onAbort = () => reject(new McpError("cancelled", "Sign-in cancelled or timed out."));
|
|
155
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
156
|
+
server.on("request", (req, res) => {
|
|
157
|
+
try {
|
|
158
|
+
if (req.method !== "GET" || !req.url?.startsWith("/callback")) {
|
|
159
|
+
res.writeHead(404).end();
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const out = parseCallback(`http://127.0.0.1${req.url}`, expectedState());
|
|
163
|
+
res.writeHead(200, { "content-type": "text/plain; charset=utf-8" }).end("Signed in. You can close this tab and return to zg.");
|
|
164
|
+
resolve(out);
|
|
165
|
+
} catch (e) {
|
|
166
|
+
res.writeHead(400, { "content-type": "text/plain; charset=utf-8" }).end("Sign-in failed. Return to zg.");
|
|
167
|
+
if (e instanceof McpError && e.message.includes("state check")) return;
|
|
168
|
+
reject(e);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
async function loginOAuth(store, serverName, opts) {
|
|
174
|
+
const srv = http.createServer();
|
|
175
|
+
await new Promise((resolve, reject) => {
|
|
176
|
+
srv.once("error", reject);
|
|
177
|
+
srv.listen(opts.port ?? 0, "127.0.0.1", () => resolve());
|
|
178
|
+
});
|
|
179
|
+
const port = srv.address().port;
|
|
180
|
+
const provider = new FileOAuthProvider(store, serverName, `http://127.0.0.1:${port}/callback`, opts.onUrl);
|
|
181
|
+
const ac = new AbortController();
|
|
182
|
+
const timer = setTimeout(() => ac.abort(), opts.timeoutMs ?? 3e5);
|
|
183
|
+
const onOuter = () => ac.abort();
|
|
184
|
+
opts.signal?.addEventListener("abort", onOuter, { once: true });
|
|
185
|
+
try {
|
|
186
|
+
await store.remove(serverName);
|
|
187
|
+
const { auth } = await import("@modelcontextprotocol/sdk/client/auth.js");
|
|
188
|
+
const first = await auth(provider, { serverUrl: opts.serverUrl });
|
|
189
|
+
if (first === "AUTHORIZED") return;
|
|
190
|
+
const waits = [waitForCallback(srv, () => provider.expectedState(), ac.signal)];
|
|
191
|
+
if (opts.manualInput) waits.push(opts.manualInput(ac.signal).then((t) => t === null ? new Promise(() => void 0) : parseCallback(t, provider.expectedState())));
|
|
192
|
+
const { code } = await Promise.race(waits);
|
|
193
|
+
const second = await auth(provider, { serverUrl: opts.serverUrl, authorizationCode: code });
|
|
194
|
+
if (second !== "AUTHORIZED") throw new McpError("auth-failed", "The sign-in did not complete.");
|
|
195
|
+
await store.update(serverName, { codeVerifier: void 0 });
|
|
196
|
+
} catch (err) {
|
|
197
|
+
throw err instanceof ZgError ? err : toMcpError(err, "auth-failed");
|
|
198
|
+
} finally {
|
|
199
|
+
clearTimeout(timer);
|
|
200
|
+
ac.abort();
|
|
201
|
+
opts.signal?.removeEventListener("abort", onOuter);
|
|
202
|
+
srv.close();
|
|
203
|
+
srv.closeAllConnections?.();
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function oauthProviderFor(store, server, serverUrl) {
|
|
207
|
+
void serverUrl;
|
|
208
|
+
return new FileOAuthProvider(store, server, "http://127.0.0.1:0/callback", null);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// src/mcp/catalog/integrations/cloud.ts
|
|
212
|
+
var CHECKED = "2026-11-28";
|
|
213
|
+
var REMOTE = { linux: "remote server; zg's HTTP client not tested against it", macos: "same", windows: "same", termux: "same" };
|
|
214
|
+
var NPX = { linux: "needs Node/npm (npx); not tested by zg", macos: "needs Node/npm (npx); not tested by zg", windows: "needs Node/npm (npx.cmd); not tested by zg", termux: "needs `pkg install nodejs`; not tested by zg" };
|
|
215
|
+
var CLOUD = [
|
|
216
|
+
{
|
|
217
|
+
id: "firebase",
|
|
218
|
+
name: "Firebase",
|
|
219
|
+
category: "cloud",
|
|
220
|
+
description: "Firebase's official MCP server, run locally through the Firebase CLI package.",
|
|
221
|
+
publisher: "official",
|
|
222
|
+
availability: "verified",
|
|
223
|
+
docs: ["https://firebase.google.com/docs/cli/mcp-server"],
|
|
224
|
+
access: ["Firebase projects reachable with your Firebase CLI login (Auth, Firestore, Storage, Functions, Hosting and more, per feature group)"],
|
|
225
|
+
auth: { kinds: ["cli-login"], note: "Uses the same credentials as the Firebase CLI (a logged-in user or Application Default Credentials). Sign in with `npx firebase-tools login` in your own terminal; zg never sees the credentials." },
|
|
226
|
+
permissions: ["Whatever your Firebase/Google account is allowed to do"],
|
|
227
|
+
capabilities: ["Feature groups: core, apphosting, auth, crashlytics, realtimedatabase, dataconnect, functions, messaging, remoteconfig, storage, firestore, developerknowledge"],
|
|
228
|
+
requires: ["Node.js and npm (npx)", "A project folder with firebase.json (or choose one at run time)"],
|
|
229
|
+
template: { transport: "stdio", command: "npx", args: ["-y", "firebase-tools@latest", "mcp"], authMethod: "none" },
|
|
230
|
+
warnings: ["npx downloads and runs the latest firebase-tools package. Use --only to limit feature groups (for example: --only firestore,auth).", "The server acts with YOUR Firebase permissions; zg asks before each tool call."],
|
|
231
|
+
platforms: NPX,
|
|
232
|
+
verification: { checked: CHECKED, sources: ["https://firebase.google.com/docs/cli/mcp-server"], verified: ["command and args", "auth model", "--dir and --only flags", "feature group names"], unverified: ["exact tool names (discover them after connecting)"] }
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
id: "supabase",
|
|
236
|
+
name: "Supabase",
|
|
237
|
+
category: "cloud",
|
|
238
|
+
description: "Supabase's official hosted MCP server (projects, SQL, migrations, docs).",
|
|
239
|
+
publisher: "official",
|
|
240
|
+
availability: "verified",
|
|
241
|
+
docs: ["https://supabase.com/docs/guides/ai-tools/mcp"],
|
|
242
|
+
repo: "https://github.com/supabase-community/supabase-mcp",
|
|
243
|
+
access: ["Your Supabase organisation or ONE project (when a project reference is given), including the database"],
|
|
244
|
+
auth: { kinds: ["oauth", "pat"], note: "Browser OAuth with dynamic client registration (no token needed), or a personal access token sent as a Bearer header for unattended use (zg reads it from SUPABASE_ACCESS_TOKEN)." },
|
|
245
|
+
permissions: ["Choose the organisation at sign-in", "For tokens: scope to the project and grant only the rights the enabled tools need"],
|
|
246
|
+
capabilities: ["Query parameters: read_only=true, project_ref=<id>, features=<groups>", "Feature groups include docs, account, database, debugging, development, functions, branching"],
|
|
247
|
+
requires: ["A Supabase account"],
|
|
248
|
+
template: { transport: "http", url: "https://mcp.supabase.com/mcp?read_only=true", authMethod: "oauth" },
|
|
249
|
+
prompts: [{ name: "project_ref", description: "Limit the server to ONE project (recommended). It is not a secret.", placeholder: "abcdefghijklmnop" }],
|
|
250
|
+
warnings: ["The template starts READ-ONLY and, when you give a project reference, project-scoped. Supabase advises against using this with production data or giving it to customers.", "Tool output can contain prompt-injection text; review before acting on it (Supabase's own advice)."],
|
|
251
|
+
platforms: REMOTE,
|
|
252
|
+
verification: { checked: CHECKED, sources: ["https://supabase.com/docs/guides/ai-tools/mcp"], verified: ["URL", "read_only / project_ref / features parameters", "OAuth DCR", "PAT header"], unverified: ["that dynamic registration accepts zg's loopback redirect (shown when you connect)"] }
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
id: "vercel",
|
|
256
|
+
name: "Vercel",
|
|
257
|
+
category: "cloud",
|
|
258
|
+
description: "Vercel's official remote MCP server (docs, projects, deployments, logs, analytics).",
|
|
259
|
+
publisher: "official",
|
|
260
|
+
availability: "restricted",
|
|
261
|
+
docs: ["https://vercel.com/docs/agent-resources/vercel-mcp"],
|
|
262
|
+
access: ["Your Vercel teams, projects and deployments with the SAME access as your Vercel user"],
|
|
263
|
+
auth: { kinds: ["oauth"], note: "OAuth with per-connection consent." },
|
|
264
|
+
permissions: ["Your Vercel user permissions"],
|
|
265
|
+
capabilities: ["Search docs, manage projects and deployments, analyse deployment logs, query web analytics (per Vercel's overview)"],
|
|
266
|
+
requires: ["A Vercel account"],
|
|
267
|
+
template: { transport: "http", url: "https://mcp.vercel.com", authMethod: "oauth" },
|
|
268
|
+
warnings: ["Vercel only allows MCP clients that are on its reviewed list or that identify themselves with a Client ID Metadata Document (CIMD). zg is neither, so Vercel may refuse the connection. zg will say so instead of claiming success.", "Deployments can be triggered from agents: review every call."],
|
|
269
|
+
platforms: REMOTE,
|
|
270
|
+
verification: { checked: CHECKED, sources: ["https://vercel.com/docs/agent-resources/vercel-mcp"], verified: ["URL", "OAuth", "client restriction (reviewed clients or CIMD)"], unverified: ["whether Vercel accepts zg; the tool list (see Vercel's tools reference)"] }
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
id: "cloudflare",
|
|
274
|
+
name: "Cloudflare",
|
|
275
|
+
category: "cloud",
|
|
276
|
+
description: "Cloudflare's official API MCP server (code-mode search/execute over the Cloudflare API).",
|
|
277
|
+
publisher: "official",
|
|
278
|
+
availability: "verified",
|
|
279
|
+
docs: ["https://developers.cloudflare.com/agents/model-context-protocol/cloudflare/servers-for-cloudflare/"],
|
|
280
|
+
access: ["Your Cloudflare account through the Cloudflare API, limited by the token or the OAuth grant"],
|
|
281
|
+
auth: { kinds: ["oauth", "api-token"], note: "OAuth, or a Cloudflare API token sent as a Bearer header (zg reads it from CLOUDFLARE_API_TOKEN). Create a token with only the permissions you need." },
|
|
282
|
+
permissions: ["A scoped API token (for example read-only on one zone)"],
|
|
283
|
+
capabilities: ["Generic 'code mode' server with search(), execute() and docs() tools (per Cloudflare's page)"],
|
|
284
|
+
requires: ["A Cloudflare account"],
|
|
285
|
+
template: { transport: "http", url: "https://mcp.cloudflare.com/mcp", authMethod: "env", credentialEnv: "CLOUDFLARE_API_TOKEN" },
|
|
286
|
+
warnings: ["execute() can run arbitrary Cloudflare API calls the token allows; zg treats it as a change and asks every time. Product-specific servers (docs, containers, browser, DEX, CASB) also exist; add them with zg mcp add."],
|
|
287
|
+
platforms: REMOTE,
|
|
288
|
+
verification: { checked: CHECKED, sources: ["https://developers.cloudflare.com/agents/model-context-protocol/cloudflare/servers-for-cloudflare/"], verified: ["URL", "Streamable HTTP", "OAuth or bearer API token", "tool names search/execute/docs"], unverified: ["per-product auth details"] }
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
id: "netlify",
|
|
292
|
+
name: "Netlify",
|
|
293
|
+
category: "cloud",
|
|
294
|
+
description: "Netlify's official MCP server (remote or local).",
|
|
295
|
+
publisher: "official",
|
|
296
|
+
availability: "restricted",
|
|
297
|
+
docs: ["https://docs.netlify.com/welcome/build-with-ai/netlify-mcp-server"],
|
|
298
|
+
repo: "https://github.com/netlify/netlify-mcp",
|
|
299
|
+
access: ["Your Netlify account and CLI capabilities, including draft and production deploys"],
|
|
300
|
+
auth: { kinds: ["oauth"], note: "Netlify's page only says to open the login link your agent gives you; the mechanism (OAuth discovery, token) is not documented there." },
|
|
301
|
+
permissions: ["Your Netlify account permissions"],
|
|
302
|
+
capabilities: ["Remote server https://mcp.netlify.com/mcp; local server via npx -y @netlify/mcp"],
|
|
303
|
+
requires: ["A Netlify account"],
|
|
304
|
+
template: { transport: "http", url: "https://mcp.netlify.com/mcp", authMethod: "oauth" },
|
|
305
|
+
warnings: ["How a generic client signs in was not documented, so the connection may fail; zg then reports the exact error.", "Agents can trigger production deploys: zg treats deploy tools as changes and asks every time."],
|
|
306
|
+
platforms: REMOTE,
|
|
307
|
+
verification: { checked: CHECKED, sources: ["https://docs.netlify.com/welcome/build-with-ai/netlify-mcp-server"], verified: ["remote URL", "local command name", "deploy capability"], unverified: ["authentication mechanism for third-party clients", "Node version for the local server"] }
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
id: "aws",
|
|
311
|
+
name: "AWS",
|
|
312
|
+
category: "cloud",
|
|
313
|
+
description: "AWS MCP Server (managed, IAM-authenticated) and the AWS Labs MCP servers.",
|
|
314
|
+
publisher: "official",
|
|
315
|
+
availability: "unverified-details",
|
|
316
|
+
docs: ["https://docs.aws.amazon.com/agent-toolkit/latest/userguide/mcp-server.md", "https://github.com/awslabs/mcp"],
|
|
317
|
+
repo: "https://github.com/awslabs/mcp",
|
|
318
|
+
access: ["Search AWS docs without authentication; API calls and scripts run with your IAM credentials"],
|
|
319
|
+
auth: { kinds: ["iam"], note: "Documentation says agents authenticate through your existing IAM credentials. How a generic client does that (request signing) was not verified." },
|
|
320
|
+
permissions: ["IAM permissions of the identity you use. Use a least-privilege role."],
|
|
321
|
+
capabilities: ["Documentation search, AWS API calls, sandboxed Python scripts, curated skills (per AWS's overview)"],
|
|
322
|
+
requires: ["AWS credentials"],
|
|
323
|
+
template: null,
|
|
324
|
+
warnings: ["The endpoint and the signing/proxy method were not confirmed in the documentation zg could read, so zg ships no configuration and will not guess one.", "Never give an agent broad IAM rights."],
|
|
325
|
+
platforms: { linux: PLAT(), macos: PLAT(), windows: PLAT(), termux: PLAT() },
|
|
326
|
+
verification: { checked: CHECKED, sources: ["https://docs.aws.amazon.com/agent-toolkit/latest/userguide/mcp-server.md"], verified: ["AWS publishes a managed MCP server", "IAM-based access"], unverified: ["endpoint", "transport", "proxy command", "required IAM actions"] }
|
|
327
|
+
}
|
|
328
|
+
];
|
|
329
|
+
function PLAT() {
|
|
330
|
+
return "not tested by zg";
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// src/mcp/catalog/integrations/data.ts
|
|
334
|
+
var CHECKED2 = "2026-11-28";
|
|
335
|
+
var NPX2 = { linux: "needs Node 22.13+ (per MongoDB); not tested by zg", macos: "needs Node 22.13+; not tested by zg", windows: "needs Node 22.13+; not tested by zg", termux: "needs a recent nodejs from pkg; not tested by zg" };
|
|
336
|
+
var NONE = { linux: "n/a", macos: "n/a", windows: "n/a", termux: "n/a" };
|
|
337
|
+
var DATA = [
|
|
338
|
+
{
|
|
339
|
+
id: "mongodb",
|
|
340
|
+
name: "MongoDB",
|
|
341
|
+
category: "database",
|
|
342
|
+
description: "MongoDB's official MCP server for databases and Atlas.",
|
|
343
|
+
publisher: "official",
|
|
344
|
+
availability: "verified",
|
|
345
|
+
docs: ["https://github.com/mongodb-js/mongodb-mcp-server"],
|
|
346
|
+
repo: "https://github.com/mongodb-js/mongodb-mcp-server",
|
|
347
|
+
access: ["The MongoDB deployment named by your connection string"],
|
|
348
|
+
auth: { kinds: ["connection-string"], note: "The connection string (which contains credentials) stays in YOUR environment variable; zg only stores the variable's name (default MDB_MCP_CONNECTION_STRING)." },
|
|
349
|
+
permissions: ["Use a database user with the least privileges needed (read-only for exploration)"],
|
|
350
|
+
capabilities: ["Read-only mode (--readOnly), confirmation-required tools such as drop-database, drop-collection, delete-many, drop-index (confirmation needs client elicitation, which zg does not offer)"],
|
|
351
|
+
requires: ["Node.js 22.13 or newer (per MongoDB's README)", "A connection string in your environment"],
|
|
352
|
+
template: { transport: "stdio", command: "npx", args: ["-y", "mongodb-mcp-server@latest", "--readOnly"], env: { MDB_MCP_CONNECTION_STRING: "MDB_MCP_CONNECTION_STRING" }, authMethod: "none" },
|
|
353
|
+
warnings: ["The template starts in --readOnly mode. zg does not support elicitation, so the server's own confirmation prompts cannot appear: zg's approval step is the confirmation.", "Remove --readOnly only if you really need writes, and keep a backup."],
|
|
354
|
+
platforms: NPX2,
|
|
355
|
+
verification: { checked: CHECKED2, sources: ["https://github.com/mongodb-js/mongodb-mcp-server"], verified: ["npx command", "env variable name", "--readOnly flag", "Node requirement", "official (mongodb-js organisation)"], unverified: ["tool list (discover after connecting)"] }
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
id: "postgresql",
|
|
359
|
+
name: "PostgreSQL",
|
|
360
|
+
category: "database",
|
|
361
|
+
description: "No maintained official PostgreSQL MCP server was verified.",
|
|
362
|
+
publisher: "community",
|
|
363
|
+
availability: "community-dependent",
|
|
364
|
+
docs: ["https://github.com/modelcontextprotocol/servers"],
|
|
365
|
+
access: [],
|
|
366
|
+
auth: { kinds: ["connection-string"], note: "Depends on the server you choose." },
|
|
367
|
+
permissions: [],
|
|
368
|
+
capabilities: [],
|
|
369
|
+
requires: [],
|
|
370
|
+
template: null,
|
|
371
|
+
warnings: ["The MCP project's own PostgreSQL reference server has been moved to an archive and is not maintained. Other servers are community projects zg has not verified.", "If your database is on Supabase, use the Supabase entry (official, supports read-only mode).", "To use a community server anyway: zg mcp add <name> --transport stdio --command <program> --arg ... --env VAR=HOSTVAR"],
|
|
372
|
+
platforms: NONE,
|
|
373
|
+
verification: { checked: CHECKED2, sources: ["https://github.com/modelcontextprotocol/servers"], verified: ["the reference PostgreSQL server is archived"], unverified: ["any community server"] }
|
|
374
|
+
},
|
|
375
|
+
{
|
|
376
|
+
id: "mysql",
|
|
377
|
+
name: "MySQL",
|
|
378
|
+
category: "database",
|
|
379
|
+
description: "No usable official MySQL MCP server was verified.",
|
|
380
|
+
publisher: "community",
|
|
381
|
+
availability: "community-dependent",
|
|
382
|
+
docs: ["https://pypi.org/project/oracle-mysql-mcp-server/"],
|
|
383
|
+
access: [],
|
|
384
|
+
auth: { kinds: [], note: "n/a" },
|
|
385
|
+
permissions: [],
|
|
386
|
+
capabilities: [],
|
|
387
|
+
requires: [],
|
|
388
|
+
template: null,
|
|
389
|
+
warnings: ["Oracle's package on PyPI states 'This is a placeholder package and should not be used' (as read on the day of verification). Other servers are community projects zg has not verified.", "To use a community server anyway: zg mcp add <name> --transport stdio --command <program> --arg ... --env VAR=HOSTVAR"],
|
|
390
|
+
platforms: NONE,
|
|
391
|
+
verification: { checked: CHECKED2, sources: ["https://pypi.org/project/oracle-mysql-mcp-server/"], verified: ["the Oracle PyPI package is labelled a placeholder"], unverified: ["any other server; Oracle's MySQL AI/HeatWave MCP offering"] }
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
id: "sqlite",
|
|
395
|
+
name: "SQLite",
|
|
396
|
+
category: "database",
|
|
397
|
+
description: "No maintained official SQLite MCP server was verified.",
|
|
398
|
+
publisher: "community",
|
|
399
|
+
availability: "community-dependent",
|
|
400
|
+
docs: ["https://github.com/modelcontextprotocol/servers"],
|
|
401
|
+
access: [],
|
|
402
|
+
auth: { kinds: ["none"], note: "n/a" },
|
|
403
|
+
permissions: [],
|
|
404
|
+
capabilities: [],
|
|
405
|
+
requires: [],
|
|
406
|
+
template: null,
|
|
407
|
+
warnings: ["The MCP project's SQLite reference server has been moved to an archive and is not maintained. Community servers exist but zg has not verified any.", "To use one anyway: zg mcp add <name> --transport stdio --command <program> --arg ..."],
|
|
408
|
+
platforms: NONE,
|
|
409
|
+
verification: { checked: CHECKED2, sources: ["https://github.com/modelcontextprotocol/servers"], verified: ["the reference SQLite server is archived"], unverified: ["any community server"] }
|
|
410
|
+
}
|
|
411
|
+
];
|
|
412
|
+
|
|
413
|
+
// src/mcp/catalog/integrations/dev.ts
|
|
414
|
+
var CHECKED3 = "2026-11-28";
|
|
415
|
+
var REMOTE2 = { linux: "remote server; zg's HTTP client not tested against it", macos: "same", windows: "same", termux: "same" };
|
|
416
|
+
var DEV = [
|
|
417
|
+
{
|
|
418
|
+
id: "playwright",
|
|
419
|
+
name: "Playwright",
|
|
420
|
+
category: "browser",
|
|
421
|
+
description: "Microsoft's official Playwright MCP server: browser automation for pages and tests.",
|
|
422
|
+
publisher: "official",
|
|
423
|
+
availability: "verified",
|
|
424
|
+
docs: ["https://playwright.dev/docs/getting-started-mcp"],
|
|
425
|
+
repo: "https://github.com/microsoft/playwright-mcp",
|
|
426
|
+
access: ["A browser that can visit ANY website you or the AI choose, with page content, clicks and typing"],
|
|
427
|
+
auth: { kinds: ["none"], note: "No sign-in. Pages you open in its browser may contain your logged-in sessions if you reuse a profile; the template starts headless and isolated." },
|
|
428
|
+
permissions: [],
|
|
429
|
+
capabilities: ["Options: --headless, --browser, --isolated, --user-data-dir, --extension, --cdp-endpoint, --idle-timeout, --config", "Page-provided content must be treated as untrusted (per Playwright's docs)"],
|
|
430
|
+
requires: ["Node.js 20 or newer (per Playwright)", "Browsers must be installed (the page does not say how; run `npx playwright install` yourself if needed)"],
|
|
431
|
+
template: { transport: "stdio", command: "npx", args: ["@playwright/mcp@latest", "--headless", "--isolated"], authMethod: "none" },
|
|
432
|
+
warnings: ["Playwright documents browser_run_code_unsafe as RCE-equivalent. zg treats any tool whose name looks like code execution as a change and asks every time; you can deny it with: zg mcp tools playwright (then /mcp policy).", "Web pages can contain instructions aimed at the AI. Review before approving navigation or form submissions."],
|
|
433
|
+
platforms: { linux: "needs Node 20+ and browsers; not tested by zg", macos: "same; not tested by zg", windows: "same; not tested by zg", termux: "browsers are generally not available in Termux; not tested and likely unsupported" },
|
|
434
|
+
verification: { checked: CHECKED3, sources: ["https://playwright.dev/docs/getting-started-mcp"], verified: ["npx command", "Node requirement", "option names", "security notes"], unverified: ["how browsers get installed", "tool list"] }
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
id: "sentry",
|
|
438
|
+
name: "Sentry",
|
|
439
|
+
category: "monitoring",
|
|
440
|
+
description: "Sentry's official hosted MCP server for issues, events and projects.",
|
|
441
|
+
publisher: "official",
|
|
442
|
+
availability: "verified",
|
|
443
|
+
docs: ["https://github.com/getsentry/sentry-mcp"],
|
|
444
|
+
repo: "https://github.com/getsentry/sentry-mcp",
|
|
445
|
+
access: ["Sentry organisations, projects, issues and events your account can see"],
|
|
446
|
+
auth: { kinds: ["oauth"], note: "MCP OAuth for the hosted server. Header tokens use a different scheme (Sentry-Bearer) that zg's token option does not send, so zg offers OAuth only." },
|
|
447
|
+
permissions: ["Scopes listed by Sentry as of the README: org:read, project:read, project:write, team:read, team:write, event:write"],
|
|
448
|
+
capabilities: ["Hosted at https://mcp.sentry.dev/mcp", "A stdio mode (npx @sentry/mcp-server@latest with SENTRY_ACCESS_TOKEN) exists; the README calls it a work in progress"],
|
|
449
|
+
requires: ["A Sentry account"],
|
|
450
|
+
template: { transport: "http", url: "https://mcp.sentry.dev/mcp", authMethod: "oauth" },
|
|
451
|
+
warnings: ["Self-hosted Sentry needs the stdio mode with --host; zg ships no template for it because the README labels it a work in progress."],
|
|
452
|
+
platforms: REMOTE2,
|
|
453
|
+
verification: { checked: CHECKED3, sources: ["https://github.com/getsentry/sentry-mcp"], verified: ["hosted URL", "OAuth", "scope list", "stdio command exists"], unverified: ["the docs.sentry.io page itself (it redirected and was not read)", "tool list"] }
|
|
454
|
+
},
|
|
455
|
+
{
|
|
456
|
+
id: "linear",
|
|
457
|
+
name: "Linear",
|
|
458
|
+
category: "project-management",
|
|
459
|
+
description: "Linear's official MCP server for issues, projects and comments.",
|
|
460
|
+
publisher: "official",
|
|
461
|
+
availability: "verified",
|
|
462
|
+
docs: ["https://linear.app/docs/mcp"],
|
|
463
|
+
access: ["Linear issues, projects and comments in the teams you allow"],
|
|
464
|
+
auth: { kinds: ["oauth", "api-token"], note: "OAuth 2.1 with dynamic client registration, or an OAuth token / API key as a Bearer header (zg reads it from LINEAR_API_KEY)." },
|
|
465
|
+
permissions: ["Read-only: use the read-only endpoint, the read scope, or an API key with only Read permission"],
|
|
466
|
+
capabilities: ["Streamable HTTP at https://mcp.linear.app/mcp (read-write) and https://mcp.linear.app/mcp/readonly (only read tools)", "The deprecated SSE endpoint is NOT used by zg"],
|
|
467
|
+
requires: ["A Linear account"],
|
|
468
|
+
template: { transport: "http", url: "https://mcp.linear.app/mcp/readonly", authMethod: "oauth" },
|
|
469
|
+
warnings: ["The template uses the READ-ONLY endpoint. For write access: zg mcp add linear-write --transport http --url https://mcp.linear.app/mcp --auth oauth"],
|
|
470
|
+
platforms: REMOTE2,
|
|
471
|
+
verification: { checked: CHECKED3, sources: ["https://linear.app/docs/mcp"], verified: ["URLs", "read-only endpoint", "OAuth DCR", "bearer API key", "SSE deprecated"], unverified: ["tool names (Linear's page lists none)"] }
|
|
472
|
+
}
|
|
473
|
+
];
|
|
474
|
+
|
|
475
|
+
// src/mcp/catalog/integrations/productivity.ts
|
|
476
|
+
var CHECKED4 = "2026-11-28";
|
|
477
|
+
var REMOTE3 = { linux: "remote server; not usable by zg today", macos: "same", windows: "same", termux: "same" };
|
|
478
|
+
var PRODUCTIVITY = [
|
|
479
|
+
{
|
|
480
|
+
id: "google-drive",
|
|
481
|
+
name: "Google Drive",
|
|
482
|
+
category: "productivity",
|
|
483
|
+
description: "Google's official Drive MCP server (drivemcp.googleapis.com).",
|
|
484
|
+
publisher: "official",
|
|
485
|
+
availability: "restricted",
|
|
486
|
+
docs: ["https://developers.google.com/workspace/drive/api/guides/configure-mcp-server"],
|
|
487
|
+
access: ["Files in your Google Drive (search, read, create, copy, update, trash)"],
|
|
488
|
+
auth: { kinds: ["oauth"], note: "Needs an OAuth 2.0 client you create in Google Cloud. Google's page lists redirect URIs for Antigravity and Claude only; a local zg callback is not among them." },
|
|
489
|
+
permissions: ["https://www.googleapis.com/auth/drive.readonly", "https://www.googleapis.com/auth/drive.file"],
|
|
490
|
+
capabilities: ["15 tools incl. search_files, read_file_content, download_file_content, create_file, update_file, trash_file, copy_file"],
|
|
491
|
+
requires: ["A Google Cloud project with drive.googleapis.com and drivemcp.googleapis.com enabled", "A pre-registered OAuth client"],
|
|
492
|
+
template: null,
|
|
493
|
+
warnings: ["zg's OAuth uses dynamic registration or a public loopback client; Google requires a pre-registered client whose redirect URIs are limited to the ones its page lists. zg therefore cannot connect today and ships no configuration. Nothing is pretended."],
|
|
494
|
+
platforms: REMOTE3,
|
|
495
|
+
verification: { checked: CHECKED4, sources: ["https://developers.google.com/workspace/drive/api/guides/configure-mcp-server"], verified: ["URL", "Streamable HTTP", "scopes", "redirect URI restriction", "tool names"], unverified: ["whether other redirect URIs can be registered"] }
|
|
496
|
+
},
|
|
497
|
+
{
|
|
498
|
+
id: "slack",
|
|
499
|
+
name: "Slack",
|
|
500
|
+
category: "productivity",
|
|
501
|
+
description: "Slack's official MCP server (mcp.slack.com).",
|
|
502
|
+
publisher: "official",
|
|
503
|
+
availability: "restricted",
|
|
504
|
+
docs: ["https://docs.slack.dev/ai/slack-mcp-server/"],
|
|
505
|
+
access: ["Search, read and post messages, files, canvases and lists according to the scopes of the Slack app"],
|
|
506
|
+
auth: { kinds: ["oauth"], note: "Confidential OAuth with a registered Slack app's client_id and client_secret; dynamic client registration and SSE are NOT supported by Slack. Only directory-published or internal apps may use MCP." },
|
|
507
|
+
permissions: ["Scopes such as search:read.public, channels:history, chat:write, files:read (see Slack's page)"],
|
|
508
|
+
capabilities: ["Streamable HTTP at https://mcp.slack.com/mcp", "Tools for search, messages, canvases, lists, reactions, file upload"],
|
|
509
|
+
requires: ["A Slack app that is directory-published or internal, with a fixed app ID"],
|
|
510
|
+
template: null,
|
|
511
|
+
warnings: ["zg has no Slack app identity and its OAuth does not hold a client secret, so it cannot connect to Slack today. zg ships no configuration instead of pretending."],
|
|
512
|
+
platforms: REMOTE3,
|
|
513
|
+
verification: { checked: CHECKED4, sources: ["https://docs.slack.dev/ai/slack-mcp-server/"], verified: ["URL", "transport", "no DCR", "app restrictions", "scope names"], unverified: ["availability label (GA/beta)"] }
|
|
514
|
+
}
|
|
515
|
+
];
|
|
516
|
+
|
|
517
|
+
// src/mcp/catalog/integrations/source-control.ts
|
|
518
|
+
var CHECKED5 = "2026-11-28";
|
|
519
|
+
var REMOTE_PLATFORMS = { linux: "remote server (no local install); zg's HTTP client not tested against it", macos: "same", windows: "same", termux: "same" };
|
|
520
|
+
var SOURCE_CONTROL = [
|
|
521
|
+
{
|
|
522
|
+
id: "github",
|
|
523
|
+
name: "GitHub",
|
|
524
|
+
category: "source-control",
|
|
525
|
+
description: "GitHub's official MCP server: repositories, issues, pull requests and more.",
|
|
526
|
+
publisher: "official",
|
|
527
|
+
availability: "verified",
|
|
528
|
+
docs: ["https://docs.github.com/en/copilot/how-tos/provide-context/use-mcp-in-your-ide/set-up-the-github-mcp-server"],
|
|
529
|
+
repo: "https://github.com/github/github-mcp-server",
|
|
530
|
+
access: ["Your GitHub repositories, issues and pull requests, limited by the scopes of the token you create", "Write tools can change issues, pull requests and files if the token allows it"],
|
|
531
|
+
auth: { kinds: ["pat", "oauth"], note: "zg uses a personal access token read from the environment variable GITHUB_PERSONAL_ACCESS_TOKEN (sent as an Authorization header). GitHub documents one-click OAuth for supported IDE clients; whether it works for other clients was not verified, so zg does not offer it for this entry." },
|
|
532
|
+
permissions: ["Create a fine-grained token with only the repositories and read/write rights you need (start read-only)"],
|
|
533
|
+
capabilities: ["Remote server at https://api.githubcopilot.com/mcp/", "Toolsets such as repos, issues, pull_requests (documented in the server's README)"],
|
|
534
|
+
requires: ["A GitHub personal access token in your environment"],
|
|
535
|
+
template: { transport: "http", url: "https://api.githubcopilot.com/mcp/", authMethod: "env", credentialEnv: "GITHUB_PERSONAL_ACCESS_TOKEN" },
|
|
536
|
+
warnings: ["On Enterprise Managed Users accounts PAT authentication is off unless an administrator enables it (per GitHub's docs).", "A read-only header for the remote server was not found in the documentation zg read; use a read-only token instead."],
|
|
537
|
+
platforms: REMOTE_PLATFORMS,
|
|
538
|
+
verification: { checked: CHECKED5, sources: ["https://docs.github.com/en/copilot/how-tos/provide-context/use-mcp-in-your-ide/set-up-the-github-mcp-server", "https://github.com/mcp/github/github-mcp-server"], verified: ["remote URL", "PAT header authentication", "official publisher (github organisation)"], unverified: ["OAuth for third-party clients", "remote read-only switch"] }
|
|
539
|
+
},
|
|
540
|
+
{
|
|
541
|
+
id: "gitlab",
|
|
542
|
+
name: "GitLab",
|
|
543
|
+
category: "source-control",
|
|
544
|
+
description: "GitLab's official MCP server (GitLab.com, Self-Managed and Dedicated).",
|
|
545
|
+
publisher: "official",
|
|
546
|
+
availability: "verified",
|
|
547
|
+
docs: ["https://docs.gitlab.com/user/gitlab_duo/model_context_protocol/mcp_server"],
|
|
548
|
+
access: ["GitLab projects, merge requests, work items, repository and CI data your account can see"],
|
|
549
|
+
auth: { kinds: ["oauth", "pat"], note: "OAuth 2.0 with dynamic client registration (scope mcp), or a fine-grained personal access token with the MCP tool resource and Execute permission. Legacy, project and group tokens are NOT accepted." },
|
|
550
|
+
permissions: ["OAuth scope: mcp", "or fine-grained PAT: MCP tool resource + Execute"],
|
|
551
|
+
capabilities: ["Toolsets: meta, core, merge_requests, work_items, repository, ci (default); wikis, code_security, orbit (opt-in)"],
|
|
552
|
+
requires: ["A GitLab account (Free, Premium or Ultimate)", "Self-Managed: your instance URL (https://<host>/api/v4/mcp)"],
|
|
553
|
+
template: { transport: "http", url: "https://gitlab.com/api/v4/mcp", authMethod: "oauth" },
|
|
554
|
+
warnings: ["For a self-managed instance, add the server by hand: zg mcp add gitlab-work --transport http --url https://<your-host>/api/v4/mcp --auth oauth"],
|
|
555
|
+
platforms: REMOTE_PLATFORMS,
|
|
556
|
+
verification: { checked: CHECKED5, sources: ["https://docs.gitlab.com/user/gitlab_duo/model_context_protocol/mcp_server"], verified: ["endpoint", "OAuth DCR and PAT requirements", "generally available status"], unverified: ["that zg's client registers successfully on every instance (instances can restrict dynamic registration)"] }
|
|
557
|
+
},
|
|
558
|
+
{
|
|
559
|
+
id: "bitbucket",
|
|
560
|
+
name: "Bitbucket",
|
|
561
|
+
category: "source-control",
|
|
562
|
+
description: "Bitbucket Cloud through Atlassian's MCP server.",
|
|
563
|
+
publisher: "official",
|
|
564
|
+
availability: "unverified-details",
|
|
565
|
+
docs: ["https://support.atlassian.com/bitbucket-cloud/docs/interacting-with-bitbucket-via-mcp/", "https://www.atlassian.com/blog/bitbucket/the-atlassian-rovo-mcp-server-now-supports-bitbucket-cloud"],
|
|
566
|
+
access: ["Pull requests, comments, tasks and pipeline failures of Bitbucket Cloud (per Atlassian's tool list)"],
|
|
567
|
+
auth: { kinds: [], note: "Atlassian's page mentions Bitbucket-specific scopes; the exact sign-in method for a generic client was not confirmed." },
|
|
568
|
+
permissions: ["Bitbucket-specific scopes (names not verified)"],
|
|
569
|
+
capabilities: ["Tools listed by Atlassian: createPullRequest, getPullRequests, getPullRequestDetails, getPullRequestComments, addPullRequestComment, updatePullRequestComment, getPullRequestTasks, createPullRequestTask, updatePullRequestTask, analyzePullRequestCommitStatusFailures, analyzePipelineStepFailure"],
|
|
570
|
+
requires: [],
|
|
571
|
+
template: null,
|
|
572
|
+
warnings: ["The documentation zg read does not state the endpoint or transport, and describes this tool list as a 'legacy MCP connection', so zg ships no configuration. If you know the endpoint from Atlassian's docs: zg mcp add bitbucket --transport http --url <url>"],
|
|
573
|
+
platforms: REMOTE_PLATFORMS,
|
|
574
|
+
verification: { checked: CHECKED5, sources: ["https://support.atlassian.com/bitbucket-cloud/docs/interacting-with-bitbucket-via-mcp/"], verified: ["Atlassian publishes it", "tool names"], unverified: ["endpoint", "transport", "auth method"] }
|
|
575
|
+
}
|
|
576
|
+
];
|
|
577
|
+
|
|
578
|
+
// src/mcp/catalog/integrations/index.ts
|
|
579
|
+
var BUILT_IN_ENTRIES = [...SOURCE_CONTROL, ...CLOUD, ...DATA, ...DEV, ...PRODUCTIVITY];
|
|
580
|
+
|
|
581
|
+
// src/mcp/catalog/search.ts
|
|
582
|
+
function searchEntries(entries, query, opts = {}) {
|
|
583
|
+
const words = query.toLowerCase().split(/\s+/).filter(Boolean);
|
|
584
|
+
const scored = [];
|
|
585
|
+
for (const e of entries) {
|
|
586
|
+
if (opts.category && e.category !== opts.category) continue;
|
|
587
|
+
const hay = `${e.id} ${e.name} ${e.category} ${e.description} ${e.publisher} ${e.availability}`.toLowerCase();
|
|
588
|
+
if (!words.every((w) => hay.includes(w))) continue;
|
|
589
|
+
const score = words.reduce((s, w) => s + (e.id === w || e.name.toLowerCase() === w ? 10 : e.id.includes(w) ? 5 : e.name.toLowerCase().includes(w) ? 3 : 1), 0);
|
|
590
|
+
scored.push({ e, score });
|
|
591
|
+
}
|
|
592
|
+
return scored.sort((a, b) => b.score - a.score || a.e.name.localeCompare(b.e.name)).map((x) => x.e);
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
// src/mcp/catalog/validation.ts
|
|
596
|
+
function validateEntry(e) {
|
|
597
|
+
const p = [];
|
|
598
|
+
if (!/^[a-z0-9][a-z0-9-]{0,39}$/.test(e.id)) p.push("bad id");
|
|
599
|
+
if (!CATEGORIES.includes(e.category)) p.push("unknown category");
|
|
600
|
+
if (e.name.trim() === "" || e.description.trim() === "") p.push("missing name or description");
|
|
601
|
+
if (e.docs.length === 0) p.push("no documentation link");
|
|
602
|
+
for (const u of [...e.docs, ...e.repo ? [e.repo] : [], ...e.verification.sources]) if (!/^https:\/\//.test(u)) p.push(`link is not https: ${u}`);
|
|
603
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(e.verification.checked)) p.push("no verification date");
|
|
604
|
+
if (e.verification.sources.length === 0) p.push("no verification source");
|
|
605
|
+
if (e.availability === "verified" || e.availability === "restricted") {
|
|
606
|
+
if (e.verification.verified.length === 0) p.push("verified entry lists nothing as verified");
|
|
607
|
+
if (e.publisher === "none") p.push("verified entry has no publisher");
|
|
608
|
+
}
|
|
609
|
+
if (e.availability === "verified" && e.template === null) p.push("verified entry has no config template");
|
|
610
|
+
if ((e.availability === "unverified-details" || e.availability === "community-dependent" || e.availability === "unavailable") && e.template !== null) p.push("an entry whose details are unverified must not ship a config template");
|
|
611
|
+
if (e.availability === "community-dependent" && e.publisher === "official") p.push("community-dependent entry cannot be marked official");
|
|
612
|
+
if ((e.availability === "unverified-details" || e.availability === "community-dependent" || e.availability === "restricted") && e.warnings.length === 0) p.push("needs a warning explaining the limit");
|
|
613
|
+
if (e.template) {
|
|
614
|
+
try {
|
|
615
|
+
validateServer({ ...e.template, args: e.template.args ?? [], env: e.template.env ?? {} });
|
|
616
|
+
} catch (err) {
|
|
617
|
+
p.push(`template invalid: ${err.message}`);
|
|
618
|
+
}
|
|
619
|
+
if (e.template.transport === "http" && /\/sse\/?$/.test(e.template.url ?? "")) p.push("template uses the deprecated SSE endpoint");
|
|
620
|
+
if (JSON.stringify(e.template).match(/(ghp_|sk-[A-Za-z0-9]{10}|Bearer\s+[A-Za-z0-9])/)) p.push("template contains a credential");
|
|
621
|
+
}
|
|
622
|
+
return p;
|
|
623
|
+
}
|
|
624
|
+
function validateCatalog(entries) {
|
|
625
|
+
const out = [];
|
|
626
|
+
const seen = /* @__PURE__ */ new Set();
|
|
627
|
+
for (const e of entries) {
|
|
628
|
+
if (seen.has(e.id)) out.push(`${e.id}: duplicate id`);
|
|
629
|
+
seen.add(e.id);
|
|
630
|
+
for (const x of validateEntry(e)) out.push(`${e.id}: ${x}`);
|
|
631
|
+
}
|
|
632
|
+
return out;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
// src/mcp/catalog/catalog-manager.ts
|
|
636
|
+
var CatalogManager = class {
|
|
637
|
+
#entries = /* @__PURE__ */ new Map();
|
|
638
|
+
constructor(extra = []) {
|
|
639
|
+
for (const e of BUILT_IN_ENTRIES) this.#entries.set(e.id, e);
|
|
640
|
+
for (const e of extra) this.register(e);
|
|
641
|
+
}
|
|
642
|
+
register(e) {
|
|
643
|
+
if (this.#entries.has(e.id)) throw new McpError("exists", `A catalog entry "${e.id}" already exists.`);
|
|
644
|
+
const problems = validateEntry(e);
|
|
645
|
+
if (problems.length > 0) throw new McpError("invalid-config", `Catalog entry "${e.id}" is invalid: ${problems.slice(0, 3).join("; ")}`);
|
|
646
|
+
this.#entries.set(e.id, e);
|
|
647
|
+
}
|
|
648
|
+
all() {
|
|
649
|
+
return [...this.#entries.values()].sort((a, b) => a.category.localeCompare(b.category) || a.name.localeCompare(b.name));
|
|
650
|
+
}
|
|
651
|
+
get(id) {
|
|
652
|
+
const e = this.#entries.get(id.toLowerCase());
|
|
653
|
+
if (!e) throw new McpError("unknown-server", `No catalog entry "${id.slice(0, 40)}".`, "See: zg integrations list");
|
|
654
|
+
return e;
|
|
655
|
+
}
|
|
656
|
+
search(q, category) {
|
|
657
|
+
return searchEntries(this.all(), q, category ? { category } : {});
|
|
658
|
+
}
|
|
659
|
+
byCategory(c) {
|
|
660
|
+
return this.all().filter((e) => e.category === c);
|
|
661
|
+
}
|
|
662
|
+
categories() {
|
|
663
|
+
return CATEGORIES.map((category) => ({ category, count: this.byCategory(category).length })).filter((c) => c.count > 0);
|
|
664
|
+
}
|
|
665
|
+
/** Servers in the settings that were created from this entry. */
|
|
666
|
+
connectedAs(settings, id) {
|
|
667
|
+
return Object.entries(settings.servers).filter(([, s]) => s.integration === id).map(([n]) => n);
|
|
668
|
+
}
|
|
669
|
+
/**
|
|
670
|
+
* Builds the configuration for an entry. Never silently replaces anything: the caller must pick a free name.
|
|
671
|
+
* `projectRef` (when the entry asks for one) is placed in the URL; it is an identifier, never a secret.
|
|
672
|
+
*/
|
|
673
|
+
plan(id, opts) {
|
|
674
|
+
const entry = this.get(id);
|
|
675
|
+
if (entry.template === null) throw new McpError("unsupported", `${entry.name} cannot be configured automatically: ${entry.availability}.`, entry.warnings[0] ?? "See: zg integrations inspect " + entry.id);
|
|
676
|
+
const t = entry.template;
|
|
677
|
+
let url = t.url;
|
|
678
|
+
if (opts.projectRef !== void 0) {
|
|
679
|
+
if (!entry.prompts?.some((p) => p.name === "project_ref")) throw new McpError("invalid-config", `${entry.name} does not take a project reference.`);
|
|
680
|
+
if (!/^[A-Za-z0-9_-]{4,64}$/.test(opts.projectRef)) throw new McpError("invalid-config", "The project reference may only contain letters, digits, '-' and '_'.");
|
|
681
|
+
const u = new URL(url ?? "");
|
|
682
|
+
u.searchParams.set("project_ref", opts.projectRef);
|
|
683
|
+
url = u.toString();
|
|
684
|
+
}
|
|
685
|
+
const base = opts.name ?? (opts.projectRef ? `${entry.id}-${opts.projectRef.toLowerCase().replace(/[^a-z0-9]/g, "").slice(0, 12)}` : entry.id);
|
|
686
|
+
const name = validateServerName(base);
|
|
687
|
+
if (opts.settings.servers[name]) throw new McpError("exists", `A server named "${name}" already exists. It was not changed.`, "Choose another name with --name, or remove the old one first.");
|
|
688
|
+
const server = validateServer({ transport: t.transport, ...t.command ? { command: t.command } : {}, args: t.args ?? [], ...url ? { url } : {}, env: t.env ?? {}, authMethod: t.authMethod, ...t.credentialEnv ? { credentialEnv: t.credentialEnv } : {}, integration: entry.id, ...opts.projectPath ? { projectPath: opts.projectPath } : {}, enabled: true });
|
|
689
|
+
return { entry, name, server, summary: this.describe(entry, server) };
|
|
690
|
+
}
|
|
691
|
+
describe(e, server) {
|
|
692
|
+
const lines = [`${e.name} (${e.publisher === "official" ? "official" : e.publisher}, ${e.availability})`, e.description, "", "Access requested:", ...e.access.map((a) => ` - ${a}`)];
|
|
693
|
+
lines.push("", `Authentication: ${e.auth.kinds.join(" / ") || "unknown"}`, ` ${e.auth.note}`);
|
|
694
|
+
if (e.permissions.length) lines.push("Permissions needed:", ...e.permissions.map((p) => ` - ${p}`));
|
|
695
|
+
if (server) lines.push("", `Will add: ${server.transport === "http" ? server.url : [server.command, ...server.args].join(" ")}`, ...Object.keys(server.env).length ? [` environment variables passed (names only): ${Object.values(server.env).join(", ")}`] : []);
|
|
696
|
+
if (e.warnings.length) lines.push("", "Please note:", ...e.warnings.map((w) => ` ! ${w}`));
|
|
697
|
+
lines.push("", "Connecting does NOT authorize everything: every tool call still asks you first.");
|
|
698
|
+
return lines;
|
|
699
|
+
}
|
|
700
|
+
};
|
|
701
|
+
|
|
702
|
+
// src/mcp/client.ts
|
|
703
|
+
var CLIENT_INFO = { name: "zero-gravity", version: VERSION };
|
|
704
|
+
var MAX_PAGES = 20;
|
|
705
|
+
var str = (v, max) => typeof v === "string" ? v.slice(0, max) : "";
|
|
706
|
+
var cleanText = (v, max) => redactSecrets(str(v, max)).replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/g, "");
|
|
707
|
+
var McpConnection = class _McpConnection {
|
|
708
|
+
#client;
|
|
709
|
+
#transport;
|
|
710
|
+
#requestTimeoutMs;
|
|
711
|
+
#closed = false;
|
|
712
|
+
#stderr = "";
|
|
713
|
+
#onClose = null;
|
|
714
|
+
#lastError = null;
|
|
715
|
+
constructor(client, transport, requestTimeoutMs) {
|
|
716
|
+
this.#client = client;
|
|
717
|
+
this.#transport = transport;
|
|
718
|
+
this.#requestTimeoutMs = requestTimeoutMs;
|
|
719
|
+
}
|
|
720
|
+
static async open(server, deps, opts) {
|
|
721
|
+
const transport = server.transport === "stdio" ? await createStdioTransport(server, deps) : await createHttpTransport(server, deps);
|
|
722
|
+
const { Client: SdkClient } = await import("@modelcontextprotocol/sdk/client/index.js");
|
|
723
|
+
const client = new SdkClient(CLIENT_INFO, { capabilities: {} });
|
|
724
|
+
const conn = new _McpConnection(client, transport, opts.requestTimeoutMs);
|
|
725
|
+
if (server.transport === "stdio") {
|
|
726
|
+
const err = transport.stderr;
|
|
727
|
+
err?.on("data", (b) => {
|
|
728
|
+
conn.#stderr = (conn.#stderr + redactSecrets(b.toString("utf8"))).slice(-4e3);
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
client.onclose = () => {
|
|
732
|
+
const was = conn.#closed;
|
|
733
|
+
conn.#closed = true;
|
|
734
|
+
if (!was) conn.#onClose?.();
|
|
735
|
+
};
|
|
736
|
+
client.onerror = (e) => {
|
|
737
|
+
conn.#lastError = toMcpError(e).message;
|
|
738
|
+
};
|
|
739
|
+
try {
|
|
740
|
+
await client.connect(transport, { timeout: opts.connectTimeoutMs, ...opts.signal ? { signal: opts.signal } : {} });
|
|
741
|
+
} catch (err) {
|
|
742
|
+
conn.#closed = true;
|
|
743
|
+
await transport.close().catch(() => void 0);
|
|
744
|
+
const e = toMcpError(err, "connect-failed");
|
|
745
|
+
const tail = conn.#stderr.split("\n").map((l) => l.trim()).filter((l) => l !== "" && !/^Node\.js v\d/.test(l)).slice(-2).join(" ").slice(0, 200);
|
|
746
|
+
throw tail && e.code !== "auth-required" ? new McpError(e.code, `${e.message} Server said: ${tail}`, e.hint) : e;
|
|
747
|
+
}
|
|
748
|
+
return conn;
|
|
749
|
+
}
|
|
750
|
+
onClosed(cb) {
|
|
751
|
+
this.#onClose = cb;
|
|
752
|
+
if (this.#closed) cb();
|
|
753
|
+
}
|
|
754
|
+
get closed() {
|
|
755
|
+
return this.#closed;
|
|
756
|
+
}
|
|
757
|
+
get lastError() {
|
|
758
|
+
return this.#lastError;
|
|
759
|
+
}
|
|
760
|
+
get stderrTail() {
|
|
761
|
+
return this.#stderr;
|
|
762
|
+
}
|
|
763
|
+
get pid() {
|
|
764
|
+
return "pid" in this.#transport ? this.#transport.pid ?? null : null;
|
|
765
|
+
}
|
|
766
|
+
get protocolVersion() {
|
|
767
|
+
return this.#transport.protocolVersion ?? null;
|
|
768
|
+
}
|
|
769
|
+
get info() {
|
|
770
|
+
const caps = this.#client.getServerCapabilities() ?? {};
|
|
771
|
+
const v = this.#client.getServerVersion();
|
|
772
|
+
return { name: v ? cleanText(v.name, 100) : null, version: v ? cleanText(v.version, 50) : null, instructions: this.#client.getInstructions() ? cleanText(this.#client.getInstructions(), 2e3) : null, capabilities: { tools: caps.tools !== void 0, resources: caps.resources !== void 0, prompts: caps.prompts !== void 0 } };
|
|
773
|
+
}
|
|
774
|
+
#opts(signal) {
|
|
775
|
+
return { timeout: this.#requestTimeoutMs, ...signal ? { signal } : {} };
|
|
776
|
+
}
|
|
777
|
+
#live() {
|
|
778
|
+
if (this.#closed) throw new McpError("closed", "The server connection is closed.", "Reconnect with: zg mcp connect <server>");
|
|
779
|
+
}
|
|
780
|
+
async listTools(max, signal) {
|
|
781
|
+
this.#live();
|
|
782
|
+
if (!this.info.capabilities.tools) return [];
|
|
783
|
+
const out = [];
|
|
784
|
+
let cursor;
|
|
785
|
+
try {
|
|
786
|
+
for (let page = 0; page < MAX_PAGES && out.length < max; page++) {
|
|
787
|
+
const res = await this.#client.listTools(cursor ? { cursor } : {}, this.#opts(signal));
|
|
788
|
+
if (!Array.isArray(res.tools)) throw new McpError("protocol", "The server returned a malformed tool list.");
|
|
789
|
+
for (const t of res.tools) {
|
|
790
|
+
if (out.length >= max) break;
|
|
791
|
+
if (typeof t?.name !== "string" || t.name === "") continue;
|
|
792
|
+
const schema = t.inputSchema && typeof t.inputSchema === "object" ? t.inputSchema : { type: "object" };
|
|
793
|
+
out.push({ name: t.name.slice(0, 128), description: cleanText(t.description, 1e3), inputSchema: schema, annotations: { ...typeof t.annotations?.readOnlyHint === "boolean" ? { readOnlyHint: t.annotations.readOnlyHint } : {}, ...typeof t.annotations?.destructiveHint === "boolean" ? { destructiveHint: t.annotations.destructiveHint } : {}, ...typeof t.annotations?.idempotentHint === "boolean" ? { idempotentHint: t.annotations.idempotentHint } : {}, ...typeof t.annotations?.openWorldHint === "boolean" ? { openWorldHint: t.annotations.openWorldHint } : {}, ...t.annotations?.title ? { title: cleanText(t.annotations.title, 100) } : {} } });
|
|
794
|
+
}
|
|
795
|
+
cursor = res.nextCursor;
|
|
796
|
+
if (!cursor) break;
|
|
797
|
+
}
|
|
798
|
+
} catch (err) {
|
|
799
|
+
throw toMcpError(err);
|
|
800
|
+
}
|
|
801
|
+
return out;
|
|
802
|
+
}
|
|
803
|
+
async callTool(name, args, signal) {
|
|
804
|
+
this.#live();
|
|
805
|
+
try {
|
|
806
|
+
const res = await this.#client.callTool({ name, arguments: args }, void 0, this.#opts(signal));
|
|
807
|
+
if (res.content !== void 0 && !Array.isArray(res.content)) throw new McpError("invalid-result", "The server returned a malformed tool result.");
|
|
808
|
+
return { content: res.content ?? [], isError: res.isError === true, structured: res.structuredContent };
|
|
809
|
+
} catch (err) {
|
|
810
|
+
throw toMcpError(err);
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
async listResources(max, signal) {
|
|
814
|
+
this.#live();
|
|
815
|
+
if (!this.info.capabilities.resources) return [];
|
|
816
|
+
const out = [];
|
|
817
|
+
let cursor;
|
|
818
|
+
try {
|
|
819
|
+
for (let page = 0; page < MAX_PAGES && out.length < max; page++) {
|
|
820
|
+
const res = await this.#client.listResources(cursor ? { cursor } : {}, this.#opts(signal));
|
|
821
|
+
for (const r of res.resources ?? []) {
|
|
822
|
+
if (out.length >= max) break;
|
|
823
|
+
if (typeof r?.uri !== "string" || r.uri === "") continue;
|
|
824
|
+
out.push({ uri: r.uri.slice(0, 2e3), name: cleanText(r.name, 200), description: cleanText(r.description, 500), mimeType: typeof r.mimeType === "string" ? r.mimeType.slice(0, 100) : null, size: typeof r.size === "number" ? r.size : null });
|
|
825
|
+
}
|
|
826
|
+
cursor = res.nextCursor;
|
|
827
|
+
if (!cursor) break;
|
|
828
|
+
}
|
|
829
|
+
} catch (err) {
|
|
830
|
+
throw toMcpError(err);
|
|
831
|
+
}
|
|
832
|
+
return out;
|
|
833
|
+
}
|
|
834
|
+
async readResource(uri, signal) {
|
|
835
|
+
this.#live();
|
|
836
|
+
try {
|
|
837
|
+
const res = await this.#client.readResource({ uri }, this.#opts(signal));
|
|
838
|
+
return (res.contents ?? []).map((c) => {
|
|
839
|
+
const x = c;
|
|
840
|
+
return { uri: str(x.uri, 2e3), mimeType: typeof x.mimeType === "string" ? x.mimeType.slice(0, 100) : null, text: typeof x.text === "string" ? x.text : null, blobBytes: typeof x.blob === "string" ? Math.floor(x.blob.length * 3 / 4) : null };
|
|
841
|
+
});
|
|
842
|
+
} catch (err) {
|
|
843
|
+
throw toMcpError(err);
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
async listPrompts(max, signal) {
|
|
847
|
+
this.#live();
|
|
848
|
+
if (!this.info.capabilities.prompts) return [];
|
|
849
|
+
const out = [];
|
|
850
|
+
let cursor;
|
|
851
|
+
try {
|
|
852
|
+
for (let page = 0; page < MAX_PAGES && out.length < max; page++) {
|
|
853
|
+
const res = await this.#client.listPrompts(cursor ? { cursor } : {}, this.#opts(signal));
|
|
854
|
+
for (const p of res.prompts ?? []) {
|
|
855
|
+
if (out.length >= max) break;
|
|
856
|
+
if (typeof p?.name !== "string" || p.name === "") continue;
|
|
857
|
+
out.push({ name: p.name.slice(0, 128), description: cleanText(p.description, 500), arguments: (p.arguments ?? []).slice(0, 30).map((a) => ({ name: cleanText(a.name, 64), description: cleanText(a.description, 300), required: a.required === true })) });
|
|
858
|
+
}
|
|
859
|
+
cursor = res.nextCursor;
|
|
860
|
+
if (!cursor) break;
|
|
861
|
+
}
|
|
862
|
+
} catch (err) {
|
|
863
|
+
throw toMcpError(err);
|
|
864
|
+
}
|
|
865
|
+
return out;
|
|
866
|
+
}
|
|
867
|
+
async getPrompt(name, args, signal) {
|
|
868
|
+
this.#live();
|
|
869
|
+
try {
|
|
870
|
+
const res = await this.#client.getPrompt({ name, arguments: args }, this.#opts(signal));
|
|
871
|
+
return { description: cleanText(res.description, 500), messages: (res.messages ?? []).slice(0, 50).map((m) => ({ role: str(m.role, 20), text: m.content && m.content.type === "text" ? cleanText(m.content.text, 2e4) : "[non-text content omitted]" })) };
|
|
872
|
+
} catch (err) {
|
|
873
|
+
throw toMcpError(err);
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
/** Close politely, then force-end the process zg started (the SDK transport escalates to a kill). Safe to call twice. */
|
|
877
|
+
async close() {
|
|
878
|
+
if (this.#closed) return;
|
|
879
|
+
this.#closed = true;
|
|
880
|
+
try {
|
|
881
|
+
await this.#client.close();
|
|
882
|
+
} catch {
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
};
|
|
886
|
+
|
|
887
|
+
// src/mcp/tool-adapter.ts
|
|
888
|
+
var TOOL_NAME = /^[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}$/;
|
|
889
|
+
var loaded = null;
|
|
890
|
+
async function loadValidator() {
|
|
891
|
+
if (loaded) return;
|
|
892
|
+
const { AjvJsonSchemaValidator: V } = await import("@modelcontextprotocol/sdk/validation/ajv");
|
|
893
|
+
loaded = new V();
|
|
894
|
+
}
|
|
895
|
+
var validator = {
|
|
896
|
+
getValidator(schema) {
|
|
897
|
+
if (!loaded) throw new McpError("internal", "The schema validator was used before it was loaded.");
|
|
898
|
+
return loaded.getValidator(schema);
|
|
899
|
+
}
|
|
900
|
+
};
|
|
901
|
+
var MAX_ARGS_BYTES = 1e5;
|
|
902
|
+
function adaptTools(server, remote) {
|
|
903
|
+
const tools = [];
|
|
904
|
+
const skipped = [];
|
|
905
|
+
const seen = /* @__PURE__ */ new Set();
|
|
906
|
+
for (const t of remote) {
|
|
907
|
+
if (!TOOL_NAME.test(t.name)) {
|
|
908
|
+
skipped.push({ name: t.name.slice(0, 40), reason: "invalid tool name" });
|
|
909
|
+
continue;
|
|
910
|
+
}
|
|
911
|
+
if (seen.has(t.name)) {
|
|
912
|
+
skipped.push({ name: t.name, reason: "duplicate tool name (the first one is kept)" });
|
|
913
|
+
continue;
|
|
914
|
+
}
|
|
915
|
+
seen.add(t.name);
|
|
916
|
+
try {
|
|
917
|
+
validator.getValidator(t.inputSchema);
|
|
918
|
+
} catch {
|
|
919
|
+
skipped.push({ name: t.name, reason: "its input schema could not be understood" });
|
|
920
|
+
continue;
|
|
921
|
+
}
|
|
922
|
+
tools.push({ id: `${server}.${t.name}`, server, name: t.name, description: t.description, inputSchema: t.inputSchema, annotations: t.annotations, sensitivity: classifyTool(t) });
|
|
923
|
+
}
|
|
924
|
+
return { tools, skipped };
|
|
925
|
+
}
|
|
926
|
+
function hasProto(v, depth = 0) {
|
|
927
|
+
if (depth > 20 || v === null || typeof v !== "object") return false;
|
|
928
|
+
for (const k of Object.keys(v)) if (k === "__proto__" || k === "constructor" || k === "prototype" || hasProto(v[k], depth + 1)) return true;
|
|
929
|
+
return false;
|
|
930
|
+
}
|
|
931
|
+
function strings(v, out = [], depth = 0) {
|
|
932
|
+
if (depth > 20) return out;
|
|
933
|
+
if (typeof v === "string") out.push(v);
|
|
934
|
+
else if (Array.isArray(v)) for (const x of v) strings(x, out, depth + 1);
|
|
935
|
+
else if (v && typeof v === "object") for (const x of Object.values(v)) strings(x, out, depth + 1);
|
|
936
|
+
return out;
|
|
937
|
+
}
|
|
938
|
+
function argWarnings(args) {
|
|
939
|
+
const w = [];
|
|
940
|
+
for (const s of strings(args)) {
|
|
941
|
+
if (/(^|[\\/])\.\.([\\/]|$)/.test(s)) w.push(`an argument contains a ".." path segment: ${s.slice(0, 80)}`);
|
|
942
|
+
else if (/^(\/(etc|root|home|proc|sys|var)\b|~[\\/]|[A-Za-z]:\\)/.test(s)) w.push(`an argument points at a path outside any project: ${s.slice(0, 80)}`);
|
|
943
|
+
}
|
|
944
|
+
return [...new Set(w)].slice(0, 5);
|
|
945
|
+
}
|
|
946
|
+
function validateArgs(tool, args) {
|
|
947
|
+
if (args === null || typeof args !== "object" || Array.isArray(args)) throw new McpError("invalid-input", "Tool arguments must be a JSON object.");
|
|
948
|
+
const a = args;
|
|
949
|
+
if (hasProto(a)) throw new McpError("invalid-input", "The arguments contain a forbidden key.");
|
|
950
|
+
const json = JSON.stringify(a);
|
|
951
|
+
if (json.length > MAX_ARGS_BYTES) throw new McpError("too-large", "The arguments are too large.");
|
|
952
|
+
if (strings(a).some((s) => looksLikeSecretValue(s))) throw new McpError("invalid-input", "An argument looks like a credential, so the call was refused.", "zg does not send secrets to tools. Use the server's own credential setup instead.");
|
|
953
|
+
const check = validator.getValidator(tool.inputSchema)(a);
|
|
954
|
+
if (!check.valid) throw new McpError("invalid-input", `The arguments do not match ${tool.id}'s schema: ${redactSecrets(check.errorMessage).slice(0, 300)}`);
|
|
955
|
+
return a;
|
|
956
|
+
}
|
|
957
|
+
function normalizeResult(res, maxBytes) {
|
|
958
|
+
const parts = [];
|
|
959
|
+
const notes = [];
|
|
960
|
+
for (const c of res.content) {
|
|
961
|
+
const p = c;
|
|
962
|
+
if (p.type === "text" && typeof p.text === "string") parts.push(p.text);
|
|
963
|
+
else if (p.type === "image" || p.type === "audio") notes.push(`[${String(p.type)} ${cleanText(p.mimeType, 60)} omitted: ${typeof p.data === "string" ? Math.floor(p.data.length * 3 / 4) : 0} bytes]`);
|
|
964
|
+
else if (p.type === "resource_link") notes.push(`[resource link not followed: ${cleanText(p.uri, 200)}]`);
|
|
965
|
+
else if (p.type === "resource" && p.resource) {
|
|
966
|
+
if (typeof p.resource.text === "string") parts.push(`[embedded resource ${cleanText(p.resource.uri, 200)}]
|
|
967
|
+
${p.resource.text}`);
|
|
968
|
+
else notes.push(`[binary resource ${cleanText(p.resource.uri, 200)} omitted]`);
|
|
969
|
+
} else notes.push("[unsupported content part omitted]");
|
|
970
|
+
}
|
|
971
|
+
if (parts.length === 0 && res.structured !== void 0) {
|
|
972
|
+
try {
|
|
973
|
+
parts.push(JSON.stringify(res.structured, null, 2));
|
|
974
|
+
} catch {
|
|
975
|
+
notes.push("[structured result could not be shown]");
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
let text = redactSecrets(parts.join("\n")).replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/g, "");
|
|
979
|
+
let truncated = false;
|
|
980
|
+
if (Buffer.byteLength(text, "utf8") > maxBytes) {
|
|
981
|
+
text = Buffer.from(text, "utf8").subarray(0, maxBytes).toString("utf8").replace(/�$/, "");
|
|
982
|
+
truncated = true;
|
|
983
|
+
}
|
|
984
|
+
return { ok: !res.isError, text, truncated, notes, isError: res.isError };
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
// src/mcp/manager.ts
|
|
988
|
+
var emptySlot = () => ({ state: "disconnected", conn: null, tools: [], skipped: [], lastError: null, connectedAt: null, info: null, pid: null, protocolVersion: null, connecting: null, abort: null });
|
|
989
|
+
var McpManager = class {
|
|
990
|
+
#d;
|
|
991
|
+
#slots = /* @__PURE__ */ new Map();
|
|
992
|
+
constructor(deps) {
|
|
993
|
+
this.#d = deps;
|
|
994
|
+
}
|
|
995
|
+
#slot(name) {
|
|
996
|
+
let s = this.#slots.get(name);
|
|
997
|
+
if (!s) {
|
|
998
|
+
s = emptySlot();
|
|
999
|
+
this.#slots.set(name, s);
|
|
1000
|
+
}
|
|
1001
|
+
return s;
|
|
1002
|
+
}
|
|
1003
|
+
get settings() {
|
|
1004
|
+
return this.#d.settings();
|
|
1005
|
+
}
|
|
1006
|
+
#check(name) {
|
|
1007
|
+
const cfg = this.settings;
|
|
1008
|
+
if (!cfg.enabled) throw new McpError("disabled", "MCP is turned off.", "Turn it on with: zg config set mcp.enabled true");
|
|
1009
|
+
const server = getServer(cfg, name);
|
|
1010
|
+
if (!server.enabled) throw new McpError("disabled", `Server "${name}" is disabled.`, `Enable it with: zg mcp enable ${name}`);
|
|
1011
|
+
const root = this.#d.projectRoot();
|
|
1012
|
+
if (server.projectPath && server.projectPath !== root) throw new McpError("wrong-project", `Server "${name}" belongs to another project (${server.projectPath}).`, "Run zg from that project, or add the server again for this one.");
|
|
1013
|
+
return server;
|
|
1014
|
+
}
|
|
1015
|
+
status(name) {
|
|
1016
|
+
const cfg = this.settings;
|
|
1017
|
+
const server = getServer(cfg, name);
|
|
1018
|
+
const s = this.#slots.get(name) ?? emptySlot();
|
|
1019
|
+
const state = !server.enabled || !cfg.enabled ? "disabled" : s.conn?.closed ? "disconnected" : s.state;
|
|
1020
|
+
return {
|
|
1021
|
+
name,
|
|
1022
|
+
state,
|
|
1023
|
+
transport: server.transport,
|
|
1024
|
+
enabled: server.enabled,
|
|
1025
|
+
integration: server.integration ?? null,
|
|
1026
|
+
target: describeTarget(server),
|
|
1027
|
+
serverName: s.info?.name ?? null,
|
|
1028
|
+
serverVersion: s.info?.version ?? null,
|
|
1029
|
+
protocolVersion: s.protocolVersion,
|
|
1030
|
+
capabilities: s.info?.capabilities ?? { tools: false, resources: false, prompts: false },
|
|
1031
|
+
toolCount: s.tools.length,
|
|
1032
|
+
lastError: s.lastError,
|
|
1033
|
+
connectedAt: s.connectedAt,
|
|
1034
|
+
pid: s.pid,
|
|
1035
|
+
authMethod: server.authMethod
|
|
1036
|
+
};
|
|
1037
|
+
}
|
|
1038
|
+
statuses() {
|
|
1039
|
+
return Object.keys(this.settings.servers).sort().map((n) => this.status(n));
|
|
1040
|
+
}
|
|
1041
|
+
isConnected(name) {
|
|
1042
|
+
const s = this.#slots.get(name);
|
|
1043
|
+
return s?.state === "connected" && s.conn !== null && !s.conn.closed;
|
|
1044
|
+
}
|
|
1045
|
+
async connect(name, signal) {
|
|
1046
|
+
const server = this.#check(name);
|
|
1047
|
+
const s = this.#slot(name);
|
|
1048
|
+
if (this.isConnected(name)) return this.status(name);
|
|
1049
|
+
if (s.connecting) {
|
|
1050
|
+
await s.connecting;
|
|
1051
|
+
return this.status(name);
|
|
1052
|
+
}
|
|
1053
|
+
s.state = "connecting";
|
|
1054
|
+
s.lastError = null;
|
|
1055
|
+
s.abort = new AbortController();
|
|
1056
|
+
const onOuter = () => s.abort?.abort();
|
|
1057
|
+
signal?.addEventListener("abort", onOuter, { once: true });
|
|
1058
|
+
const run = (async () => {
|
|
1059
|
+
let conn = null;
|
|
1060
|
+
try {
|
|
1061
|
+
const cfg = this.settings;
|
|
1062
|
+
const oauth = server.authMethod === "oauth" ? await this.#d.oauth?.(name, server) : void 0;
|
|
1063
|
+
if (server.authMethod === "oauth" && !oauth) throw new McpError("auth-required", `Server "${name}" has not been signed in.`, `Run: zg mcp connect ${name}`);
|
|
1064
|
+
const root = this.#d.projectRoot();
|
|
1065
|
+
conn = await McpConnection.open(server, { env: this.#d.env, windows: this.#d.windows, termux: this.#d.termux, ...root ? { cwd: root } : {}, ...oauth ? { oauth } : {} }, { connectTimeoutMs: cfg.connectTimeoutSeconds * 1e3, requestTimeoutMs: cfg.requestTimeoutSeconds * 1e3, signal: s.abort?.signal });
|
|
1066
|
+
const remote = await conn.listTools(cfg.maxToolsPerServer, s.abort?.signal);
|
|
1067
|
+
await loadValidator();
|
|
1068
|
+
const adapted = adaptTools(name, remote);
|
|
1069
|
+
s.conn = conn;
|
|
1070
|
+
s.tools = adapted.tools;
|
|
1071
|
+
s.skipped = adapted.skipped;
|
|
1072
|
+
s.info = conn.info;
|
|
1073
|
+
s.pid = conn.pid;
|
|
1074
|
+
s.protocolVersion = conn.protocolVersion;
|
|
1075
|
+
s.connectedAt = (this.#d.now?.() ?? /* @__PURE__ */ new Date()).toISOString();
|
|
1076
|
+
s.state = "connected";
|
|
1077
|
+
const mine = conn;
|
|
1078
|
+
conn.onClosed(() => {
|
|
1079
|
+
if (s.conn !== mine) return;
|
|
1080
|
+
s.state = "disconnected";
|
|
1081
|
+
s.lastError = "The server connection closed unexpectedly.";
|
|
1082
|
+
s.tools = [];
|
|
1083
|
+
s.pid = null;
|
|
1084
|
+
});
|
|
1085
|
+
} catch (err) {
|
|
1086
|
+
await conn?.close();
|
|
1087
|
+
const e = toMcpError(err, "connect-failed");
|
|
1088
|
+
s.conn = null;
|
|
1089
|
+
s.tools = [];
|
|
1090
|
+
s.state = e.code === "auth-required" ? "auth-required" : "failed";
|
|
1091
|
+
s.lastError = e.hint ? `${e.message} ${e.hint}` : e.message;
|
|
1092
|
+
throw e;
|
|
1093
|
+
} finally {
|
|
1094
|
+
signal?.removeEventListener("abort", onOuter);
|
|
1095
|
+
s.connecting = null;
|
|
1096
|
+
s.abort = null;
|
|
1097
|
+
}
|
|
1098
|
+
})();
|
|
1099
|
+
s.connecting = run.catch(() => void 0);
|
|
1100
|
+
await run;
|
|
1101
|
+
return this.status(name);
|
|
1102
|
+
}
|
|
1103
|
+
async disconnect(name) {
|
|
1104
|
+
getServer(this.settings, name);
|
|
1105
|
+
const s = this.#slots.get(name);
|
|
1106
|
+
if (!s) return;
|
|
1107
|
+
s.abort?.abort();
|
|
1108
|
+
const c = s.conn;
|
|
1109
|
+
s.conn = null;
|
|
1110
|
+
s.tools = [];
|
|
1111
|
+
s.pid = null;
|
|
1112
|
+
s.state = "disconnected";
|
|
1113
|
+
s.lastError = null;
|
|
1114
|
+
await c?.close();
|
|
1115
|
+
}
|
|
1116
|
+
async reconnect(name, signal) {
|
|
1117
|
+
await this.disconnect(name);
|
|
1118
|
+
return this.connect(name, signal);
|
|
1119
|
+
}
|
|
1120
|
+
async refresh(name, signal) {
|
|
1121
|
+
this.#check(name);
|
|
1122
|
+
const s = this.#slots.get(name);
|
|
1123
|
+
if (!s?.conn || s.conn.closed) throw new McpError("not-connected", `Server "${name}" is not connected.`, `Connect it: zg mcp connect ${name}`);
|
|
1124
|
+
const remote = await s.conn.listTools(this.settings.maxToolsPerServer, signal);
|
|
1125
|
+
await loadValidator();
|
|
1126
|
+
const adapted = adaptTools(name, remote);
|
|
1127
|
+
s.tools = adapted.tools;
|
|
1128
|
+
s.skipped = adapted.skipped;
|
|
1129
|
+
return this.status(name);
|
|
1130
|
+
}
|
|
1131
|
+
skipped(name) {
|
|
1132
|
+
return this.#slots.get(name)?.skipped ?? [];
|
|
1133
|
+
}
|
|
1134
|
+
/** Tools the AI may be offered: connected servers only, with denied tools left out. */
|
|
1135
|
+
tools(opts = {}) {
|
|
1136
|
+
const out = [];
|
|
1137
|
+
const cfg = this.settings;
|
|
1138
|
+
if (!cfg.enabled) return out;
|
|
1139
|
+
for (const [name, s] of this.#slots) {
|
|
1140
|
+
const server = cfg.servers[name];
|
|
1141
|
+
if (!server || !server.enabled || !this.isConnected(name)) continue;
|
|
1142
|
+
for (const t of s.tools) if (opts.includeDenied || server.toolPolicy[t.name] !== "deny") out.push(t);
|
|
1143
|
+
}
|
|
1144
|
+
return out.sort((a, b) => a.id.localeCompare(b.id));
|
|
1145
|
+
}
|
|
1146
|
+
findTool(id) {
|
|
1147
|
+
return this.tools({ includeDenied: true }).find((t) => t.id === id) ?? null;
|
|
1148
|
+
}
|
|
1149
|
+
/** Validate, call, normalize. The caller has ALREADY obtained any approval; nothing here decides policy. */
|
|
1150
|
+
async callTool(id, args, signal) {
|
|
1151
|
+
const tool = this.findTool(id);
|
|
1152
|
+
if (!tool) throw new McpError("unknown-tool", `No connected tool "${id.slice(0, 80)}".`, "See: zg mcp tools");
|
|
1153
|
+
this.#check(tool.server);
|
|
1154
|
+
await loadValidator();
|
|
1155
|
+
const valid = validateArgs(tool, args);
|
|
1156
|
+
const conn = this.#slots.get(tool.server)?.conn;
|
|
1157
|
+
if (!conn || conn.closed) throw new McpError("not-connected", `Server "${tool.server}" is not connected.`);
|
|
1158
|
+
const raw = await conn.callTool(tool.name, valid, signal);
|
|
1159
|
+
return normalizeResult(raw, this.settings.maxResultBytes);
|
|
1160
|
+
}
|
|
1161
|
+
async listResources(name, signal) {
|
|
1162
|
+
const c = this.#conn(name);
|
|
1163
|
+
return c.listResources(500, signal);
|
|
1164
|
+
}
|
|
1165
|
+
async readResource(name, uri, signal) {
|
|
1166
|
+
return this.#conn(name).readResource(uri, signal);
|
|
1167
|
+
}
|
|
1168
|
+
async listPrompts(name, signal) {
|
|
1169
|
+
return this.#conn(name).listPrompts(200, signal);
|
|
1170
|
+
}
|
|
1171
|
+
async getPrompt(name, prompt, args, signal) {
|
|
1172
|
+
return this.#conn(name).getPrompt(prompt, args, signal);
|
|
1173
|
+
}
|
|
1174
|
+
#conn(name) {
|
|
1175
|
+
this.#check(name);
|
|
1176
|
+
const c = this.#slots.get(name)?.conn;
|
|
1177
|
+
if (!c || c.closed) throw new McpError("not-connected", `Server "${name}" is not connected.`, `Connect it: zg mcp connect ${name}`);
|
|
1178
|
+
return c;
|
|
1179
|
+
}
|
|
1180
|
+
/** Last lines the server wrote to its error stream (scrubbed). For diagnostics only. */
|
|
1181
|
+
stderrTail(name) {
|
|
1182
|
+
return redactSecrets(this.#slots.get(name)?.conn?.stderrTail ?? "").trim().slice(-500);
|
|
1183
|
+
}
|
|
1184
|
+
/** Stops every server zg started. Safe to call more than once. */
|
|
1185
|
+
async shutdown() {
|
|
1186
|
+
await Promise.all([...this.#slots.keys()].map((n) => this.disconnect(n).catch(() => void 0)));
|
|
1187
|
+
}
|
|
1188
|
+
};
|
|
1189
|
+
|
|
1190
|
+
// src/mcp/registry.ts
|
|
1191
|
+
var McpToolRegistry = class {
|
|
1192
|
+
#m;
|
|
1193
|
+
constructor(m) {
|
|
1194
|
+
this.#m = m;
|
|
1195
|
+
}
|
|
1196
|
+
list() {
|
|
1197
|
+
return this.#m.tools();
|
|
1198
|
+
}
|
|
1199
|
+
get(id) {
|
|
1200
|
+
const t = this.#m.findTool(id);
|
|
1201
|
+
return t && this.#m.settings.servers[t.server]?.toolPolicy[t.name] !== "deny" ? t : null;
|
|
1202
|
+
}
|
|
1203
|
+
/** One-line facts for a model prompt (untrusted text is truncated). */
|
|
1204
|
+
digest(max = 60) {
|
|
1205
|
+
return this.list().slice(0, max).map((t) => `${t.id} [${t.sensitivity}] ${t.description.slice(0, 160)}`);
|
|
1206
|
+
}
|
|
1207
|
+
};
|
|
1208
|
+
|
|
1209
|
+
// src/mcp/service.ts
|
|
1210
|
+
var McpService = class {
|
|
1211
|
+
manager;
|
|
1212
|
+
catalog;
|
|
1213
|
+
tokens;
|
|
1214
|
+
resources;
|
|
1215
|
+
prompts;
|
|
1216
|
+
registry;
|
|
1217
|
+
#d;
|
|
1218
|
+
constructor(deps) {
|
|
1219
|
+
this.#d = deps;
|
|
1220
|
+
this.catalog = deps.catalog ?? new CatalogManager();
|
|
1221
|
+
this.tokens = new TokenStore(deps.configDir);
|
|
1222
|
+
this.manager = new McpManager({
|
|
1223
|
+
settings: deps.settings,
|
|
1224
|
+
env: deps.env,
|
|
1225
|
+
windows: deps.windows,
|
|
1226
|
+
termux: deps.termux,
|
|
1227
|
+
projectRoot: deps.projectRoot,
|
|
1228
|
+
...deps.now ? { now: deps.now } : {},
|
|
1229
|
+
oauth: async (name, server) => await this.tokens.hasTokens(name) && server.url ? oauthProviderFor(this.tokens, name, server.url) : void 0
|
|
1230
|
+
});
|
|
1231
|
+
this.resources = new ResourceManager(this.manager);
|
|
1232
|
+
this.prompts = new PromptManager(this.manager);
|
|
1233
|
+
this.registry = new McpToolRegistry(this.manager);
|
|
1234
|
+
}
|
|
1235
|
+
get settings() {
|
|
1236
|
+
return this.#d.settings();
|
|
1237
|
+
}
|
|
1238
|
+
async setEnabled(on) {
|
|
1239
|
+
await this.#d.update({ ...this.settings, enabled: on });
|
|
1240
|
+
if (!on) await this.manager.shutdown();
|
|
1241
|
+
}
|
|
1242
|
+
async add(name, server, opts = {}) {
|
|
1243
|
+
await this.#d.update(addServer(this.settings, name, server, opts));
|
|
1244
|
+
}
|
|
1245
|
+
async remove(name) {
|
|
1246
|
+
getServer(this.settings, name);
|
|
1247
|
+
await this.manager.disconnect(name);
|
|
1248
|
+
const hadCredentials = await this.tokens.remove(name);
|
|
1249
|
+
await this.#d.update(removeServer(this.settings, name));
|
|
1250
|
+
return { hadCredentials };
|
|
1251
|
+
}
|
|
1252
|
+
async setServerEnabled(name, on) {
|
|
1253
|
+
if (!on) await this.manager.disconnect(name);
|
|
1254
|
+
await this.#d.update(updateServer(this.settings, name, { enabled: on }));
|
|
1255
|
+
}
|
|
1256
|
+
async setPolicy(server, tool, policy) {
|
|
1257
|
+
await this.#d.update(setToolPolicy(this.settings, server, tool, policy));
|
|
1258
|
+
}
|
|
1259
|
+
/** OAuth sign-in for a server. Tokens go to the owner-only store; nothing is printed except the URL to open. */
|
|
1260
|
+
async signIn(name, io) {
|
|
1261
|
+
const s = getServer(this.settings, name);
|
|
1262
|
+
if (s.authMethod !== "oauth" || !s.url) throw new McpError("invalid-config", `Server "${name}" does not use OAuth.`);
|
|
1263
|
+
await loginOAuth(this.tokens, name, { serverUrl: s.url, onUrl: io.onUrl, ...io.manualInput ? { manualInput: io.manualInput } : {}, ...io.signal ? { signal: io.signal } : {} });
|
|
1264
|
+
}
|
|
1265
|
+
async signOut(name) {
|
|
1266
|
+
getServer(this.settings, name);
|
|
1267
|
+
await this.manager.disconnect(name);
|
|
1268
|
+
return this.tokens.remove(name);
|
|
1269
|
+
}
|
|
1270
|
+
/**
|
|
1271
|
+
* Adds the server a catalog plan describes and connects it. The caller has ALREADY shown `plan.summary` and obtained the user's
|
|
1272
|
+
* approval. "Connected" is reported only if sign-in (when needed), initialization and tool discovery all succeeded; otherwise
|
|
1273
|
+
* the server stays configured but disconnected, and the error says why.
|
|
1274
|
+
*/
|
|
1275
|
+
async connectPlan(plan, io) {
|
|
1276
|
+
await this.add(plan.name, plan.server, io.replace ? { replace: true } : {});
|
|
1277
|
+
try {
|
|
1278
|
+
if (plan.server.authMethod === "oauth") await this.signIn(plan.name, io);
|
|
1279
|
+
return await this.manager.connect(plan.name, io.signal);
|
|
1280
|
+
} catch (err) {
|
|
1281
|
+
throw toMcpError(err);
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
/** Read-only diagnostics. Never connects, never prints a credential. */
|
|
1285
|
+
async doctor(opts = {}) {
|
|
1286
|
+
const s = this.settings;
|
|
1287
|
+
const out = [];
|
|
1288
|
+
out.push({ id: "mcp-enabled", label: "MCP", status: s.enabled ? "pass" : "info", detail: s.enabled ? `on, ${Object.keys(s.servers).length} server(s) configured` : "off", ...s.enabled ? {} : { hint: "turn on with: zg config set mcp.enabled true" } });
|
|
1289
|
+
const names = opts.server ? [opts.server] : Object.keys(s.servers).sort();
|
|
1290
|
+
for (const name of names) {
|
|
1291
|
+
let server;
|
|
1292
|
+
try {
|
|
1293
|
+
server = getServer(s, name);
|
|
1294
|
+
} catch (e) {
|
|
1295
|
+
out.push({ id: `mcp-${name}`, label: `mcp ${name}`.slice(0, 18), status: "fail", detail: describeMcpError(e) });
|
|
1296
|
+
continue;
|
|
1297
|
+
}
|
|
1298
|
+
const label = `mcp ${name}`.slice(0, 18);
|
|
1299
|
+
const problems = [];
|
|
1300
|
+
const notes = [`${server.transport}`, describeTarget(server)];
|
|
1301
|
+
if (server.transport === "stdio") {
|
|
1302
|
+
try {
|
|
1303
|
+
await resolveCommand(server.command ?? "", { env: this.#d.env, windows: this.#d.windows, termux: this.#d.termux });
|
|
1304
|
+
notes.push("program found");
|
|
1305
|
+
} catch (e) {
|
|
1306
|
+
problems.push(describeMcpError(e));
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
for (const [child, host] of Object.entries(server.env)) if (!this.#d.env[host]) problems.push(`environment variable ${host} (for ${child}) is not set`);
|
|
1310
|
+
if (server.authMethod === "env" && server.credentialEnv && !this.#d.env[server.credentialEnv]) problems.push(`environment variable ${server.credentialEnv} is not set`);
|
|
1311
|
+
if (server.authMethod === "oauth") notes.push(await this.tokens.hasTokens(name) ? "signed in (credentials stored locally)" : "not signed in");
|
|
1312
|
+
if (server.projectPath && server.projectPath !== this.#d.projectRoot()) notes.push("belongs to another project");
|
|
1313
|
+
const st = this.manager.status(name);
|
|
1314
|
+
notes.push(`state: ${st.state}`);
|
|
1315
|
+
if (st.lastError) problems.push(`last error: ${st.lastError}`);
|
|
1316
|
+
if (!server.enabled) notes.push("disabled");
|
|
1317
|
+
out.push({ id: `mcp-${name}`, label, status: problems.length > 0 ? st.state === "failed" ? "fail" : "warn" : "pass", detail: [...notes, ...problems].join("; ").slice(0, 400) });
|
|
1318
|
+
}
|
|
1319
|
+
return out;
|
|
1320
|
+
}
|
|
1321
|
+
/** Checks of the built-in catalog itself (shape and safety rules, not network). */
|
|
1322
|
+
catalogDoctor() {
|
|
1323
|
+
const problems = validateCatalog(this.catalog.all());
|
|
1324
|
+
const all = this.catalog.all();
|
|
1325
|
+
const count = (a) => all.filter((e) => e.availability === a).length;
|
|
1326
|
+
return [
|
|
1327
|
+
{ id: "catalog", label: "Integration catalog", status: problems.length ? "fail" : "pass", detail: problems.length ? problems.slice(0, 3).join("; ") : `${all.length} entries (${count("verified")} verified, ${count("restricted")} restricted, ${count("unverified-details")} details unverified, ${count("community-dependent")} community-dependent)` },
|
|
1328
|
+
{ id: "catalog-date", label: "Catalog checked", status: "info", detail: `vendor docs were read on ${all.map((e) => e.verification.checked).sort().pop() ?? "?"}; services change, so re-check an entry with: zg integrations inspect <id>` }
|
|
1329
|
+
];
|
|
1330
|
+
}
|
|
1331
|
+
};
|
|
1332
|
+
|
|
1333
|
+
export {
|
|
1334
|
+
loadValidator,
|
|
1335
|
+
argWarnings,
|
|
1336
|
+
validateArgs,
|
|
1337
|
+
McpService
|
|
1338
|
+
};
|