@xlmtools/cli 0.1.1 → 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.
Files changed (41) hide show
  1. package/dist/cli.js +6 -1
  2. package/dist/lib/api-fetch.js +20 -0
  3. package/dist/tools/crypto.js +2 -1
  4. package/dist/tools/dex-candles.js +2 -1
  5. package/dist/tools/dex-orderbook.js +2 -1
  6. package/dist/tools/dex-trades.js +2 -1
  7. package/dist/tools/domain.js +2 -1
  8. package/dist/tools/image.js +2 -1
  9. package/dist/tools/oracle-price.js +2 -1
  10. package/dist/tools/research.js +2 -1
  11. package/dist/tools/scrape.js +2 -1
  12. package/dist/tools/screenshot.js +2 -1
  13. package/dist/tools/search.js +2 -1
  14. package/dist/tools/stellar-account.js +2 -1
  15. package/dist/tools/stellar-asset.js +2 -1
  16. package/dist/tools/stellar-pools.js +2 -1
  17. package/dist/tools/stocks.js +2 -1
  18. package/dist/tools/swap-quote.js +2 -1
  19. package/dist/tools/weather.js +2 -1
  20. package/dist/tools/youtube.js +2 -1
  21. package/package.json +1 -1
  22. package/src/cli.ts +6 -1
  23. package/src/lib/api-fetch.ts +30 -0
  24. package/src/tools/crypto.ts +2 -1
  25. package/src/tools/dex-candles.ts +2 -1
  26. package/src/tools/dex-orderbook.ts +4 -2
  27. package/src/tools/dex-trades.ts +2 -1
  28. package/src/tools/domain.ts +2 -1
  29. package/src/tools/image.ts +2 -1
  30. package/src/tools/oracle-price.ts +2 -1
  31. package/src/tools/research.ts +4 -2
  32. package/src/tools/scrape.ts +4 -2
  33. package/src/tools/screenshot.ts +4 -2
  34. package/src/tools/search.ts +4 -2
  35. package/src/tools/stellar-account.ts +4 -2
  36. package/src/tools/stellar-asset.ts +4 -2
  37. package/src/tools/stellar-pools.ts +2 -1
  38. package/src/tools/stocks.ts +4 -2
  39. package/src/tools/swap-quote.ts +2 -1
  40. package/src/tools/weather.ts +2 -1
  41. package/src/tools/youtube.ts +4 -2
package/dist/cli.js CHANGED
@@ -3,6 +3,7 @@ import { Mppx } from "mppx/client";
3
3
  import { stellar } from "@stellar/mpp/charge/client";
4
4
  import { Horizon } from "@stellar/stellar-sdk";
5
5
  import { loadOrCreateWallet, getKeypair } from "./lib/wallet.js";
6
+ import { apiFetch } from "./lib/api-fetch.js";
6
7
  import { TOOL_PRICES } from "./lib/config.js";
7
8
  import { logger } from "./lib/logger.js";
8
9
  // ── Arg parsing ──────────────────────────────────────────
