@x402scan/mcp 0.0.7-beta.4 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/run-server.cjs +7156 -6859
- package/dist/esm/index.js +2657 -11
- package/dist/esm/index.js.map +1 -1
- package/package.json +10 -5
- package/dist/esm/chunk-2UP5W5MC.js +0 -47
- package/dist/esm/chunk-2UP5W5MC.js.map +0 -1
- package/dist/esm/chunk-JXXC6FYE.js +0 -970
- package/dist/esm/chunk-JXXC6FYE.js.map +0 -1
- package/dist/esm/chunk-Q2QVXJFE.js +0 -90
- package/dist/esm/chunk-Q2QVXJFE.js.map +0 -1
- package/dist/esm/chunk-RZYTNVC6.js +0 -112
- package/dist/esm/chunk-RZYTNVC6.js.map +0 -1
- package/dist/esm/fund-ANZCZU5C.js +0 -30
- package/dist/esm/fund-ANZCZU5C.js.map +0 -1
- package/dist/esm/install-BBOI4D6I.js +0 -701
- package/dist/esm/install-BBOI4D6I.js.map +0 -1
- package/dist/esm/server-IOVNYPTB.js +0 -976
- package/dist/esm/server-IOVNYPTB.js.map +0 -1
|
@@ -1,701 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Clients,
|
|
3
|
-
clientMetadata
|
|
4
|
-
} from "./chunk-Q2QVXJFE.js";
|
|
5
|
-
import {
|
|
6
|
-
DIST_TAG,
|
|
7
|
-
getBalance
|
|
8
|
-
} from "./chunk-2UP5W5MC.js";
|
|
9
|
-
import {
|
|
10
|
-
promptDeposit,
|
|
11
|
-
wait
|
|
12
|
-
} from "./chunk-RZYTNVC6.js";
|
|
13
|
-
import {
|
|
14
|
-
err,
|
|
15
|
-
getWallet,
|
|
16
|
-
log,
|
|
17
|
-
redeemInviteCode,
|
|
18
|
-
resultFromThrowable,
|
|
19
|
-
safeReadFile,
|
|
20
|
-
safeWriteFile
|
|
21
|
-
} from "./chunk-JXXC6FYE.js";
|
|
22
|
-
|
|
23
|
-
// src/cli/install/index.ts
|
|
24
|
-
import chalk5 from "chalk";
|
|
25
|
-
import { intro, outro as outro3 } from "@clack/prompts";
|
|
26
|
-
|
|
27
|
-
// src/cli/install/1-get-client/index.ts
|
|
28
|
-
import z from "zod";
|
|
29
|
-
import { select, log as log2, outro } from "@clack/prompts";
|
|
30
|
-
import chalk from "chalk";
|
|
31
|
-
var getClient = async ({ client: flagClient, yes }) => {
|
|
32
|
-
if (yes) {
|
|
33
|
-
if (!flagClient) {
|
|
34
|
-
throw new Error(
|
|
35
|
-
`Client is required when yes is true. Pass --client as one of these values: ${Object.values(Clients).join(", ")}`
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
const parsedClient2 = z.enum(Clients).safeParse(flagClient);
|
|
39
|
-
if (!parsedClient2.success) {
|
|
40
|
-
throw new Error(
|
|
41
|
-
`${flagClient} is not a valid client. Valid options are: ${Object.values(Clients).join(", ")}`
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
return parsedClient2.data;
|
|
45
|
-
}
|
|
46
|
-
const parsedClient = z.enum(Clients).safeParse(flagClient);
|
|
47
|
-
if (parsedClient.success) {
|
|
48
|
-
return parsedClient.data;
|
|
49
|
-
}
|
|
50
|
-
if (flagClient) {
|
|
51
|
-
log2.error(`${flagClient} is not a valid client. Please select a client`);
|
|
52
|
-
}
|
|
53
|
-
const client = await select({
|
|
54
|
-
message: "Where would you like to install the x402scan MCP server?",
|
|
55
|
-
options: Object.values(Clients).map((client2) => {
|
|
56
|
-
const metadata = clientMetadata[client2];
|
|
57
|
-
return {
|
|
58
|
-
label: metadata.name,
|
|
59
|
-
value: client2
|
|
60
|
-
};
|
|
61
|
-
}),
|
|
62
|
-
maxItems: 7
|
|
63
|
-
});
|
|
64
|
-
const parsedClientSelection = z.enum(Clients).safeParse(client);
|
|
65
|
-
if (parsedClientSelection.success) {
|
|
66
|
-
return parsedClientSelection.data;
|
|
67
|
-
}
|
|
68
|
-
outro(chalk.bold.red("No MCP client selected"));
|
|
69
|
-
process.exit(0);
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
// src/cli/install/2-add-server/index.ts
|
|
73
|
-
import fs2 from "fs";
|
|
74
|
-
import chalk2 from "chalk";
|
|
75
|
-
import { log as clackLog, confirm, outro as outro2, stream } from "@clack/prompts";
|
|
76
|
-
|
|
77
|
-
// src/cli/install/2-add-server/lib/client-config-file.ts
|
|
78
|
-
import os2 from "os";
|
|
79
|
-
import path2 from "path";
|
|
80
|
-
import process3 from "process";
|
|
81
|
-
import fs from "fs";
|
|
82
|
-
|
|
83
|
-
// src/cli/install/2-add-server/lib/platforms.ts
|
|
84
|
-
import os from "os";
|
|
85
|
-
import path from "path";
|
|
86
|
-
import process2 from "process";
|
|
87
|
-
import z2 from "zod";
|
|
88
|
-
var Platforms = /* @__PURE__ */ ((Platforms2) => {
|
|
89
|
-
Platforms2["Windows"] = "win32";
|
|
90
|
-
Platforms2["MacOS"] = "darwin";
|
|
91
|
-
Platforms2["Linux"] = "linux";
|
|
92
|
-
return Platforms2;
|
|
93
|
-
})(Platforms || {});
|
|
94
|
-
var getPlatformPath = () => {
|
|
95
|
-
const platform = z2.enum(Platforms).safeParse(process2.platform);
|
|
96
|
-
if (!platform.success) {
|
|
97
|
-
throw new Error(`Invalid platform: ${process2.platform}`);
|
|
98
|
-
}
|
|
99
|
-
const homeDir = os.homedir();
|
|
100
|
-
switch (platform.data) {
|
|
101
|
-
case "win32" /* Windows */:
|
|
102
|
-
return {
|
|
103
|
-
baseDir: process2.env.APPDATA ?? path.join(homeDir, "AppData", "Roaming"),
|
|
104
|
-
vscodePath: path.join("Code", "User")
|
|
105
|
-
};
|
|
106
|
-
case "darwin" /* MacOS */:
|
|
107
|
-
return {
|
|
108
|
-
baseDir: path.join(homeDir, "Library", "Application Support"),
|
|
109
|
-
vscodePath: path.join("Code", "User")
|
|
110
|
-
};
|
|
111
|
-
case "linux" /* Linux */:
|
|
112
|
-
return {
|
|
113
|
-
baseDir: process2.env.XDG_CONFIG_HOME ?? path.join(homeDir, ".config"),
|
|
114
|
-
vscodePath: path.join("Code/User")
|
|
115
|
-
};
|
|
116
|
-
default:
|
|
117
|
-
throw new Error(`Invalid platform: ${process2.platform}`);
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
// src/cli/install/2-add-server/lib/file-types.ts
|
|
122
|
-
import * as TOML from "@iarna/toml";
|
|
123
|
-
import yaml from "js-yaml";
|
|
124
|
-
import * as jsonc from "jsonc-parser";
|
|
125
|
-
|
|
126
|
-
// src/cli/install/2-add-server/lib/result.ts
|
|
127
|
-
var errorType = "config";
|
|
128
|
-
var surface = "config_file";
|
|
129
|
-
var configResultFromThrowable = (fn, error) => resultFromThrowable(errorType, surface, fn, error);
|
|
130
|
-
|
|
131
|
-
// src/cli/install/2-add-server/lib/file-types.ts
|
|
132
|
-
var parseContent = (fileContent, format, path3) => {
|
|
133
|
-
return configResultFromThrowable(
|
|
134
|
-
() => {
|
|
135
|
-
let config;
|
|
136
|
-
if (format === "yaml" /* YAML */) {
|
|
137
|
-
config = yaml.load(fileContent);
|
|
138
|
-
} else if (format === "toml" /* TOML */) {
|
|
139
|
-
config = TOML.parse(fileContent);
|
|
140
|
-
} else if (path3.endsWith(".jsonc")) {
|
|
141
|
-
config = jsonc.parse(fileContent);
|
|
142
|
-
} else {
|
|
143
|
-
config = JSON.parse(fileContent);
|
|
144
|
-
}
|
|
145
|
-
return {
|
|
146
|
-
config,
|
|
147
|
-
fileContent
|
|
148
|
-
};
|
|
149
|
-
},
|
|
150
|
-
(e) => ({
|
|
151
|
-
cause: "parse_config",
|
|
152
|
-
message: e instanceof Error ? e.message : "Failed to parse config file"
|
|
153
|
-
})
|
|
154
|
-
);
|
|
155
|
-
};
|
|
156
|
-
var parseClientConfig = async ({ format, path: path3 }) => {
|
|
157
|
-
const readResult = await safeReadFile("config_file", path3);
|
|
158
|
-
if (readResult.isErr()) return readResult;
|
|
159
|
-
const parseResult = parseContent(readResult.value, format, path3);
|
|
160
|
-
if (parseResult.isErr()) return parseResult;
|
|
161
|
-
return parseResult;
|
|
162
|
-
};
|
|
163
|
-
var serializeJsonc = (config, originalContent) => {
|
|
164
|
-
return configResultFromThrowable(
|
|
165
|
-
() => {
|
|
166
|
-
const modifications = [];
|
|
167
|
-
for (const key of Object.keys(config)) {
|
|
168
|
-
const keyPath = [key];
|
|
169
|
-
const edits = jsonc.modify(originalContent, keyPath, config[key], {
|
|
170
|
-
formattingOptions: { tabSize: 2, insertSpaces: true }
|
|
171
|
-
});
|
|
172
|
-
modifications.push(...edits);
|
|
173
|
-
}
|
|
174
|
-
return jsonc.applyEdits(originalContent, modifications);
|
|
175
|
-
},
|
|
176
|
-
(e) => ({
|
|
177
|
-
cause: "serialize_config",
|
|
178
|
-
message: e instanceof Error ? e.message : "Failed to serialize JSONC"
|
|
179
|
-
})
|
|
180
|
-
);
|
|
181
|
-
};
|
|
182
|
-
var serializeClientConfig = ({ format, path: path3 }, config, originalContent) => {
|
|
183
|
-
if (format === "yaml" /* YAML */) {
|
|
184
|
-
return yaml.dump(config, {
|
|
185
|
-
indent: 2,
|
|
186
|
-
lineWidth: -1,
|
|
187
|
-
noRefs: true
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
if (format === "toml" /* TOML */) {
|
|
191
|
-
return TOML.stringify(config);
|
|
192
|
-
}
|
|
193
|
-
if (path3.endsWith(".jsonc") && originalContent) {
|
|
194
|
-
const result = serializeJsonc(config, originalContent);
|
|
195
|
-
if (result.isOk()) {
|
|
196
|
-
return result.value;
|
|
197
|
-
}
|
|
198
|
-
console.log(`Error applying JSONC edits: ${result.error.message}`);
|
|
199
|
-
console.log("Falling back to JSON.stringify (comments will be lost)");
|
|
200
|
-
return JSON.stringify(config, null, 2);
|
|
201
|
-
}
|
|
202
|
-
return JSON.stringify(config, null, 2);
|
|
203
|
-
};
|
|
204
|
-
var stringifyObject = (config, format) => {
|
|
205
|
-
if (format === "yaml" /* YAML */) {
|
|
206
|
-
return yaml.dump(config, {
|
|
207
|
-
indent: 2,
|
|
208
|
-
lineWidth: -1,
|
|
209
|
-
noRefs: true
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
if (format === "toml" /* TOML */) {
|
|
213
|
-
return TOML.stringify(config);
|
|
214
|
-
}
|
|
215
|
-
return JSON.stringify(config, null, 2);
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
// src/cli/install/2-add-server/lib/client-config-file.ts
|
|
219
|
-
var getClientConfigFile = (client) => {
|
|
220
|
-
const homeDir = os2.homedir();
|
|
221
|
-
const { baseDir, vscodePath } = getPlatformPath();
|
|
222
|
-
switch (client) {
|
|
223
|
-
case "claude" /* Claude */:
|
|
224
|
-
return {
|
|
225
|
-
path: path2.join(baseDir, "Claude", "claude_desktop_config.json"),
|
|
226
|
-
configKey: "mcpServers",
|
|
227
|
-
format: "json" /* JSON */
|
|
228
|
-
};
|
|
229
|
-
case "cline" /* Cline */:
|
|
230
|
-
return {
|
|
231
|
-
path: path2.join(
|
|
232
|
-
baseDir,
|
|
233
|
-
vscodePath,
|
|
234
|
-
"globalStorage",
|
|
235
|
-
"saoudrizwan.claude-dev",
|
|
236
|
-
"settings",
|
|
237
|
-
"cline_mcp_settings.json"
|
|
238
|
-
),
|
|
239
|
-
configKey: "mcpServers",
|
|
240
|
-
format: "json" /* JSON */
|
|
241
|
-
};
|
|
242
|
-
case "roo-cline" /* RooCline */:
|
|
243
|
-
return {
|
|
244
|
-
path: path2.join(
|
|
245
|
-
baseDir,
|
|
246
|
-
vscodePath,
|
|
247
|
-
"globalStorage",
|
|
248
|
-
"rooveterinaryinc.roo-cline",
|
|
249
|
-
"settings",
|
|
250
|
-
"mcp_settings.json"
|
|
251
|
-
),
|
|
252
|
-
configKey: "mcpServers",
|
|
253
|
-
format: "json" /* JSON */
|
|
254
|
-
};
|
|
255
|
-
case "windsurf" /* Windsurf */:
|
|
256
|
-
return {
|
|
257
|
-
path: path2.join(homeDir, ".codeium", "windsurf", "mcp_config.json"),
|
|
258
|
-
configKey: "mcpServers",
|
|
259
|
-
format: "json" /* JSON */
|
|
260
|
-
};
|
|
261
|
-
case "cursor" /* Cursor */:
|
|
262
|
-
return {
|
|
263
|
-
path: path2.join(homeDir, ".cursor", "mcp.json"),
|
|
264
|
-
configKey: "mcpServers",
|
|
265
|
-
format: "json" /* JSON */
|
|
266
|
-
};
|
|
267
|
-
case "warp" /* Warp */:
|
|
268
|
-
return {
|
|
269
|
-
path: "no-local-config",
|
|
270
|
-
// it's okay this isn't a real path, we never use it
|
|
271
|
-
configKey: "mcpServers",
|
|
272
|
-
format: "json" /* JSON */
|
|
273
|
-
};
|
|
274
|
-
case "gemini-cli" /* GeminiCli */:
|
|
275
|
-
return {
|
|
276
|
-
path: path2.join(homeDir, ".gemini", "settings.json"),
|
|
277
|
-
configKey: "mcpServers",
|
|
278
|
-
format: "json" /* JSON */
|
|
279
|
-
};
|
|
280
|
-
case "vscode" /* Vscode */:
|
|
281
|
-
return {
|
|
282
|
-
path: path2.join(baseDir, vscodePath, "mcp.json"),
|
|
283
|
-
configKey: "mcpServers",
|
|
284
|
-
format: "json" /* JSON */
|
|
285
|
-
};
|
|
286
|
-
case "claude-code" /* ClaudeCode */:
|
|
287
|
-
return {
|
|
288
|
-
path: path2.join(homeDir, ".claude.json"),
|
|
289
|
-
configKey: "mcpServers",
|
|
290
|
-
format: "json" /* JSON */
|
|
291
|
-
};
|
|
292
|
-
case "goose" /* Goose */:
|
|
293
|
-
return {
|
|
294
|
-
path: path2.join(homeDir, ".config", "goose", "config.yaml"),
|
|
295
|
-
configKey: "extensions",
|
|
296
|
-
format: "yaml" /* YAML */
|
|
297
|
-
};
|
|
298
|
-
case "zed" /* Zed */:
|
|
299
|
-
return {
|
|
300
|
-
path: process3.platform === "win32" ? path2.join(
|
|
301
|
-
process3.env.APPDATA ?? path2.join(homeDir, "AppData", "Roaming"),
|
|
302
|
-
"Zed",
|
|
303
|
-
"settings.json"
|
|
304
|
-
) : path2.join(homeDir, ".config", "zed", "settings.json"),
|
|
305
|
-
configKey: "context_servers",
|
|
306
|
-
format: "json" /* JSON */
|
|
307
|
-
};
|
|
308
|
-
case "codex" /* Codex */:
|
|
309
|
-
return {
|
|
310
|
-
path: path2.join(
|
|
311
|
-
process3.env.CODEX_HOME ?? path2.join(homeDir, ".codex"),
|
|
312
|
-
"config.toml"
|
|
313
|
-
),
|
|
314
|
-
configKey: "mcp_servers",
|
|
315
|
-
format: "toml" /* TOML */
|
|
316
|
-
};
|
|
317
|
-
case "opencode" /* Opencode */: {
|
|
318
|
-
const jsonPath = path2.join(
|
|
319
|
-
homeDir,
|
|
320
|
-
".config",
|
|
321
|
-
"opencode",
|
|
322
|
-
"opencode.json"
|
|
323
|
-
);
|
|
324
|
-
const jsoncPath = jsonPath.replace(".json", ".jsonc");
|
|
325
|
-
if (fs.existsSync(jsoncPath)) {
|
|
326
|
-
log.info(`Found .jsonc file for OpenCode, using: ${jsoncPath}`);
|
|
327
|
-
return {
|
|
328
|
-
path: jsoncPath,
|
|
329
|
-
configKey: "mcp",
|
|
330
|
-
format: "json" /* JSON */
|
|
331
|
-
};
|
|
332
|
-
}
|
|
333
|
-
return {
|
|
334
|
-
path: jsonPath,
|
|
335
|
-
configKey: "mcp",
|
|
336
|
-
format: "json" /* JSON */
|
|
337
|
-
};
|
|
338
|
-
}
|
|
339
|
-
default:
|
|
340
|
-
throw new Error(`Unknown client: ${String(client)}`);
|
|
341
|
-
}
|
|
342
|
-
};
|
|
343
|
-
|
|
344
|
-
// src/cli/install/2-add-server/lib/nested-values.ts
|
|
345
|
-
var getNestedValue = (obj, path3) => {
|
|
346
|
-
const keys = path3.split(".");
|
|
347
|
-
let current = obj;
|
|
348
|
-
for (const key of keys) {
|
|
349
|
-
if (current && typeof current === "object" && key in current) {
|
|
350
|
-
current = current[key];
|
|
351
|
-
} else {
|
|
352
|
-
return void 0;
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
return current;
|
|
356
|
-
};
|
|
357
|
-
var setNestedValue = (obj, path3, value) => {
|
|
358
|
-
const keys = path3.split(".");
|
|
359
|
-
const lastKey = keys.pop();
|
|
360
|
-
if (!lastKey) return;
|
|
361
|
-
const target = keys.reduce((current, key) => {
|
|
362
|
-
current[key] ??= {};
|
|
363
|
-
return current[key];
|
|
364
|
-
}, obj);
|
|
365
|
-
target[lastKey] = value;
|
|
366
|
-
};
|
|
367
|
-
|
|
368
|
-
// src/cli/install/2-add-server/index.ts
|
|
369
|
-
var getMcpConfig = (globalFlags) => {
|
|
370
|
-
if (globalFlags.dev) {
|
|
371
|
-
return {
|
|
372
|
-
serverName: "x402",
|
|
373
|
-
command: "node",
|
|
374
|
-
args: [`${process.cwd()}/dist/esm/index.js`, "--dev"]
|
|
375
|
-
};
|
|
376
|
-
}
|
|
377
|
-
return {
|
|
378
|
-
serverName: "x402",
|
|
379
|
-
command: "npx",
|
|
380
|
-
args: ["-y", `@x402scan/mcp@${DIST_TAG}`]
|
|
381
|
-
};
|
|
382
|
-
};
|
|
383
|
-
var addServer = async (client, globalFlags) => {
|
|
384
|
-
const { serverName, command, args } = getMcpConfig(globalFlags);
|
|
385
|
-
if (client === "warp" /* Warp */) {
|
|
386
|
-
clackLog.info(
|
|
387
|
-
chalk2.bold.yellow("Warp requires a manual installation through their UI.")
|
|
388
|
-
);
|
|
389
|
-
clackLog.message(
|
|
390
|
-
"Please copy the following configuration object and add it to your Warp MCP config:"
|
|
391
|
-
);
|
|
392
|
-
console.log();
|
|
393
|
-
console.log(
|
|
394
|
-
JSON.stringify(
|
|
395
|
-
{
|
|
396
|
-
[serverName]: {
|
|
397
|
-
command,
|
|
398
|
-
args,
|
|
399
|
-
working_directory: null,
|
|
400
|
-
start_on_launch: true
|
|
401
|
-
}
|
|
402
|
-
},
|
|
403
|
-
null,
|
|
404
|
-
2
|
|
405
|
-
)
|
|
406
|
-
);
|
|
407
|
-
console.log();
|
|
408
|
-
clackLog.message(
|
|
409
|
-
`Read Warp's documentation at https://docs.warp.dev/knowledge-and-collaboration/mcp`
|
|
410
|
-
);
|
|
411
|
-
const addedToWarp = await confirm({
|
|
412
|
-
message: "Did you add the MCP server to your Warp config?"
|
|
413
|
-
});
|
|
414
|
-
if (!addedToWarp) {
|
|
415
|
-
return err("user", "install", {
|
|
416
|
-
cause: "warp_mcp_server_not_added",
|
|
417
|
-
message: "Warp MCP server not added"
|
|
418
|
-
});
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
const clientFileTarget = getClientConfigFile(client);
|
|
422
|
-
const { name } = clientMetadata[client];
|
|
423
|
-
let config = {};
|
|
424
|
-
let content = void 0;
|
|
425
|
-
log.info(`Checking if config file exists at: ${clientFileTarget.path}`);
|
|
426
|
-
if (!fs2.existsSync(clientFileTarget.path)) {
|
|
427
|
-
log.info("Config file not found, creating default empty config");
|
|
428
|
-
setNestedValue(config, clientFileTarget.configKey, {});
|
|
429
|
-
log.info("Config created successfully");
|
|
430
|
-
if (!globalFlags.yes) {
|
|
431
|
-
await wait({
|
|
432
|
-
startText: "Locating config file",
|
|
433
|
-
stopText: `No config found, creating default empty config`,
|
|
434
|
-
ms: 1e3
|
|
435
|
-
});
|
|
436
|
-
}
|
|
437
|
-
} else {
|
|
438
|
-
log.info("Config file found, reading config file content");
|
|
439
|
-
const parseResult = await parseClientConfig(clientFileTarget);
|
|
440
|
-
if (parseResult.isErr()) {
|
|
441
|
-
clackLog.error(
|
|
442
|
-
chalk2.bold.red(`Error reading config: ${parseResult.error.message}`)
|
|
443
|
-
);
|
|
444
|
-
outro2(chalk2.bold.red(`Error adding x402scan MCP to ${name}`));
|
|
445
|
-
process.exit(1);
|
|
446
|
-
}
|
|
447
|
-
const { config: rawConfig, fileContent } = parseResult.value;
|
|
448
|
-
config = rawConfig;
|
|
449
|
-
content = fileContent;
|
|
450
|
-
const existingValue = getNestedValue(rawConfig, clientFileTarget.configKey);
|
|
451
|
-
if (!existingValue) {
|
|
452
|
-
setNestedValue(rawConfig, clientFileTarget.configKey, {});
|
|
453
|
-
}
|
|
454
|
-
if (!globalFlags.yes) {
|
|
455
|
-
await wait({
|
|
456
|
-
startText: `Locating config file`,
|
|
457
|
-
stopText: `Config loaded from ${clientFileTarget.path}`,
|
|
458
|
-
ms: 1e3
|
|
459
|
-
});
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
const servers = getNestedValue(config, clientFileTarget.configKey);
|
|
463
|
-
if (!servers || typeof servers !== "object") {
|
|
464
|
-
log.error(`Invalid ${clientFileTarget.configKey} structure in config`);
|
|
465
|
-
clackLog.error(
|
|
466
|
-
chalk2.bold.red(
|
|
467
|
-
`Invalid ${clientFileTarget.configKey} structure in config`
|
|
468
|
-
)
|
|
469
|
-
);
|
|
470
|
-
outro2(chalk2.bold.red(`Error adding x402scan MCP to ${name}`));
|
|
471
|
-
process.exit(1);
|
|
472
|
-
}
|
|
473
|
-
if (client === "goose" /* Goose */) {
|
|
474
|
-
servers[serverName] = {
|
|
475
|
-
name: serverName,
|
|
476
|
-
cmd: command,
|
|
477
|
-
args,
|
|
478
|
-
enabled: true,
|
|
479
|
-
envs: {},
|
|
480
|
-
type: "stdio",
|
|
481
|
-
timeout: 300
|
|
482
|
-
};
|
|
483
|
-
} else if (client === "zed" /* Zed */) {
|
|
484
|
-
servers[serverName] = {
|
|
485
|
-
source: "custom",
|
|
486
|
-
command,
|
|
487
|
-
args,
|
|
488
|
-
env: {}
|
|
489
|
-
};
|
|
490
|
-
} else if (client === "opencode" /* Opencode */) {
|
|
491
|
-
servers[serverName] = {
|
|
492
|
-
type: "local",
|
|
493
|
-
command,
|
|
494
|
-
args,
|
|
495
|
-
enabled: true,
|
|
496
|
-
environment: {}
|
|
497
|
-
};
|
|
498
|
-
} else {
|
|
499
|
-
servers[serverName] = {
|
|
500
|
-
command,
|
|
501
|
-
args
|
|
502
|
-
};
|
|
503
|
-
}
|
|
504
|
-
if (!globalFlags.yes) {
|
|
505
|
-
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
506
|
-
clackLog.step(
|
|
507
|
-
`The following will be added to ${chalk2.bold.underline(clientFileTarget.path)}`
|
|
508
|
-
);
|
|
509
|
-
}
|
|
510
|
-
const configStr = formatDiffByFormat(
|
|
511
|
-
{
|
|
512
|
-
[clientFileTarget.configKey]: {
|
|
513
|
-
[serverName]: servers[serverName]
|
|
514
|
-
}
|
|
515
|
-
},
|
|
516
|
-
clientFileTarget.format
|
|
517
|
-
);
|
|
518
|
-
if (!globalFlags.yes) {
|
|
519
|
-
await stream.message(
|
|
520
|
-
(async function* () {
|
|
521
|
-
for (const num of Array.from(
|
|
522
|
-
{ length: configStr.length },
|
|
523
|
-
(_, i) => i
|
|
524
|
-
)) {
|
|
525
|
-
const char = configStr[num];
|
|
526
|
-
yield char;
|
|
527
|
-
if (!["\n", " ", "\u2500", "\u256E", "\u256D", "\u2570", "\u256F", "\u2502"].includes(char)) {
|
|
528
|
-
await new Promise((resolve) => setTimeout(resolve, 5));
|
|
529
|
-
} else {
|
|
530
|
-
await new Promise((resolve) => setTimeout(resolve, 2));
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
})()
|
|
534
|
-
);
|
|
535
|
-
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
536
|
-
}
|
|
537
|
-
const isConfirmed = globalFlags.yes ? true : await confirm({
|
|
538
|
-
message: `Would you like to proceed?`,
|
|
539
|
-
active: "Install MCP",
|
|
540
|
-
inactive: "Cancel"
|
|
541
|
-
});
|
|
542
|
-
if (isConfirmed !== true) {
|
|
543
|
-
outro2(chalk2.bold.red("Installation cancelled"));
|
|
544
|
-
process.exit(0);
|
|
545
|
-
}
|
|
546
|
-
const configContent = serializeClientConfig(
|
|
547
|
-
clientFileTarget,
|
|
548
|
-
config,
|
|
549
|
-
content
|
|
550
|
-
);
|
|
551
|
-
const writeResult = await safeWriteFile(
|
|
552
|
-
"config_file",
|
|
553
|
-
clientFileTarget.path,
|
|
554
|
-
configContent
|
|
555
|
-
);
|
|
556
|
-
if (writeResult.isErr()) {
|
|
557
|
-
clackLog.error(
|
|
558
|
-
chalk2.bold.red(`Error writing config: ${writeResult.error.message}`)
|
|
559
|
-
);
|
|
560
|
-
outro2(chalk2.bold.red(`Error adding x402scan MCP to ${name}`));
|
|
561
|
-
process.exit(1);
|
|
562
|
-
}
|
|
563
|
-
clackLog.success(chalk2.bold.green(`Added x402scan MCP to ${name}`));
|
|
564
|
-
};
|
|
565
|
-
var formatDiffByFormat = (obj, format) => {
|
|
566
|
-
const str = stringifyObject(obj, format);
|
|
567
|
-
switch (format) {
|
|
568
|
-
case "json" /* JSON */: {
|
|
569
|
-
const numLines = str.split("\n").length;
|
|
570
|
-
return str.split("\n").map((line, index) => {
|
|
571
|
-
const diffLines = [0, 1, numLines - 2, numLines - 1];
|
|
572
|
-
const isDiffLine = !diffLines.includes(index);
|
|
573
|
-
if (isDiffLine) {
|
|
574
|
-
return `${chalk2.bold.green(`+ ${line.slice(2)}`)}`;
|
|
575
|
-
}
|
|
576
|
-
return line;
|
|
577
|
-
}).join("\n");
|
|
578
|
-
}
|
|
579
|
-
case "yaml" /* YAML */: {
|
|
580
|
-
return str.split("\n").map((line, index) => {
|
|
581
|
-
const diffLines = [0, 1, str.length - 2, str.length - 1];
|
|
582
|
-
const isDiffLine = !diffLines.includes(index);
|
|
583
|
-
if (isDiffLine) {
|
|
584
|
-
return `${chalk2.bold.green(`+ ${line.slice(2)}`)}`;
|
|
585
|
-
}
|
|
586
|
-
return line;
|
|
587
|
-
}).join("\n");
|
|
588
|
-
}
|
|
589
|
-
case "toml" /* TOML */: {
|
|
590
|
-
return str.split("\n").filter((line) => line.trim() !== "").map((line) => {
|
|
591
|
-
return `${chalk2.bold.green(`+ ${line.trim()}`)}`;
|
|
592
|
-
}).join("\n");
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
};
|
|
596
|
-
|
|
597
|
-
// src/cli/install/3-redeem-invite/index.ts
|
|
598
|
-
import chalk3 from "chalk";
|
|
599
|
-
import { log as log3, spinner } from "@clack/prompts";
|
|
600
|
-
var redeemInviteCode2 = async (props, flags) => {
|
|
601
|
-
const s = spinner();
|
|
602
|
-
if (!flags.yes) {
|
|
603
|
-
s.start("Redeeming invite code...");
|
|
604
|
-
}
|
|
605
|
-
const result = await redeemInviteCode(props);
|
|
606
|
-
return result.match(
|
|
607
|
-
async ({ amount, txHash }) => {
|
|
608
|
-
if (!flags.yes) {
|
|
609
|
-
s.stop("Invite code redeemed successfully!");
|
|
610
|
-
await wait({
|
|
611
|
-
startText: "Processing...",
|
|
612
|
-
stopText: chalk3.green(
|
|
613
|
-
`${chalk3.bold(amount)} USDC has been sent to your wallet!`
|
|
614
|
-
),
|
|
615
|
-
ms: 1e3
|
|
616
|
-
});
|
|
617
|
-
}
|
|
618
|
-
log3.info(chalk3.dim(`Transaction: https://basescan.org/tx/${txHash}`));
|
|
619
|
-
return true;
|
|
620
|
-
},
|
|
621
|
-
(error) => {
|
|
622
|
-
if (!flags.yes) {
|
|
623
|
-
s.stop("Invite code redemption failed");
|
|
624
|
-
}
|
|
625
|
-
log3.warning(
|
|
626
|
-
chalk3.yellow(`Failed to redeem invite code: ${error.message}`)
|
|
627
|
-
);
|
|
628
|
-
return false;
|
|
629
|
-
}
|
|
630
|
-
);
|
|
631
|
-
};
|
|
632
|
-
|
|
633
|
-
// src/cli/install/4-add-funds/index.ts
|
|
634
|
-
import chalk4 from "chalk";
|
|
635
|
-
import { log as log4, spinner as spinner2 } from "@clack/prompts";
|
|
636
|
-
var addFunds = async ({ flags, address, isNew }) => {
|
|
637
|
-
if (isNew) {
|
|
638
|
-
if (!flags.yes) {
|
|
639
|
-
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
640
|
-
}
|
|
641
|
-
log4.info("To use paid API tools, you will need USDC in your wallet.");
|
|
642
|
-
await promptDeposit({ address, flags, surface: "add-funds" });
|
|
643
|
-
} else {
|
|
644
|
-
const { start, stop } = spinner2();
|
|
645
|
-
start("Checking balance...");
|
|
646
|
-
const balanceResult = await getBalance({
|
|
647
|
-
address,
|
|
648
|
-
flags,
|
|
649
|
-
surface: "add-funds"
|
|
650
|
-
});
|
|
651
|
-
if (balanceResult.isOk()) {
|
|
652
|
-
stop(`Balance: ${chalk4.bold(`${balanceResult.value.balance} USDC`)} `);
|
|
653
|
-
} else {
|
|
654
|
-
stop(`Error: ${balanceResult.error.message}`);
|
|
655
|
-
return;
|
|
656
|
-
}
|
|
657
|
-
const balance = balanceResult.value;
|
|
658
|
-
if (balance.balance < 1) {
|
|
659
|
-
log4.warning(
|
|
660
|
-
chalk4.bold(
|
|
661
|
-
`Your balance is low (${balance.balance} USDC). Consider topping up.`
|
|
662
|
-
)
|
|
663
|
-
);
|
|
664
|
-
await promptDeposit({ address, flags, surface: "install" });
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
};
|
|
668
|
-
|
|
669
|
-
// src/cli/install/index.ts
|
|
670
|
-
var installMcpServer = async (flags) => {
|
|
671
|
-
intro(chalk5.green.bold(`Install x402scan MCP`));
|
|
672
|
-
const walletResult = await getWallet();
|
|
673
|
-
if (walletResult.isErr()) {
|
|
674
|
-
log.error(JSON.stringify(walletResult.error, null, 2));
|
|
675
|
-
outro3(chalk5.bold.red("Failed to get wallet"));
|
|
676
|
-
process.exit(1);
|
|
677
|
-
}
|
|
678
|
-
const {
|
|
679
|
-
account: { address },
|
|
680
|
-
isNew
|
|
681
|
-
} = walletResult.value;
|
|
682
|
-
const client = await getClient(flags);
|
|
683
|
-
await addServer(client, flags);
|
|
684
|
-
const inviteRedeemed = flags.invite ? await redeemInviteCode2(
|
|
685
|
-
{
|
|
686
|
-
code: flags.invite,
|
|
687
|
-
dev: flags.dev,
|
|
688
|
-
address,
|
|
689
|
-
surface: "install"
|
|
690
|
-
},
|
|
691
|
-
flags
|
|
692
|
-
) : false;
|
|
693
|
-
if (!inviteRedeemed) {
|
|
694
|
-
await addFunds({ flags, address, isNew });
|
|
695
|
-
}
|
|
696
|
-
outro3(chalk5.bold.green("Your x402scan MCP server is ready to use!"));
|
|
697
|
-
};
|
|
698
|
-
export {
|
|
699
|
-
installMcpServer
|
|
700
|
-
};
|
|
701
|
-
//# sourceMappingURL=install-BBOI4D6I.js.map
|