@caravo/mcp 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/dist/index.js +15 -5
  2. 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 set, uses balance auth instead of x402
24
- const API_KEY = process.env.CARAVO_API_KEY;
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
- const r = API_KEY
49
- ? await fetch(url, opts)
50
- : await fetchWithX402(url, opts, wallet);
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caravo/mcp",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Local stdio MCP server for Caravo with built-in x402 wallet",
5
5
  "type": "module",
6
6
  "bin": {