@@ -190,7 +191,11 @@ async function main() {
190
191
  if (isPaid) {
191
192
  process.stderr.write(` Tool: ${tool} · Cost: $${TOOL_PRICES[tool]} USDC\n`);
192
193
  }
193
- const res = await fetch(url, init);
194
+ // Route through apiFetch so the X-XLMTools-Client header (and any
195
+ // future cross-cutting concerns like retries / user-agent) are
196
+ // applied consistently with the MCP tools. apiFetch detects the
197
+ // full-URL form and passes it straight through.
198
+ const res = await apiFetch(config, url, init);
194
199
  if (!res.ok) {
195
200
  const text = await res.text();
196
201
  process.stderr.write(`Error ${res.status}: ${text}\n`);
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Shared fetch helper for tool calls against the XLMTools API.
3
+ *
4
+ * Every API request gets stamped with `X-XLMTools-Client: <G-address>`
5
+ * so the server can attribute calls back to the user's wallet on the
6
+ * /stats/by-client endpoint. The header is self-declared (no signature)
7
+ * which is fine because:
8
+ * - Paid calls are additionally verified by the Stellar tx receipt
9
+ * - Free calls have no economic value to spoof
10
+ *
11
+ * Usage:
12
+ * const config = loadOrCreateWallet();
13
+ * const res = await apiFetch(config, `/crypto?ids=${ids}`);
14
+ */
15
+ export async function apiFetch(config, path, init) {
16
+ const url = path.startsWith("http") ? path : `${config.apiUrl}${path}`;
17
+ const headers = new Headers(init?.headers);
18
+ headers.set("X-XLMTools-Client", config.stellarPublicKey);
19
+ return fetch(url, { ...init, headers });
20
+ }
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { loadOrCreateWallet } from "../lib/wallet.js";
3
+ import { apiFetch } from "../lib/api-fetch.js";
3
4
  import { ok, err } from "../lib/format.js";
4
5
  export function registerCryptoTool(server) {
5
6
  server.registerTool("crypto", {
@@ -11,7 +12,7 @@ export function registerCryptoTool(server) {
11
12
  }, async ({ ids, vs_currency }) => {
12
13
  try {
13
14
  const config = loadOrCreateWallet();
14
- const res = await fetch(`${config.apiUrl}/crypto?ids=${encodeURIComponent(ids)}&vs_currency=${vs_currency}`);
15
+ const res = await apiFetch(config, `/crypto?ids=${encodeURIComponent(ids)}&vs_currency=${vs_currency}`);
15
16
  if (!res.ok)
16
17
  return err(`Crypto API error: ${res.status}`);
17
18
  return ok(await res.json());
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { loadOrCreateWallet } from "../lib/wallet.js";
3
+ import { apiFetch } from "../lib/api-fetch.js";
3
4
  import { ok, err } from "../lib/format.js";
4
5
  import { logger } from "../lib/logger.js";
5
6
  export function registerDexCandlesTool(server) {
@@ -31,7 +32,7 @@ export function registerDexCandlesTool(server) {
31
32
  resolution,
32
33
  limit: String(limit),
33
34
  });
34
- const res = await fetch(`${config.apiUrl}/dex-candles?${params}`);
35
+ const res = await apiFetch(config, `/dex-candles?${params}`);
35
36
  if (!res.ok) {
36
37
  const body = await res.text();
37
38
  return err(`Candles error ${res.status}: ${body}`);
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { loadOrCreateWallet } from "../lib/wallet.js";
3
+ import { apiFetch } from "../lib/api-fetch.js";
3
4
  import { ok, err } from "../lib/format.js";
4
5
  import { logger } from "../lib/logger.js";
5
6
  export function registerDexOrderbookTool(server) {
@@ -22,7 +23,7 @@ export function registerDexOrderbookTool(server) {
22
23
  logger.debug({ pair, limit }, "dex-orderbook invoked");
23
24
  try {
24
25
  const config = loadOrCreateWallet();
25
- const res = await fetch(`${config.apiUrl}/dex-orderbook?pair=${encodeURIComponent(pair)}&limit=${limit}`);
26
+ const res = await apiFetch(config, `/dex-orderbook?pair=${encodeURIComponent(pair)}&limit=${limit}`);
26
27
  if (!res.ok) {
27
28
  const body = await res.text();
28
29
  return err(`Orderbook error ${res.status}: ${body}`);
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { loadOrCreateWallet } from "../lib/wallet.js";
3
+ import { apiFetch } from "../lib/api-fetch.js";
3
4
  import { ok, err } from "../lib/format.js";
4
5
  import { logger } from "../lib/logger.js";
5
6
  export function registerDexTradesTool(server) {
@@ -30,7 +31,7 @@ export function registerDexTradesTool(server) {
30
31
  limit: String(limit),
31
32
  trade_type,
32
33
  });
33
- const res = await fetch(`${config.apiUrl}/dex-trades?${params}`);
34
+ const res = await apiFetch(config, `/dex-trades?${params}`);
34
35
  if (!res.ok) {
35
36
  const body = await res.text();
36
37
  return err(`Trades error ${res.status}: ${body}`);
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { loadOrCreateWallet } from "../lib/wallet.js";
3
+ import { apiFetch } from "../lib/api-fetch.js";
3
4
  import { ok, err } from "../lib/format.js";
4
5
  export function registerDomainTool(server) {
5
6
  server.registerTool("domain", {
@@ -10,7 +11,7 @@ export function registerDomainTool(server) {
10
11
  }, async ({ name }) => {
11
12
  try {
12
13
  const config = loadOrCreateWallet();
13
- const res = await fetch(`${config.apiUrl}/domain?name=${encodeURIComponent(name)}`);
14
+ const res = await apiFetch(config, `/domain?name=${encodeURIComponent(name)}`);
14
15
  if (!res.ok)
15
16
  return err(`Domain API error: ${res.status}`);
16
17
  return ok(await res.json());
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { loadOrCreateWallet } from "../lib/wallet.js";
3
+ import { apiFetch } from "../lib/api-fetch.js";
3
4
  import { okPaid, err } from "../lib/format.js";
4
5
  import { logger } from "../lib/logger.js";
5
6
  import { TOOL_PRICES } from "../lib/config.js";
@@ -22,7 +23,7 @@ export function registerImageTool(server) {
22
23
  return withCache("image", { prompt, size }, () => withBudget("image", async () => {
23
24
  try {
24
25
  const config = loadOrCreateWallet();
25
- const res = await fetch(`${config.apiUrl}/image`, {
26
+ const res = await apiFetch(config, `/image`, {
26
27
  method: "POST",
27
28
  headers: { "Content-Type": "application/json" },
28
29
  body: JSON.stringify({ prompt, size }),
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { loadOrCreateWallet } from "../lib/wallet.js";
3
+ import { apiFetch } from "../lib/api-fetch.js";
3
4
  import { ok, err } from "../lib/format.js";
4
5
  import { logger } from "../lib/logger.js";
5
6
  export function registerOraclePriceTool(server) {
@@ -21,7 +22,7 @@ export function registerOraclePriceTool(server) {
21
22
  try {
22
23
  const config = loadOrCreateWallet();
23
24
  const params = new URLSearchParams({ asset, feed });
24
- const res = await fetch(`${config.apiUrl}/oracle-price?${params}`);
25
+ const res = await apiFetch(config, `/oracle-price?${params}`);
25
26
  if (!res.ok) {
26
27
  const body = await res.text();
27
28
  return err(`Oracle error ${res.status}: ${body}`);
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { loadOrCreateWallet } from "../lib/wallet.js";
3
+ import { apiFetch } from "../lib/api-fetch.js";
3
4
  import { okPaid, err } from "../lib/format.js";
4
5
  import { logger } from "../lib/logger.js";
5
6
  import { TOOL_PRICES } from "../lib/config.js";
@@ -22,7 +23,7 @@ export function registerResearchTool(server) {
22
23
  return withCache("research", { query, num_results }, () => withBudget("research", async () => {
23
24
  try {
24
25
  const config = loadOrCreateWallet();
25
- const res = await fetch(`${config.apiUrl}/research?q=${encodeURIComponent(query)}&num_results=${num_results}`);
26
+ const res = await apiFetch(config, `/research?q=${encodeURIComponent(query)}&num_results=${num_results}`);
26
27
  if (!res.ok) {
27
28
  const body = await res.text();
28
29
  return err(`Research API error ${res.status}: ${body}`);
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { loadOrCreateWallet } from "../lib/wallet.js";
3
+ import { apiFetch } from "../lib/api-fetch.js";
3
4
  import { okPaid, err } from "../lib/format.js";
4
5
  import { logger } from "../lib/logger.js";
5
6
  import { TOOL_PRICES } from "../lib/config.js";
@@ -16,7 +17,7 @@ export function registerScrapeTool(server) {
16
17
  return withCache("scrape", { url }, () => withBudget("scrape", async () => {
17
18
  try {
18
19
  const config = loadOrCreateWallet();
19
- const res = await fetch(`${config.apiUrl}/scrape?url=${encodeURIComponent(url)}`);
20
+ const res = await apiFetch(config, `/scrape?url=${encodeURIComponent(url)}`);
20
21
  if (!res.ok) {
21
22
  const body = await res.text();
22
23
  return err(`Scrape API error ${res.status}: ${body}`);
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { loadOrCreateWallet } from "../lib/wallet.js";
3
+ import { apiFetch } from "../lib/api-fetch.js";
3
4
  import { okPaid, err } from "../lib/format.js";
4
5
  import { logger } from "../lib/logger.js";
5
6
  import { TOOL_PRICES } from "../lib/config.js";
@@ -21,7 +22,7 @@ export function registerScreenshotTool(server) {
21
22
  try {
22
23
  const config = loadOrCreateWallet();
23
24
  const params = new URLSearchParams({ url, format });
24
- const res = await fetch(`${config.apiUrl}/screenshot?${params.toString()}`);
25
+ const res = await apiFetch(config, `/screenshot?${params.toString()}`);
25
26
  if (!res.ok) {
26
27
  const body = await res.text();
27
28
  return err(`Screenshot API error ${res.status}: ${body}`);
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { loadOrCreateWallet } from "../lib/wallet.js";
3
+ import { apiFetch } from "../lib/api-fetch.js";
3
4
  import { okPaid, err } from "../lib/format.js";
4
5
  import { logger } from "../lib/logger.js";
5
6
  import { TOOL_PRICES } from "../lib/config.js";
@@ -22,7 +23,7 @@ export function registerSearchTool(server) {
22
23
  return withCache("search", { query, count }, () => withBudget("search", async () => {
23
24
  try {
24
25
  const config = loadOrCreateWallet();
25
- const res = await fetch(`${config.apiUrl}/search?q=${encodeURIComponent(query)}&count=${count}`);
26
+ const res = await apiFetch(config, `/search?q=${encodeURIComponent(query)}&count=${count}`);
26
27
  if (!res.ok) {
27
28
  const body = await res.text();
28
29
  return err(`Search API error ${res.status}: ${body}`);
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { loadOrCreateWallet } from "../lib/wallet.js";
3
+ import { apiFetch } from "../lib/api-fetch.js";
3
4
  import { ok, err } from "../lib/format.js";
4
5
  import { logger } from "../lib/logger.js";
5
6
  export function registerStellarAccountTool(server) {
@@ -15,7 +16,7 @@ export function registerStellarAccountTool(server) {
15
16
  logger.debug({ address }, "stellar-account invoked");
16
17
  try {
17
18
  const config = loadOrCreateWallet();
18
- const res = await fetch(`${config.apiUrl}/stellar-account?address=${encodeURIComponent(address)}`);
19
+ const res = await apiFetch(config, `/stellar-account?address=${encodeURIComponent(address)}`);
19
20
  if (!res.ok) {
20
21
  const body = await res.text();
21
22
  return err(`Account lookup error ${res.status}: ${body}`);
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { loadOrCreateWallet } from "../lib/wallet.js";
3
+ import { apiFetch } from "../lib/api-fetch.js";
3
4
  import { ok, err } from "../lib/format.js";
4
5
  import { logger } from "../lib/logger.js";
5
6
  export function registerStellarAssetTool(server) {
@@ -16,7 +17,7 @@ export function registerStellarAssetTool(server) {
16
17
  logger.debug({ asset }, "stellar-asset invoked");
17
18
  try {
18
19
  const config = loadOrCreateWallet();
19
- const res = await fetch(`${config.apiUrl}/stellar-asset?asset=${encodeURIComponent(asset)}`);
20
+ const res = await apiFetch(config, `/stellar-asset?asset=${encodeURIComponent(asset)}`);
20
21
  if (!res.ok) {
21
22
  const body = await res.text();
22
23
  return err(`Asset lookup error ${res.status}: ${body}`);
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { loadOrCreateWallet } from "../lib/wallet.js";
3
+ import { apiFetch } from "../lib/api-fetch.js";
3
4
  import { ok, err } from "../lib/format.js";
4
5
  import { logger } from "../lib/logger.js";
5
6
  export function registerStellarPoolsTool(server) {
@@ -25,7 +26,7 @@ export function registerStellarPoolsTool(server) {
25
26
  const params = new URLSearchParams({ limit: String(limit) });
26
27
  if (asset)
27
28
  params.set("asset", asset);
28
- const res = await fetch(`${config.apiUrl}/stellar-pools?${params}`);
29
+ const res = await apiFetch(config, `/stellar-pools?${params}`);
29
30
  if (!res.ok) {
30
31
  const body = await res.text();
31
32
  return err(`Pools error ${res.status}: ${body}`);
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { loadOrCreateWallet } from "../lib/wallet.js";
3
+ import { apiFetch } from "../lib/api-fetch.js";
3
4
  import { okPaid, err } from "../lib/format.js";
4
5
  import { logger } from "../lib/logger.js";
5
6
  import { TOOL_PRICES } from "../lib/config.js";
@@ -18,7 +19,7 @@ export function registerStocksTool(server) {
18
19
  return withCache("stocks", { symbol }, () => withBudget("stocks", async () => {
19
20
  try {
20
21
  const config = loadOrCreateWallet();
21
- const res = await fetch(`${config.apiUrl}/stocks?symbol=${encodeURIComponent(symbol)}`);
22
+ const res = await apiFetch(config, `/stocks?symbol=${encodeURIComponent(symbol)}`);
22
23
  if (!res.ok) {
23
24
  const body = await res.text();
24
25
  return err(`Stocks API error ${res.status}: ${body}`);
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { loadOrCreateWallet } from "../lib/wallet.js";
3
+ import { apiFetch } from "../lib/api-fetch.js";
3
4
  import { ok, err } from "../lib/format.js";
4
5
  import { logger } from "../lib/logger.js";
5
6
  export function registerSwapQuoteTool(server) {
@@ -22,7 +23,7 @@ export function registerSwapQuoteTool(server) {
22
23
  try {
23
24
  const config = loadOrCreateWallet();
24
25
  const params = new URLSearchParams({ from, to, amount, mode });
25
- const res = await fetch(`${config.apiUrl}/swap-quote?${params}`);
26
+ const res = await apiFetch(config, `/swap-quote?${params}`);
26
27
  if (!res.ok) {
27
28
  const body = await res.text();
28
29
  return err(`Swap quote error ${res.status}: ${body}`);
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { loadOrCreateWallet } from "../lib/wallet.js";
3
+ import { apiFetch } from "../lib/api-fetch.js";
3
4
  import { ok, err } from "../lib/format.js";
4
5
  export function registerWeatherTool(server) {
5
6
  server.registerTool("weather", {
@@ -10,7 +11,7 @@ export function registerWeatherTool(server) {
10
11
  }, async ({ location }) => {
11
12
  try {
12
13
  const config = loadOrCreateWallet();
13
- const res = await fetch(`${config.apiUrl}/weather?location=${encodeURIComponent(location)}`);
14
+ const res = await apiFetch(config, `/weather?location=${encodeURIComponent(location)}`);
14
15
  if (!res.ok)
15
16
  return err(`Weather API error: ${res.status}`);
16
17
  return ok(await res.json());
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { loadOrCreateWallet } from "../lib/wallet.js";
3
+ import { apiFetch } from "../lib/api-fetch.js";
3
4
  import { okPaid, err } from "../lib/format.js";
4
5
  import { logger } from "../lib/logger.js";
5
6
  import { TOOL_PRICES } from "../lib/config.js";
@@ -26,7 +27,7 @@ export function registerYoutubeTool(server) {
26
27
  qs.set("q", query);
27
28
  if (id)
28
29
  qs.set("id", id);
29
- const res = await fetch(`${config.apiUrl}/youtube?${qs.toString()}`);
30
+ const res = await apiFetch(config, `/youtube?${qs.toString()}`);
30
31
  if (!res.ok) {
31
32
  const body = await res.text();
32
33
  return err(`YouTube API error ${res.status}: ${body}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xlmtools/cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "xlmtools": "dist/index.js",
package/src/cli.ts CHANGED
@@ -4,6 +4,7 @@ import { Mppx } from "mppx/client";
4
4
  import { stellar } from "@stellar/mpp/charge/client";
5
5
  import { Horizon } from "@stellar/stellar-sdk";
6
6
  import { loadOrCreateWallet, getKeypair } from "./lib/wallet.js";
7
+ import { apiFetch } from "./lib/api-fetch.js";
7
8
  import { TOOL_PRICES } from "./lib/config.js";
8
9
  import { logger } from "./lib/logger.js";
9
10
 
@@ -211,7 +212,11 @@ async function main() {
211
212
  process.stderr.write(` Tool: ${tool} · Cost: $${TOOL_PRICES[tool]} USDC\n`);
212
213
  }
213
214
 
214
- const res = await fetch(url, init);
215
+ // Route through apiFetch so the X-XLMTools-Client header (and any
216
+ // future cross-cutting concerns like retries / user-agent) are
217
+ // applied consistently with the MCP tools. apiFetch detects the
218
+ // full-URL form and passes it straight through.
219
+ const res = await apiFetch(config, url, init);
215
220
 
216
221
  if (!res.ok) {
217
222
  const text = await res.text();
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Shared fetch helper for tool calls against the XLMTools API.
3
+ *
4
+ * Every API request gets stamped with `X-XLMTools-Client: <G-address>`
5
+ * so the server can attribute calls back to the user's wallet on the
6
+ * /stats/by-client endpoint. The header is self-declared (no signature)
7
+ * which is fine because:
8
+ * - Paid calls are additionally verified by the Stellar tx receipt
9
+ * - Free calls have no economic value to spoof
10
+ *
11
+ * Usage:
12
+ * const config = loadOrCreateWallet();
13
+ * const res = await apiFetch(config, `/crypto?ids=${ids}`);
14
+ */
15
+
16
+ export interface ClientConfig {
17
+ apiUrl: string;
18
+ stellarPublicKey: string;
19
+ }
20
+
21
+ export async function apiFetch(
22
+ config: ClientConfig,
23
+ path: string,
24
+ init?: RequestInit,
25
+ ): Promise<Response> {
26
+ const url = path.startsWith("http") ? path : `${config.apiUrl}${path}`;
27
+ const headers = new Headers(init?.headers);
28
+ headers.set("X-XLMTools-Client", config.stellarPublicKey);
29
+ return fetch(url, { ...init, headers });
30
+ }
@@ -1,6 +1,7 @@
1
1
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { z } from "zod";
3
3
  import { loadOrCreateWallet } from "../lib/wallet.js";
4
+ import { apiFetch } from "../lib/api-fetch.js";
4
5
  import { ok, err } from "../lib/format.js";
5
6
 
6
7
  export function registerCryptoTool(server: McpServer): void {
@@ -16,7 +17,7 @@ export function registerCryptoTool(server: McpServer): void {
16
17
  async ({ ids, vs_currency }) => {
17
18
  try {
18
19
  const config = loadOrCreateWallet();
19
- const res = await fetch(`${config.apiUrl}/crypto?ids=${encodeURIComponent(ids)}&vs_currency=${vs_currency}`);
20
+ const res = await apiFetch(config, `/crypto?ids=${encodeURIComponent(ids)}&vs_currency=${vs_currency}`);
20
21
  if (!res.ok) return err(`Crypto API error: ${res.status}`);
21
22
  return ok(await res.json());
22
23
  } catch (e) { return err(String(e)); }
@@ -1,6 +1,7 @@
1
1
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { z } from "zod";
3
3
  import { loadOrCreateWallet } from "../lib/wallet.js";
4
+ import { apiFetch } from "../lib/api-fetch.js";
4
5
  import { ok, err } from "../lib/format.js";
5
6
  import { logger } from "../lib/logger.js";
6
7
 
@@ -37,7 +38,7 @@ export function registerDexCandlesTool(server: McpServer): void {
37
38
  resolution,
38
39
  limit: String(limit),
39
40
  });
40
- const res = await fetch(`${config.apiUrl}/dex-candles?${params}`);
41
+ const res = await apiFetch(config, `/dex-candles?${params}`);
41
42
  if (!res.ok) {
42
43
  const body = await res.text();
43
44
  return err(`Candles error ${res.status}: ${body}`);
@@ -1,6 +1,7 @@
1
1
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { z } from "zod";
3
3
  import { loadOrCreateWallet } from "../lib/wallet.js";
4
+ import { apiFetch } from "../lib/api-fetch.js";
4
5
  import { ok, err } from "../lib/format.js";
5
6
  import { logger } from "../lib/logger.js";
6
7
 
@@ -28,8 +29,9 @@ export function registerDexOrderbookTool(server: McpServer): void {
28
29
  logger.debug({ pair, limit }, "dex-orderbook invoked");
29
30
  try {
30
31
  const config = loadOrCreateWallet();
31
- const res = await fetch(
32
- `${config.apiUrl}/dex-orderbook?pair=${encodeURIComponent(pair)}&limit=${limit}`
32
+ const res = await apiFetch(
33
+ config,
34
+ `/dex-orderbook?pair=${encodeURIComponent(pair)}&limit=${limit}`,
33
35
  );
34
36
  if (!res.ok) {
35
37
  const body = await res.text();
@@ -1,6 +1,7 @@
1
1
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { z } from "zod";
3
3
  import { loadOrCreateWallet } from "../lib/wallet.js";
4
+ import { apiFetch } from "../lib/api-fetch.js";
4
5
  import { ok, err } from "../lib/format.js";
5
6
  import { logger } from "../lib/logger.js";
6
7
 
@@ -36,7 +37,7 @@ export function registerDexTradesTool(server: McpServer): void {
36
37
  limit: String(limit),
37
38
  trade_type,
38
39
  });
39
- const res = await fetch(`${config.apiUrl}/dex-trades?${params}`);
40
+ const res = await apiFetch(config, `/dex-trades?${params}`);
40
41
  if (!res.ok) {
41
42
  const body = await res.text();
42
43
  return err(`Trades error ${res.status}: ${body}`);
@@ -1,6 +1,7 @@
1
1
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { z } from "zod";
3
3
  import { loadOrCreateWallet } from "../lib/wallet.js";
4
+ import { apiFetch } from "../lib/api-fetch.js";
4
5
  import { ok, err } from "../lib/format.js";
5
6
 
6
7
  export function registerDomainTool(server: McpServer): void {
@@ -15,7 +16,7 @@ export function registerDomainTool(server: McpServer): void {
15
16
  async ({ name }) => {
16
17
  try {
17
18
  const config = loadOrCreateWallet();
18
- const res = await fetch(`${config.apiUrl}/domain?name=${encodeURIComponent(name)}`);
19
+ const res = await apiFetch(config, `/domain?name=${encodeURIComponent(name)}`);
19
20
  if (!res.ok) return err(`Domain API error: ${res.status}`);
20
21
  return ok(await res.json());
21
22
  } catch (e) { return err(String(e)); }
@@ -1,6 +1,7 @@
1
1
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { z } from "zod";
3
3
  import { loadOrCreateWallet } from "../lib/wallet.js";
4
+ import { apiFetch } from "../lib/api-fetch.js";
4
5
  import { okPaid, err } from "../lib/format.js";
5
6
  import { logger } from "../lib/logger.js";
6
7
  import { TOOL_PRICES } from "../lib/config.js";
@@ -28,7 +29,7 @@ export function registerImageTool(server: McpServer): void {
28
29
  withBudget("image", async () => {
29
30
  try {
30
31
  const config = loadOrCreateWallet();
31
- const res = await fetch(`${config.apiUrl}/image`, {
32
+ const res = await apiFetch(config, `/image`, {
32
33
  method: "POST",
33
34
  headers: { "Content-Type": "application/json" },
34
35
  body: JSON.stringify({ prompt, size }),
@@ -1,6 +1,7 @@
1
1
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { z } from "zod";
3
3
  import { loadOrCreateWallet } from "../lib/wallet.js";
4
+ import { apiFetch } from "../lib/api-fetch.js";
4
5
  import { ok, err } from "../lib/format.js";
5
6
  import { logger } from "../lib/logger.js";
6
7
 
@@ -27,7 +28,7 @@ export function registerOraclePriceTool(server: McpServer): void {
27
28
  try {
28
29
  const config = loadOrCreateWallet();
29
30
  const params = new URLSearchParams({ asset, feed });
30
- const res = await fetch(`${config.apiUrl}/oracle-price?${params}`);
31
+ const res = await apiFetch(config, `/oracle-price?${params}`);
31
32
  if (!res.ok) {
32
33
  const body = await res.text();
33
34
  return err(`Oracle error ${res.status}: ${body}`);
@@ -1,6 +1,7 @@
1
1
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { z } from "zod";
3
3
  import { loadOrCreateWallet } from "../lib/wallet.js";
4
+ import { apiFetch } from "../lib/api-fetch.js";
4
5
  import { okPaid, err } from "../lib/format.js";
5
6
  import { logger } from "../lib/logger.js";
6
7
  import { TOOL_PRICES } from "../lib/config.js";
@@ -28,8 +29,9 @@ export function registerResearchTool(server: McpServer): void {
28
29
  withBudget("research", async () => {
29
30
  try {
30
31
  const config = loadOrCreateWallet();
31
- const res = await fetch(
32
- `${config.apiUrl}/research?q=${encodeURIComponent(query)}&num_results=${num_results}`,
32
+ const res = await apiFetch(
33
+ config,
34
+ `/research?q=${encodeURIComponent(query)}&num_results=${num_results}`,
33
35
  );
34
36
  if (!res.ok) {
35
37
  const body = await res.text();
@@ -1,6 +1,7 @@
1
1
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { z } from "zod";
3
3
  import { loadOrCreateWallet } from "../lib/wallet.js";
4
+ import { apiFetch } from "../lib/api-fetch.js";
4
5
  import { okPaid, err } from "../lib/format.js";
5
6
  import { logger } from "../lib/logger.js";
6
7
  import { TOOL_PRICES } from "../lib/config.js";
@@ -22,8 +23,9 @@ export function registerScrapeTool(server: McpServer): void {
22
23
  withBudget("scrape", async () => {
23
24
  try {
24
25
  const config = loadOrCreateWallet();
25
- const res = await fetch(
26
- `${config.apiUrl}/scrape?url=${encodeURIComponent(url)}`,
26
+ const res = await apiFetch(
27
+ config,
28
+ `/scrape?url=${encodeURIComponent(url)}`,
27
29
  );
28
30
  if (!res.ok) {
29
31
  const body = await res.text();
@@ -1,6 +1,7 @@
1
1
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { z } from "zod";
3
3
  import { loadOrCreateWallet } from "../lib/wallet.js";
4
+ import { apiFetch } from "../lib/api-fetch.js";
4
5
  import { okPaid, err } from "../lib/format.js";
5
6
  import { logger } from "../lib/logger.js";
6
7
  import { TOOL_PRICES } from "../lib/config.js";
@@ -27,8 +28,9 @@ export function registerScreenshotTool(server: McpServer): void {
27
28
  try {
28
29
  const config = loadOrCreateWallet();
29
30
  const params = new URLSearchParams({ url, format });
30
- const res = await fetch(
31
- `${config.apiUrl}/screenshot?${params.toString()}`,
31
+ const res = await apiFetch(
32
+ config,
33
+ `/screenshot?${params.toString()}`,
32
34
  );
33
35
  if (!res.ok) {
34
36
  const body = await res.text();
@@ -1,6 +1,7 @@
1
1
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { z } from "zod";
3
3
  import { loadOrCreateWallet } from "../lib/wallet.js";
4
+ import { apiFetch } from "../lib/api-fetch.js";
4
5
  import { okPaid, err } from "../lib/format.js";
5
6
  import { logger } from "../lib/logger.js";
6
7
  import { TOOL_PRICES } from "../lib/config.js";
@@ -28,8 +29,9 @@ export function registerSearchTool(server: McpServer): void {
28
29
  withBudget("search", async () => {
29
30
  try {
30
31
  const config = loadOrCreateWallet();
31
- const res = await fetch(
32
- `${config.apiUrl}/search?q=${encodeURIComponent(query)}&count=${count}`,
32
+ const res = await apiFetch(
33
+ config,
34
+ `/search?q=${encodeURIComponent(query)}&count=${count}`,
33
35
  );
34
36
  if (!res.ok) {
35
37
  const body = await res.text();
@@ -1,6 +1,7 @@
1
1
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { z } from "zod";
3
3
  import { loadOrCreateWallet } from "../lib/wallet.js";
4
+ import { apiFetch } from "../lib/api-fetch.js";
4
5
  import { ok, err } from "../lib/format.js";
5
6
  import { logger } from "../lib/logger.js";
6
7
 
@@ -21,8 +22,9 @@ export function registerStellarAccountTool(server: McpServer): void {
21
22
  logger.debug({ address }, "stellar-account invoked");
22
23
  try {
23
24
  const config = loadOrCreateWallet();
24
- const res = await fetch(
25
- `${config.apiUrl}/stellar-account?address=${encodeURIComponent(address)}`
25
+ const res = await apiFetch(
26
+ config,
27
+ `/stellar-account?address=${encodeURIComponent(address)}`,
26
28
  );
27
29
  if (!res.ok) {
28
30
  const body = await res.text();
@@ -1,6 +1,7 @@
1
1
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { z } from "zod";
3
3
  import { loadOrCreateWallet } from "../lib/wallet.js";
4
+ import { apiFetch } from "../lib/api-fetch.js";
4
5
  import { ok, err } from "../lib/format.js";
5
6
  import { logger } from "../lib/logger.js";
6
7
 
@@ -22,8 +23,9 @@ export function registerStellarAssetTool(server: McpServer): void {
22
23
  logger.debug({ asset }, "stellar-asset invoked");
23
24
  try {
24
25
  const config = loadOrCreateWallet();
25
- const res = await fetch(
26
- `${config.apiUrl}/stellar-asset?asset=${encodeURIComponent(asset)}`
26
+ const res = await apiFetch(
27
+ config,
28
+ `/stellar-asset?asset=${encodeURIComponent(asset)}`,
27
29
  );
28
30
  if (!res.ok) {
29
31
  const body = await res.text();
@@ -1,6 +1,7 @@
1
1
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { z } from "zod";
3
3
  import { loadOrCreateWallet } from "../lib/wallet.js";
4
+ import { apiFetch } from "../lib/api-fetch.js";
4
5
  import { ok, err } from "../lib/format.js";
5
6
  import { logger } from "../lib/logger.js";
6
7
 
@@ -30,7 +31,7 @@ export function registerStellarPoolsTool(server: McpServer): void {
30
31
  const config = loadOrCreateWallet();
31
32
  const params = new URLSearchParams({ limit: String(limit) });
32
33
  if (asset) params.set("asset", asset);
33
- const res = await fetch(`${config.apiUrl}/stellar-pools?${params}`);
34
+ const res = await apiFetch(config, `/stellar-pools?${params}`);
34
35
  if (!res.ok) {
35
36
  const body = await res.text();
36
37
  return err(`Pools error ${res.status}: ${body}`);
@@ -1,6 +1,7 @@
1
1
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { z } from "zod";
3
3
  import { loadOrCreateWallet } from "../lib/wallet.js";
4
+ import { apiFetch } from "../lib/api-fetch.js";
4
5
  import { okPaid, err } from "../lib/format.js";
5
6
  import { logger } from "../lib/logger.js";
6
7
  import { TOOL_PRICES } from "../lib/config.js";
@@ -24,8 +25,9 @@ export function registerStocksTool(server: McpServer): void {
24
25
  withBudget("stocks", async () => {
25
26
  try {
26
27
  const config = loadOrCreateWallet();
27
- const res = await fetch(
28
- `${config.apiUrl}/stocks?symbol=${encodeURIComponent(symbol)}`,
28
+ const res = await apiFetch(
29
+ config,
30
+ `/stocks?symbol=${encodeURIComponent(symbol)}`,
29
31
  );
30
32
  if (!res.ok) {
31
33
  const body = await res.text();
@@ -1,6 +1,7 @@
1
1
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { z } from "zod";
3
3
  import { loadOrCreateWallet } from "../lib/wallet.js";
4
+ import { apiFetch } from "../lib/api-fetch.js";
4
5
  import { ok, err } from "../lib/format.js";
5
6
  import { logger } from "../lib/logger.js";
6
7
 
@@ -28,7 +29,7 @@ export function registerSwapQuoteTool(server: McpServer): void {
28
29
  try {
29
30
  const config = loadOrCreateWallet();
30
31
  const params = new URLSearchParams({ from, to, amount, mode });
31
- const res = await fetch(`${config.apiUrl}/swap-quote?${params}`);
32
+ const res = await apiFetch(config, `/swap-quote?${params}`);
32
33
  if (!res.ok) {
33
34
  const body = await res.text();
34
35
  return err(`Swap quote error ${res.status}: ${body}`);
@@ -1,6 +1,7 @@
1
1
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { z } from "zod";
3
3
  import { loadOrCreateWallet } from "../lib/wallet.js";
4
+ import { apiFetch } from "../lib/api-fetch.js";
4
5
  import { ok, err } from "../lib/format.js";
5
6
 
6
7
  export function registerWeatherTool(server: McpServer): void {
@@ -15,7 +16,7 @@ export function registerWeatherTool(server: McpServer): void {
15
16
  async ({ location }) => {
16
17
  try {
17
18
  const config = loadOrCreateWallet();
18
- const res = await fetch(`${config.apiUrl}/weather?location=${encodeURIComponent(location)}`);
19
+ const res = await apiFetch(config, `/weather?location=${encodeURIComponent(location)}`);
19
20
  if (!res.ok) return err(`Weather API error: ${res.status}`);
20
21
  return ok(await res.json());
21
22
  } catch (e) { return err(String(e)); }
@@ -1,6 +1,7 @@
1
1
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { z } from "zod";
3
3
  import { loadOrCreateWallet } from "../lib/wallet.js";
4
+ import { apiFetch } from "../lib/api-fetch.js";
4
5
  import { okPaid, err } from "../lib/format.js";
5
6
  import { logger } from "../lib/logger.js";
6
7
  import { TOOL_PRICES } from "../lib/config.js";
@@ -30,8 +31,9 @@ export function registerYoutubeTool(server: McpServer): void {
30
31
  const qs = new URLSearchParams();
31
32
  if (query) qs.set("q", query);
32
33
  if (id) qs.set("id", id);
33
- const res = await fetch(
34
- `${config.apiUrl}/youtube?${qs.toString()}`,
34
+ const res = await apiFetch(
35
+ config,
36
+ `/youtube?${qs.toString()}`,
35
37
  );
36
38
  if (!res.ok) {
37
39
  const body = await res.text();