@caravo/mcp 0.1.0 → 0.1.2
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/index.js +29 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -20,8 +20,9 @@ import { z } from "zod";
|
|
|
20
20
|
import { loadOrCreateWallet } from "./wallet.js";
|
|
21
21
|
import { fetchWithX402 } from "./x402.js";
|
|
22
22
|
const API_BASE = process.env.CARAVO_URL ?? "https://caravo.ai";
|
|
23
|
-
// Optional API key: if
|
|
24
|
-
const
|
|
23
|
+
// Optional API key: if it looks like a real key (am_ prefix), uses balance auth; otherwise x402
|
|
24
|
+
const RAW_KEY = process.env.CARAVO_API_KEY;
|
|
25
|
+
const API_KEY = RAW_KEY && RAW_KEY.startsWith("am_") ? RAW_KEY : undefined;
|
|
25
26
|
const wallet = loadOrCreateWallet();
|
|
26
27
|
process.stderr.write(`[caravo] wallet: ${wallet.address}\n`);
|
|
27
28
|
process.stderr.write(API_KEY
|
|
@@ -45,9 +46,18 @@ async function apiPost(path, body) {
|
|
|
45
46
|
headers: baseHeaders(),
|
|
46
47
|
body: JSON.stringify(body),
|
|
47
48
|
};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
if (!API_KEY)
|
|
50
|
+
return (await fetchWithX402(url, opts, wallet)).json();
|
|
51
|
+
const r = await fetch(url, opts);
|
|
52
|
+
if (r.status === 401 || r.status === 403) {
|
|
53
|
+
process.stderr.write("[caravo] API key auth failed, falling back to x402\n");
|
|
54
|
+
const x402Opts = {
|
|
55
|
+
method: "POST",
|
|
56
|
+
headers: { "Content-Type": "application/json" },
|
|
57
|
+
body: JSON.stringify(body),
|
|
58
|
+
};
|
|
59
|
+
return (await fetchWithX402(url, x402Opts, wallet)).json();
|
|
60
|
+
}
|
|
51
61
|
return r.json();
|
|
52
62
|
}
|
|
53
63
|
async function apiDelete(path, body) {
|
|
@@ -305,8 +315,13 @@ function registerAllTools(server) {
|
|
|
305
315
|
per_page: z.number().optional().describe("Results per page (default 10)"),
|
|
306
316
|
},
|
|
307
317
|
}, async ({ query, tag, provider, page = 1, per_page = 10 }) => {
|
|
308
|
-
|
|
309
|
-
|
|
318
|
+
if (!Number.isInteger(page) || page < 1) {
|
|
319
|
+
return { content: [{ type: "text", text: "Error: page must be a positive integer" }], isError: true };
|
|
320
|
+
}
|
|
321
|
+
if (!Number.isInteger(per_page) || per_page < 1) {
|
|
322
|
+
return { content: [{ type: "text", text: "Error: per_page must be a positive integer" }], isError: true };
|
|
323
|
+
}
|
|
324
|
+
per_page = Math.min(100, per_page);
|
|
310
325
|
const params = new URLSearchParams();
|
|
311
326
|
if (query)
|
|
312
327
|
params.set("query", query);
|
|
@@ -527,6 +542,13 @@ function registerAllTools(server) {
|
|
|
527
542
|
per_page: z.number().optional().describe("Results per page (default 20)"),
|
|
528
543
|
},
|
|
529
544
|
}, async ({ status = "open", page = 1, per_page = 20 }) => {
|
|
545
|
+
if (!Number.isInteger(page) || page < 1) {
|
|
546
|
+
return { content: [{ type: "text", text: "Error: page must be a positive integer" }], isError: true };
|
|
547
|
+
}
|
|
548
|
+
if (!Number.isInteger(per_page) || per_page < 1) {
|
|
549
|
+
return { content: [{ type: "text", text: "Error: per_page must be a positive integer" }], isError: true };
|
|
550
|
+
}
|
|
551
|
+
per_page = Math.min(100, per_page);
|
|
530
552
|
const params = new URLSearchParams();
|
|
531
553
|
params.set("status", status);
|
|
532
554
|
params.set("page", String(page));
|