@supabeast/mcp 0.1.1 → 0.2.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/README.md +10 -2
- package/package.json +5 -2
- package/skills/supabeast/SKILL.md +1 -1
- package/src/api.mjs +383 -0
- package/src/browser.mjs +195 -0
- package/src/check.mjs +17 -14
- package/src/clients.mjs +311 -72
- package/src/constants.mjs +11 -2
- package/src/credentials.mjs +109 -0
- package/src/index.mjs +1316 -110
- package/src/local-project.mjs +110 -0
- package/src/prompt.mjs +56 -0
package/src/clients.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
1
|
+
import { chmodSync, existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { CLIENT_LABELS, DEFAULT_MCP_URL, SUPPORTED_CLIENTS } from "./constants.mjs";
|
|
@@ -13,6 +13,42 @@ function isPlainObject(value) {
|
|
|
13
13
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
function deepEqualPlain(a, b) {
|
|
17
|
+
if (a === b) return true;
|
|
18
|
+
if (!isPlainObject(a) || !isPlainObject(b)) return false;
|
|
19
|
+
const keysA = Object.keys(a);
|
|
20
|
+
const keysB = Object.keys(b);
|
|
21
|
+
if (keysA.length !== keysB.length) return false;
|
|
22
|
+
return keysA.every((key) => Object.hasOwn(b, key) && deepEqualPlain(a[key], b[key]));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function cloneEntry(entry) {
|
|
26
|
+
if (!isPlainObject(entry)) return entry;
|
|
27
|
+
return isPlainObject(entry.headers)
|
|
28
|
+
? { ...entry, headers: { ...entry.headers } }
|
|
29
|
+
: { ...entry };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function entryHasBearerAuth(entry) {
|
|
33
|
+
return (
|
|
34
|
+
isPlainObject(entry) &&
|
|
35
|
+
isPlainObject(entry.headers) &&
|
|
36
|
+
typeof entry.headers.Authorization === "string" &&
|
|
37
|
+
/^Bearer\s+\S+$/i.test(entry.headers.Authorization)
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function configHasBearerEntry(rawContent, rootKey) {
|
|
42
|
+
if (!rawContent || rawContent.trim() === "") return false;
|
|
43
|
+
try {
|
|
44
|
+
const parsed = JSON.parse(rawContent);
|
|
45
|
+
const entry = isPlainObject(parsed) && isPlainObject(parsed[rootKey]) ? parsed[rootKey].supabeast : null;
|
|
46
|
+
return entryHasBearerAuth(entry);
|
|
47
|
+
} catch {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
16
52
|
function resolveEnvDir(envValue, fallbackParts, pathApi) {
|
|
17
53
|
if (typeof envValue === "string" && envValue.trim()) {
|
|
18
54
|
return envValue.trim();
|
|
@@ -46,8 +82,52 @@ function readOptionalUtf8(filePath) {
|
|
|
46
82
|
return { existed: true, content: readFileSync(filePath, "utf8") };
|
|
47
83
|
}
|
|
48
84
|
|
|
49
|
-
|
|
50
|
-
|
|
85
|
+
function buildAntigravityEntry(url, bearerToken, scope) {
|
|
86
|
+
// Hard guardrail: never emit Bearer credentials into repository/project-scoped configs.
|
|
87
|
+
const token = scope === "user" && typeof bearerToken === "string" ? bearerToken.trim() : "";
|
|
88
|
+
return token
|
|
89
|
+
? { serverUrl: url, headers: { Authorization: `Bearer ${token}` } }
|
|
90
|
+
: { serverUrl: url };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Discover existing T3 Code Antigravity provider `mcp_config.json` paths on disk without fabricating profiles. */
|
|
94
|
+
export function findT3AntigravityConfigPaths(options = {}) {
|
|
95
|
+
const { homeDir = os.homedir(), env = process.env, pathApi = path } = options;
|
|
96
|
+
const t3UserdataDir = resolveEnvDir(
|
|
97
|
+
env?.T3_USERDATA_DIR,
|
|
98
|
+
[homeDir, ".t3", "userdata"],
|
|
99
|
+
pathApi,
|
|
100
|
+
);
|
|
101
|
+
const antigravityDir = pathApi.join(t3UserdataDir, "providers", "antigravity");
|
|
102
|
+
if (!existsSync(antigravityDir)) {
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
let entries;
|
|
106
|
+
try {
|
|
107
|
+
entries = readdirSync(antigravityDir, { withFileTypes: true });
|
|
108
|
+
} catch {
|
|
109
|
+
return [];
|
|
110
|
+
}
|
|
111
|
+
const profiles = entries
|
|
112
|
+
.filter((entry) => entry.isDirectory() && !entry.name.startsWith("."))
|
|
113
|
+
.map((entry) => entry.name)
|
|
114
|
+
.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
115
|
+
|
|
116
|
+
const configPaths = [];
|
|
117
|
+
for (const profile of profiles) {
|
|
118
|
+
const profileDir = pathApi.join(antigravityDir, profile);
|
|
119
|
+
if (
|
|
120
|
+
existsSync(pathApi.join(profileDir, "config")) ||
|
|
121
|
+
existsSync(pathApi.join(profileDir, "antigravity-acp"))
|
|
122
|
+
) {
|
|
123
|
+
configPaths.push(pathApi.join(profileDir, "config", "mcp_config.json"));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return configPaths;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Resolve all config targets and skill paths for a coding agent client (supports multi-profile T3 Code). */
|
|
130
|
+
export function resolveClientTargets(clientId, options = {}) {
|
|
51
131
|
const {
|
|
52
132
|
scope = "user",
|
|
53
133
|
homeDir = os.homedir(),
|
|
@@ -55,6 +135,7 @@ export function resolveClientTarget(clientId, options = {}) {
|
|
|
55
135
|
env = process.env,
|
|
56
136
|
pathApi = path,
|
|
57
137
|
url = DEFAULT_MCP_URL,
|
|
138
|
+
bearerToken,
|
|
58
139
|
} = options;
|
|
59
140
|
|
|
60
141
|
if (!SUPPORTED_CLIENTS.includes(clientId)) {
|
|
@@ -69,66 +150,153 @@ export function resolveClientTarget(clientId, options = {}) {
|
|
|
69
150
|
const xdgConfigHome = resolveEnvDir(env?.XDG_CONFIG_HOME, [homeDir, ".config"], pathApi);
|
|
70
151
|
|
|
71
152
|
if (clientId === "claude") {
|
|
72
|
-
return
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
:
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
:
|
|
85
|
-
|
|
153
|
+
return [
|
|
154
|
+
{
|
|
155
|
+
clientId,
|
|
156
|
+
label: CLIENT_LABELS[clientId],
|
|
157
|
+
scope,
|
|
158
|
+
format: "json",
|
|
159
|
+
rootKey: "mcpServers",
|
|
160
|
+
urlKey: "url",
|
|
161
|
+
entry: { type: "http", url },
|
|
162
|
+
configPath: isProject
|
|
163
|
+
? pathApi.join(cwd, ".mcp.json")
|
|
164
|
+
: pathApi.join(homeDir, ".claude.json"),
|
|
165
|
+
skillPath: isProject
|
|
166
|
+
? pathApi.join(cwd, ".claude", "skills", "supabeast", "SKILL.md")
|
|
167
|
+
: pathApi.join(homeDir, ".claude", "skills", "supabeast", "SKILL.md"),
|
|
168
|
+
},
|
|
169
|
+
];
|
|
86
170
|
}
|
|
87
171
|
if (clientId === "cursor") {
|
|
88
|
-
return
|
|
172
|
+
return [
|
|
173
|
+
{
|
|
174
|
+
clientId,
|
|
175
|
+
label: CLIENT_LABELS[clientId],
|
|
176
|
+
scope,
|
|
177
|
+
format: "json",
|
|
178
|
+
rootKey: "mcpServers",
|
|
179
|
+
urlKey: "url",
|
|
180
|
+
entry: { url },
|
|
181
|
+
configPath: isProject
|
|
182
|
+
? pathApi.join(cwd, ".cursor", "mcp.json")
|
|
183
|
+
: pathApi.join(homeDir, ".cursor", "mcp.json"),
|
|
184
|
+
skillPath: isProject
|
|
185
|
+
? pathApi.join(cwd, ".cursor", "skills", "supabeast", "SKILL.md")
|
|
186
|
+
: pathApi.join(homeDir, ".cursor", "skills", "supabeast", "SKILL.md"),
|
|
187
|
+
},
|
|
188
|
+
];
|
|
189
|
+
}
|
|
190
|
+
if (clientId === "codex") {
|
|
191
|
+
return [
|
|
192
|
+
{
|
|
193
|
+
clientId,
|
|
194
|
+
label: CLIENT_LABELS[clientId],
|
|
195
|
+
scope,
|
|
196
|
+
format: "toml",
|
|
197
|
+
urlKey: "url",
|
|
198
|
+
entry: { url },
|
|
199
|
+
configPath: isProject
|
|
200
|
+
? pathApi.join(cwd, ".codex", "config.toml")
|
|
201
|
+
: pathApi.join(codexHome, "config.toml"),
|
|
202
|
+
skillPath: isProject
|
|
203
|
+
? pathApi.join(cwd, ".agents", "skills", "supabeast", "SKILL.md")
|
|
204
|
+
: pathApi.join(homeDir, ".agents", "skills", "supabeast", "SKILL.md"),
|
|
205
|
+
},
|
|
206
|
+
];
|
|
207
|
+
}
|
|
208
|
+
if (clientId === "gemini") {
|
|
209
|
+
return [
|
|
210
|
+
{
|
|
211
|
+
clientId,
|
|
212
|
+
label: CLIENT_LABELS[clientId],
|
|
213
|
+
scope,
|
|
214
|
+
format: "json",
|
|
215
|
+
rootKey: "mcpServers",
|
|
216
|
+
urlKey: "httpUrl",
|
|
217
|
+
entry: { httpUrl: url },
|
|
218
|
+
configPath: isProject
|
|
219
|
+
? pathApi.join(cwd, ".gemini", "settings.json")
|
|
220
|
+
: pathApi.join(homeDir, ".gemini", "settings.json"),
|
|
221
|
+
skillPath: isProject
|
|
222
|
+
? pathApi.join(cwd, ".gemini", "skills", "supabeast", "SKILL.md")
|
|
223
|
+
: pathApi.join(homeDir, ".gemini", "skills", "supabeast", "SKILL.md"),
|
|
224
|
+
},
|
|
225
|
+
];
|
|
226
|
+
}
|
|
227
|
+
if (clientId === "antigravity") {
|
|
228
|
+
return [
|
|
229
|
+
{
|
|
230
|
+
clientId,
|
|
231
|
+
label: CLIENT_LABELS[clientId],
|
|
232
|
+
scope,
|
|
233
|
+
format: "json",
|
|
234
|
+
rootKey: "mcpServers",
|
|
235
|
+
urlKey: "serverUrl",
|
|
236
|
+
supportsBearerHeader: !isProject,
|
|
237
|
+
entry: buildAntigravityEntry(url, bearerToken, scope),
|
|
238
|
+
configPath: isProject
|
|
239
|
+
? pathApi.join(cwd, ".agents", "mcp_config.json")
|
|
240
|
+
: pathApi.join(homeDir, ".gemini", "config", "mcp_config.json"),
|
|
241
|
+
skillPath: isProject
|
|
242
|
+
? pathApi.join(cwd, ".agents", "skills", "supabeast", "SKILL.md")
|
|
243
|
+
: pathApi.join(homeDir, ".gemini", "config", "skills", "supabeast", "SKILL.md"),
|
|
244
|
+
},
|
|
245
|
+
];
|
|
246
|
+
}
|
|
247
|
+
if (clientId === "t3") {
|
|
248
|
+
if (isProject) {
|
|
249
|
+
return [
|
|
250
|
+
{
|
|
251
|
+
clientId,
|
|
252
|
+
label: CLIENT_LABELS[clientId],
|
|
253
|
+
scope,
|
|
254
|
+
format: "json",
|
|
255
|
+
rootKey: "mcpServers",
|
|
256
|
+
urlKey: "serverUrl",
|
|
257
|
+
supportsBearerHeader: false,
|
|
258
|
+
entry: { serverUrl: url },
|
|
259
|
+
configPath: pathApi.join(cwd, ".agents", "mcp_config.json"),
|
|
260
|
+
skillPath: pathApi.join(cwd, ".agents", "skills", "supabeast", "SKILL.md"),
|
|
261
|
+
},
|
|
262
|
+
];
|
|
263
|
+
}
|
|
264
|
+
const t3SkillPath = pathApi.join(homeDir, ".agents", "skills", "supabeast", "SKILL.md");
|
|
265
|
+
return findT3AntigravityConfigPaths({ homeDir, env, pathApi }).map((configPath) => ({
|
|
89
266
|
clientId,
|
|
90
267
|
label: CLIENT_LABELS[clientId],
|
|
91
268
|
scope,
|
|
92
269
|
format: "json",
|
|
93
270
|
rootKey: "mcpServers",
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
skillPath:
|
|
99
|
-
|
|
100
|
-
: pathApi.join(homeDir, ".cursor", "skills", "supabeast", "SKILL.md"),
|
|
101
|
-
};
|
|
271
|
+
urlKey: "serverUrl",
|
|
272
|
+
supportsBearerHeader: true,
|
|
273
|
+
entry: buildAntigravityEntry(url, bearerToken, scope),
|
|
274
|
+
configPath,
|
|
275
|
+
skillPath: t3SkillPath,
|
|
276
|
+
}));
|
|
102
277
|
}
|
|
103
|
-
|
|
104
|
-
|
|
278
|
+
return [
|
|
279
|
+
{
|
|
105
280
|
clientId,
|
|
106
281
|
label: CLIENT_LABELS[clientId],
|
|
107
282
|
scope,
|
|
108
|
-
format: "
|
|
109
|
-
|
|
283
|
+
format: "json",
|
|
284
|
+
rootKey: "mcp",
|
|
285
|
+
urlKey: "url",
|
|
286
|
+
entry: { type: "remote", url },
|
|
110
287
|
configPath: isProject
|
|
111
|
-
? pathApi.join(cwd, ".
|
|
112
|
-
: pathApi.join(
|
|
288
|
+
? pathApi.join(cwd, "opencode.json")
|
|
289
|
+
: pathApi.join(xdgConfigHome, "opencode", "opencode.json"),
|
|
113
290
|
skillPath: isProject
|
|
114
291
|
? pathApi.join(cwd, ".agents", "skills", "supabeast", "SKILL.md")
|
|
115
292
|
: pathApi.join(homeDir, ".agents", "skills", "supabeast", "SKILL.md"),
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
rootKey: "mcp",
|
|
124
|
-
entry: { type: "remote", url },
|
|
125
|
-
configPath: isProject
|
|
126
|
-
? pathApi.join(cwd, "opencode.json")
|
|
127
|
-
: pathApi.join(xdgConfigHome, "opencode", "opencode.json"),
|
|
128
|
-
skillPath: isProject
|
|
129
|
-
? pathApi.join(cwd, ".agents", "skills", "supabeast", "SKILL.md")
|
|
130
|
-
: pathApi.join(homeDir, ".agents", "skills", "supabeast", "SKILL.md"),
|
|
131
|
-
};
|
|
293
|
+
},
|
|
294
|
+
];
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/** Resolve primary config path, skill path, and entry builder for a coding agent client and scope. */
|
|
298
|
+
export function resolveClientTarget(clientId, options = {}) {
|
|
299
|
+
return resolveClientTargets(clientId, options)[0] ?? null;
|
|
132
300
|
}
|
|
133
301
|
|
|
134
302
|
/** Detect coding agent clients present on disk in user home or current workspace. */
|
|
@@ -152,6 +320,27 @@ export function detectInstalledClients(options = {}) {
|
|
|
152
320
|
if (existsSync(codexHome) || existsSync(pathApi.join(cwd, ".codex"))) {
|
|
153
321
|
detected.push("codex");
|
|
154
322
|
}
|
|
323
|
+
if (
|
|
324
|
+
existsSync(pathApi.join(homeDir, ".gemini", "settings.json")) ||
|
|
325
|
+
existsSync(pathApi.join(homeDir, ".gemini", "oauth_creds.json")) ||
|
|
326
|
+
existsSync(pathApi.join(homeDir, ".gemini", "google_accounts.json")) ||
|
|
327
|
+
existsSync(pathApi.join(homeDir, ".gemini", "mcp-oauth-tokens.json")) ||
|
|
328
|
+
existsSync(pathApi.join(homeDir, ".gemini", "skills")) ||
|
|
329
|
+
existsSync(pathApi.join(cwd, ".gemini"))
|
|
330
|
+
) {
|
|
331
|
+
detected.push("gemini");
|
|
332
|
+
}
|
|
333
|
+
if (
|
|
334
|
+
existsSync(pathApi.join(homeDir, ".gemini", "config")) ||
|
|
335
|
+
existsSync(pathApi.join(homeDir, ".gemini", "antigravity")) ||
|
|
336
|
+
existsSync(pathApi.join(homeDir, ".gemini", "antigravity-cli")) ||
|
|
337
|
+
existsSync(pathApi.join(cwd, ".agents", "mcp_config.json"))
|
|
338
|
+
) {
|
|
339
|
+
detected.push("antigravity");
|
|
340
|
+
}
|
|
341
|
+
if (findT3AntigravityConfigPaths({ homeDir, env, pathApi }).length > 0) {
|
|
342
|
+
detected.push("t3");
|
|
343
|
+
}
|
|
155
344
|
if (
|
|
156
345
|
existsSync(pathApi.join(xdgConfigHome, "opencode")) ||
|
|
157
346
|
existsSync(pathApi.join(cwd, "opencode.json")) ||
|
|
@@ -163,7 +352,7 @@ export function detectInstalledClients(options = {}) {
|
|
|
163
352
|
}
|
|
164
353
|
|
|
165
354
|
/** Merge SupaBeast Remote MCP entry into a JSON config string without disturbing unrelated settings. */
|
|
166
|
-
export function mergeJsonMcpConfig(rawText, rootKey, desiredEntry, existed = false) {
|
|
355
|
+
export function mergeJsonMcpConfig(rawText, rootKey, desiredEntry, existed = false, options = {}) {
|
|
167
356
|
let doc = {};
|
|
168
357
|
if (existed && rawText.trim() !== "") {
|
|
169
358
|
let parsed;
|
|
@@ -194,12 +383,15 @@ export function mergeJsonMcpConfig(rawText, rootKey, desiredEntry, existed = fal
|
|
|
194
383
|
|
|
195
384
|
const existingSection = currentRoot ?? {};
|
|
196
385
|
const existingEntry = existingSection.supabeast;
|
|
197
|
-
const
|
|
198
|
-
|
|
386
|
+
const effectiveEntry =
|
|
387
|
+
options.preserveExistingHeaders &&
|
|
388
|
+
!Object.hasOwn(desiredEntry, "headers") &&
|
|
199
389
|
isPlainObject(existingEntry) &&
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
390
|
+
isPlainObject(existingEntry.headers)
|
|
391
|
+
? { ...desiredEntry, headers: { ...existingEntry.headers } }
|
|
392
|
+
: cloneEntry(desiredEntry);
|
|
393
|
+
|
|
394
|
+
if (isPlainObject(existingEntry) && deepEqualPlain(existingEntry, effectiveEntry)) {
|
|
203
395
|
return { ok: true, action: "unchanged", content: rawText };
|
|
204
396
|
}
|
|
205
397
|
|
|
@@ -208,7 +400,7 @@ export function mergeJsonMcpConfig(rawText, rootKey, desiredEntry, existed = fal
|
|
|
208
400
|
...doc,
|
|
209
401
|
[rootKey]: {
|
|
210
402
|
...existingSection,
|
|
211
|
-
supabeast:
|
|
403
|
+
supabeast: effectiveEntry,
|
|
212
404
|
},
|
|
213
405
|
};
|
|
214
406
|
const content = JSON.stringify(nextDoc, null, 2).replace(/\n/g, eol) + eol;
|
|
@@ -268,14 +460,20 @@ export function mergeCodexTomlConfig(rawText, url, existed = false) {
|
|
|
268
460
|
|
|
269
461
|
/** Write or preview Remote MCP configuration for a resolved client target. */
|
|
270
462
|
export function applyClientConfig(target, options = {}) {
|
|
271
|
-
const { dryRun = false, pathApi = path } = options;
|
|
463
|
+
const { dryRun = false, pathApi = path, platform = process.platform } = options;
|
|
272
464
|
const { existed, content: rawText } = readOptionalUtf8(target.configPath);
|
|
465
|
+
const preserveExistingHeaders = Boolean(target.supportsBearerHeader && !target.entry.headers);
|
|
273
466
|
const merged =
|
|
274
467
|
target.format === "toml"
|
|
275
468
|
? mergeCodexTomlConfig(rawText, target.entry.url, existed)
|
|
276
|
-
: mergeJsonMcpConfig(rawText, target.rootKey, target.entry, existed
|
|
469
|
+
: mergeJsonMcpConfig(rawText, target.rootKey, target.entry, existed, {
|
|
470
|
+
preserveExistingHeaders,
|
|
471
|
+
});
|
|
277
472
|
|
|
278
473
|
if (!merged.ok) {
|
|
474
|
+
const safeManualEntry = isPlainObject(target.entry)
|
|
475
|
+
? Object.fromEntries(Object.entries(target.entry).filter(([key]) => key !== "headers"))
|
|
476
|
+
: target.entry;
|
|
279
477
|
return {
|
|
280
478
|
clientId: target.clientId,
|
|
281
479
|
label: target.label,
|
|
@@ -283,13 +481,27 @@ export function applyClientConfig(target, options = {}) {
|
|
|
283
481
|
path: target.configPath,
|
|
284
482
|
status: "error",
|
|
285
483
|
reason: merged.reason,
|
|
286
|
-
manualEntry:
|
|
484
|
+
manualEntry: safeManualEntry,
|
|
287
485
|
};
|
|
288
486
|
}
|
|
289
487
|
|
|
488
|
+
const hasBearerAuth =
|
|
489
|
+
target.format === "json" &&
|
|
490
|
+
(entryHasBearerAuth(target.entry) ||
|
|
491
|
+
(preserveExistingHeaders && configHasBearerEntry(merged.content, target.rootKey)));
|
|
492
|
+
|
|
290
493
|
if (!dryRun && merged.action !== "unchanged") {
|
|
291
494
|
mkdirSync(pathApi.dirname(target.configPath), { recursive: true });
|
|
292
|
-
writeFileSync(
|
|
495
|
+
writeFileSync(
|
|
496
|
+
target.configPath,
|
|
497
|
+
merged.content,
|
|
498
|
+
hasBearerAuth ? { encoding: "utf8", mode: 0o600 } : "utf8",
|
|
499
|
+
);
|
|
500
|
+
if (hasBearerAuth && platform !== "win32") {
|
|
501
|
+
chmodSync(target.configPath, 0o600);
|
|
502
|
+
}
|
|
503
|
+
} else if (!dryRun && hasBearerAuth && platform !== "win32" && existsSync(target.configPath)) {
|
|
504
|
+
chmodSync(target.configPath, 0o600);
|
|
293
505
|
}
|
|
294
506
|
|
|
295
507
|
return {
|
|
@@ -298,6 +510,7 @@ export function applyClientConfig(target, options = {}) {
|
|
|
298
510
|
scope: target.scope,
|
|
299
511
|
path: target.configPath,
|
|
300
512
|
status: dryRun && merged.action !== "unchanged" ? `would_${merged.action}` : merged.action,
|
|
513
|
+
authMode: hasBearerAuth ? "bearer" : "oauth",
|
|
301
514
|
};
|
|
302
515
|
}
|
|
303
516
|
|
|
@@ -305,42 +518,53 @@ export function applyClientConfig(target, options = {}) {
|
|
|
305
518
|
export function inspectClientConfig(target) {
|
|
306
519
|
const { existed, content } = readOptionalUtf8(target.configPath);
|
|
307
520
|
if (!existed) {
|
|
308
|
-
return { status: "missing", configuredUrl: null };
|
|
521
|
+
return { status: "missing", configuredUrl: null, authMode: "oauth" };
|
|
309
522
|
}
|
|
310
523
|
if (target.format === "toml") {
|
|
311
524
|
const lines = content.split(/\r?\n/);
|
|
312
525
|
const headerIdx = lines.findIndex((line) => CODEX_HEADER_RE.test(line));
|
|
313
|
-
if (headerIdx === -1) return { status: "missing", configuredUrl: null };
|
|
526
|
+
if (headerIdx === -1) return { status: "missing", configuredUrl: null, authMode: "oauth" };
|
|
314
527
|
for (let i = headerIdx + 1; i < lines.length; i++) {
|
|
315
528
|
if (TOML_SECTION_RE.test(lines[i])) break;
|
|
316
529
|
const keyMatch = TOML_URL_KEY_RE.exec(lines[i]);
|
|
317
530
|
if (!keyMatch) continue;
|
|
318
531
|
const parsed = extractTomlString(keyMatch[2]);
|
|
319
|
-
if (!parsed) return { status: "invalid", configuredUrl: null };
|
|
532
|
+
if (!parsed) return { status: "invalid", configuredUrl: null, authMode: "oauth" };
|
|
320
533
|
return {
|
|
321
534
|
status: parsed.value === target.entry.url ? "configured" : "outdated",
|
|
322
535
|
configuredUrl: parsed.value,
|
|
536
|
+
authMode: "oauth",
|
|
323
537
|
};
|
|
324
538
|
}
|
|
325
|
-
return { status: "missing", configuredUrl: null };
|
|
539
|
+
return { status: "missing", configuredUrl: null, authMode: "oauth" };
|
|
326
540
|
}
|
|
327
541
|
|
|
328
|
-
if (content.trim() === "") return { status: "missing", configuredUrl: null };
|
|
542
|
+
if (content.trim() === "") return { status: "missing", configuredUrl: null, authMode: "oauth" };
|
|
329
543
|
let parsed;
|
|
330
544
|
try {
|
|
331
545
|
parsed = JSON.parse(content);
|
|
332
546
|
} catch {
|
|
333
|
-
return { status: "invalid", configuredUrl: null };
|
|
547
|
+
return { status: "invalid", configuredUrl: null, authMode: "oauth" };
|
|
334
548
|
}
|
|
335
|
-
if (!isPlainObject(parsed)) return { status: "invalid", configuredUrl: null };
|
|
549
|
+
if (!isPlainObject(parsed)) return { status: "invalid", configuredUrl: null, authMode: "oauth" };
|
|
336
550
|
const entry = isPlainObject(parsed[target.rootKey]) ? parsed[target.rootKey].supabeast : null;
|
|
337
|
-
if (!isPlainObject(entry)) return { status: "missing", configuredUrl: null };
|
|
338
|
-
const configuredUrl =
|
|
551
|
+
if (!isPlainObject(entry)) return { status: "missing", configuredUrl: null, authMode: "oauth" };
|
|
552
|
+
const configuredUrl = (() => {
|
|
553
|
+
const urlKey = target.urlKey ?? "url";
|
|
554
|
+
if (typeof entry[urlKey] === "string") return entry[urlKey];
|
|
555
|
+
return typeof entry.url === "string" ? entry.url : null;
|
|
556
|
+
})();
|
|
557
|
+
const hasBearerHeader = entryHasBearerAuth(entry);
|
|
558
|
+
const authMode = hasBearerHeader ? "bearer" : "oauth";
|
|
339
559
|
const desiredKeys = Object.keys(target.entry);
|
|
560
|
+
const compareKeys =
|
|
561
|
+
target.supportsBearerHeader && !Object.hasOwn(target.entry, "headers") && hasBearerHeader
|
|
562
|
+
? Object.keys(entry).filter((key) => key !== "headers")
|
|
563
|
+
: Object.keys(entry);
|
|
340
564
|
const matches =
|
|
341
|
-
|
|
342
|
-
desiredKeys.every((key) => entry[key]
|
|
343
|
-
return { status: matches ? "configured" : "outdated", configuredUrl };
|
|
565
|
+
compareKeys.length === desiredKeys.length &&
|
|
566
|
+
desiredKeys.every((key) => deepEqualPlain(entry[key], target.entry[key]));
|
|
567
|
+
return { status: matches ? "configured" : "outdated", configuredUrl, authMode };
|
|
344
568
|
}
|
|
345
569
|
|
|
346
570
|
/** Render manual Remote MCP setup snippet strings for any client (plus T3 Code). */
|
|
@@ -349,7 +573,22 @@ export function renderManualSnippets(mcpUrl = DEFAULT_MCP_URL) {
|
|
|
349
573
|
claude: `claude mcp add --transport http supabeast ${mcpUrl}`,
|
|
350
574
|
cursor: JSON.stringify({ mcpServers: { supabeast: { url: mcpUrl } } }, null, 2),
|
|
351
575
|
codex: `codex mcp add supabeast --url ${mcpUrl}`,
|
|
576
|
+
gemini: `gemini mcp add --transport http supabeast ${mcpUrl}`,
|
|
577
|
+
antigravity: JSON.stringify({ mcpServers: { supabeast: { serverUrl: mcpUrl } } }, null, 2),
|
|
352
578
|
opencode: JSON.stringify({ mcp: { supabeast: { type: "remote", url: mcpUrl } } }, null, 2),
|
|
353
|
-
t3:
|
|
579
|
+
t3: JSON.stringify(
|
|
580
|
+
{
|
|
581
|
+
mcpServers: {
|
|
582
|
+
supabeast: {
|
|
583
|
+
serverUrl: mcpUrl,
|
|
584
|
+
headers: {
|
|
585
|
+
Authorization: "Bearer YOUR_CONNECTION_TOKEN",
|
|
586
|
+
},
|
|
587
|
+
},
|
|
588
|
+
},
|
|
589
|
+
},
|
|
590
|
+
null,
|
|
591
|
+
2,
|
|
592
|
+
),
|
|
354
593
|
};
|
|
355
594
|
}
|
package/src/constants.mjs
CHANGED
|
@@ -4,13 +4,22 @@ export const DEFAULT_MCP_URL = "https://app.supabeast.com/mcp";
|
|
|
4
4
|
export const DEFAULT_APP_ORIGIN = "https://app.supabeast.com";
|
|
5
5
|
export const PROTECTED_RESOURCE_PATH = "/.well-known/oauth-protected-resource/mcp";
|
|
6
6
|
export const AUTH_SERVER_PATH = "/.well-known/oauth-authorization-server";
|
|
7
|
-
export const SUPPORTED_CLIENTS = ["claude", "cursor", "codex", "opencode"];
|
|
8
|
-
export const PACKAGE_VERSION = "0.
|
|
7
|
+
export const SUPPORTED_CLIENTS = ["claude", "cursor", "codex", "gemini", "antigravity", "t3", "opencode"];
|
|
8
|
+
export const PACKAGE_VERSION = "0.2.0";
|
|
9
|
+
|
|
10
|
+
/** Resolve the SupaBeast web/API origin corresponding to a validated Remote MCP endpoint URL. */
|
|
11
|
+
export function resolveAppOrigin(mcpUrl = DEFAULT_MCP_URL) {
|
|
12
|
+
const validated = validateMcpUrl(mcpUrl);
|
|
13
|
+
return new URL(validated).origin;
|
|
14
|
+
}
|
|
9
15
|
|
|
10
16
|
export const CLIENT_LABELS = {
|
|
11
17
|
claude: "Claude Code",
|
|
12
18
|
cursor: "Cursor",
|
|
13
19
|
codex: "Codex CLI",
|
|
20
|
+
gemini: "Gemini CLI",
|
|
21
|
+
antigravity: "Antigravity",
|
|
22
|
+
t3: "T3 Code (Antigravity)",
|
|
14
23
|
opencode: "OpenCode",
|
|
15
24
|
};
|
|
16
25
|
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
/** Resolve the user configuration directory for SupaBeast CLI credentials. */
|
|
6
|
+
export function resolveConfigDir(options = {}) {
|
|
7
|
+
const {
|
|
8
|
+
env = process.env,
|
|
9
|
+
homeDir = os.homedir(),
|
|
10
|
+
platform = process.platform,
|
|
11
|
+
pathApi = path,
|
|
12
|
+
} = options;
|
|
13
|
+
|
|
14
|
+
if (platform === "win32" && typeof env?.APPDATA === "string" && env.APPDATA.trim()) {
|
|
15
|
+
return pathApi.join(env.APPDATA.trim(), "supabeast");
|
|
16
|
+
}
|
|
17
|
+
if (typeof env?.XDG_CONFIG_HOME === "string" && env.XDG_CONFIG_HOME.trim()) {
|
|
18
|
+
return pathApi.join(env.XDG_CONFIG_HOME.trim(), "supabeast");
|
|
19
|
+
}
|
|
20
|
+
return pathApi.join(homeDir, ".config", "supabeast");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Resolve the local credentials file path for SupaBeast CLI. */
|
|
24
|
+
export function resolveCredentialsPath(options = {}) {
|
|
25
|
+
const { pathApi = path } = options;
|
|
26
|
+
return pathApi.join(resolveConfigDir(options), "credentials.json");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function readCredentialsFile(filePath) {
|
|
30
|
+
if (!existsSync(filePath)) return { version: 1, profiles: {} };
|
|
31
|
+
try {
|
|
32
|
+
const parsed = JSON.parse(readFileSync(filePath, "utf8"));
|
|
33
|
+
if (
|
|
34
|
+
parsed &&
|
|
35
|
+
typeof parsed === "object" &&
|
|
36
|
+
!Array.isArray(parsed) &&
|
|
37
|
+
parsed.profiles &&
|
|
38
|
+
typeof parsed.profiles === "object" &&
|
|
39
|
+
!Array.isArray(parsed.profiles)
|
|
40
|
+
) {
|
|
41
|
+
return { version: 1, profiles: { ...parsed.profiles } };
|
|
42
|
+
}
|
|
43
|
+
} catch {
|
|
44
|
+
/* Treat corrupt credentials file as empty rather than crashing CLI commands. */
|
|
45
|
+
}
|
|
46
|
+
return { version: 1, profiles: {} };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function writeCredentialsFile(filePath, payload, pathApi = path) {
|
|
50
|
+
const dir = pathApi.dirname(filePath);
|
|
51
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
52
|
+
writeFileSync(filePath, JSON.stringify(payload, null, 2) + "\n", {
|
|
53
|
+
encoding: "utf8",
|
|
54
|
+
mode: 0o600,
|
|
55
|
+
});
|
|
56
|
+
try {
|
|
57
|
+
chmodSync(dir, 0o700);
|
|
58
|
+
chmodSync(filePath, 0o600);
|
|
59
|
+
} catch {
|
|
60
|
+
/* Ignore chmod errors on platforms/filesystems without POSIX modes. */
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Load the stored non-expired CLI credential for `origin`, if present. */
|
|
65
|
+
export function loadCredential(origin, options = {}) {
|
|
66
|
+
const filePath = resolveCredentialsPath(options);
|
|
67
|
+
const store = readCredentialsFile(filePath);
|
|
68
|
+
const entry = store.profiles[origin];
|
|
69
|
+
if (!entry || typeof entry !== "object" || typeof entry.token !== "string" || !entry.token) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
const now = options.now ?? Date.now();
|
|
73
|
+
if (typeof entry.expiresAt === "number" && entry.expiresAt <= now) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
return entry;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Persist a CLI credential entry for `origin` with owner-only file permissions. */
|
|
80
|
+
export function saveCredential(origin, entry, options = {}) {
|
|
81
|
+
const { pathApi = path } = options;
|
|
82
|
+
const filePath = resolveCredentialsPath(options);
|
|
83
|
+
const store = readCredentialsFile(filePath);
|
|
84
|
+
store.profiles[origin] = {
|
|
85
|
+
token: entry.token,
|
|
86
|
+
expiresAt: entry.expiresAt,
|
|
87
|
+
user: entry.user ?? null,
|
|
88
|
+
workspace: entry.workspace ?? null,
|
|
89
|
+
updatedAt: options.now ?? Date.now(),
|
|
90
|
+
};
|
|
91
|
+
writeCredentialsFile(filePath, store, pathApi);
|
|
92
|
+
return filePath;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Remove any stored CLI credential for `origin`. */
|
|
96
|
+
export function clearCredential(origin, options = {}) {
|
|
97
|
+
const { pathApi = path } = options;
|
|
98
|
+
const filePath = resolveCredentialsPath(options);
|
|
99
|
+
if (!existsSync(filePath)) return false;
|
|
100
|
+
const store = readCredentialsFile(filePath);
|
|
101
|
+
if (!Object.hasOwn(store.profiles, origin)) return false;
|
|
102
|
+
delete store.profiles[origin];
|
|
103
|
+
if (Object.keys(store.profiles).length === 0) {
|
|
104
|
+
rmSync(filePath, { force: true });
|
|
105
|
+
} else {
|
|
106
|
+
writeCredentialsFile(filePath, store, pathApi);
|
|
107
|
+
}
|
|
108
|
+
return true;
|
|
109
|
+
}
|