@xlmtools/cli 0.1.2 → 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 +18 -12
- package/dist/cli.d.ts +2 -0
- package/{src/lib/api-fetch.ts → dist/lib/api-fetch.d.ts} +3 -14
- package/dist/lib/budget.d.ts +14 -0
- package/dist/lib/cache.d.ts +7 -0
- package/dist/lib/config.d.ts +2 -0
- package/dist/lib/format.d.ts +15 -0
- package/dist/lib/logger.d.ts +2 -0
- package/dist/lib/wallet.d.ts +9 -0
- package/dist/server.d.ts +22 -0
- package/dist/server.js +89 -0
- package/dist/tools/budget.d.ts +2 -0
- package/dist/tools/crypto.d.ts +2 -0
- package/dist/tools/dex-candles.d.ts +2 -0
- package/dist/tools/dex-orderbook.d.ts +2 -0
- package/dist/tools/dex-trades.d.ts +2 -0
- package/dist/tools/domain.d.ts +2 -0
- package/dist/tools/image.d.ts +2 -0
- package/dist/tools/oracle-price.d.ts +2 -0
- package/dist/tools/research.d.ts +2 -0
- package/dist/tools/scrape.d.ts +2 -0
- package/dist/tools/screenshot.d.ts +2 -0
- package/dist/tools/search.d.ts +2 -0
- package/dist/tools/stellar-account.d.ts +2 -0
- package/dist/tools/stellar-asset.d.ts +2 -0
- package/dist/tools/stellar-pools.d.ts +2 -0
- package/dist/tools/stocks.d.ts +2 -0
- package/dist/tools/swap-quote.d.ts +2 -0
- package/dist/tools/tools-list.d.ts +2 -0
- package/dist/tools/wallet-tool.d.ts +2 -0
- package/dist/tools/weather.d.ts +2 -0
- package/dist/tools/youtube.d.ts +2 -0
- package/package.json +27 -3
- package/dist/index.js +0 -77
- package/dist/tools/card.js +0 -51
- package/dist/tools/reddit.js +0 -40
- package/src/cli.ts +0 -245
- package/src/index.ts +0 -90
- package/src/lib/budget.ts +0 -78
- package/src/lib/cache.ts +0 -66
- package/src/lib/config.ts +0 -18
- package/src/lib/format.ts +0 -51
- package/src/lib/logger.ts +0 -6
- package/src/lib/wallet.ts +0 -143
- package/src/tools/budget.ts +0 -67
- package/src/tools/crypto.ts +0 -26
- package/src/tools/dex-candles.ts +0 -53
- package/src/tools/dex-orderbook.ts +0 -47
- package/src/tools/dex-trades.ts +0 -52
- package/src/tools/domain.ts +0 -25
- package/src/tools/image.ts +0 -50
- package/src/tools/oracle-price.ts +0 -43
- package/src/tools/research.ts +0 -49
- package/src/tools/scrape.ts +0 -43
- package/src/tools/screenshot.ts +0 -48
- package/src/tools/search.ts +0 -49
- package/src/tools/stellar-account.ts +0 -40
- package/src/tools/stellar-asset.ts +0 -41
- package/src/tools/stellar-pools.ts +0 -46
- package/src/tools/stocks.ts +0 -45
- package/src/tools/swap-quote.ts +0 -44
- package/src/tools/tools-list.ts +0 -22
- package/src/tools/wallet-tool.ts +0 -51
- package/src/tools/weather.ts +0 -25
- package/src/tools/youtube.ts +0 -51
- package/tsconfig.json +0 -13
package/src/tools/search.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import { loadOrCreateWallet } from "../lib/wallet.js";
|
|
4
|
-
import { apiFetch } from "../lib/api-fetch.js";
|
|
5
|
-
import { okPaid, err } from "../lib/format.js";
|
|
6
|
-
import { logger } from "../lib/logger.js";
|
|
7
|
-
import { TOOL_PRICES } from "../lib/config.js";
|
|
8
|
-
import { withBudget } from "../lib/budget.js";
|
|
9
|
-
import { withCache } from "../lib/cache.js";
|
|
10
|
-
|
|
11
|
-
export function registerSearchTool(server: McpServer): void {
|
|
12
|
-
server.registerTool(
|
|
13
|
-
"search",
|
|
14
|
-
{
|
|
15
|
-
title: "Web Search",
|
|
16
|
-
description: `Search the web and news in real-time. Returns results with source URLs.\nCost: $${TOOL_PRICES.search} USDC per search (paid via Stellar MPP).`, inputSchema: z.object({
|
|
17
|
-
query: z.string().describe("Search query"),
|
|
18
|
-
count: z.coerce.number()
|
|
19
|
-
.int()
|
|
20
|
-
.min(1)
|
|
21
|
-
.max(20)
|
|
22
|
-
.default(10)
|
|
23
|
-
.describe("Number of results (1-20)"),
|
|
24
|
-
}),
|
|
25
|
-
},
|
|
26
|
-
async ({ query, count }) => {
|
|
27
|
-
logger.debug({ query, count }, "search tool invoked");
|
|
28
|
-
return withCache("search", { query, count }, () =>
|
|
29
|
-
withBudget("search", async () => {
|
|
30
|
-
try {
|
|
31
|
-
const config = loadOrCreateWallet();
|
|
32
|
-
const res = await apiFetch(
|
|
33
|
-
config,
|
|
34
|
-
`/search?q=${encodeURIComponent(query)}&count=${count}`,
|
|
35
|
-
);
|
|
36
|
-
if (!res.ok) {
|
|
37
|
-
const body = await res.text();
|
|
38
|
-
return err(`Search API error ${res.status}: ${body}`);
|
|
39
|
-
}
|
|
40
|
-
return okPaid(await res.json());
|
|
41
|
-
} catch (e: unknown) {
|
|
42
|
-
logger.error({ err: e }, "search tool error");
|
|
43
|
-
return err(`Search failed: ${String(e)}`);
|
|
44
|
-
}
|
|
45
|
-
}),
|
|
46
|
-
);
|
|
47
|
-
},
|
|
48
|
-
);
|
|
49
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import { loadOrCreateWallet } from "../lib/wallet.js";
|
|
4
|
-
import { apiFetch } from "../lib/api-fetch.js";
|
|
5
|
-
import { ok, err } from "../lib/format.js";
|
|
6
|
-
import { logger } from "../lib/logger.js";
|
|
7
|
-
|
|
8
|
-
export function registerStellarAccountTool(server: McpServer): void {
|
|
9
|
-
server.registerTool(
|
|
10
|
-
"stellar-account",
|
|
11
|
-
{
|
|
12
|
-
title: "Stellar Account Lookup",
|
|
13
|
-
description:
|
|
14
|
-
`Look up any Stellar account: balances, trustlines, signers, and status.\n` +
|
|
15
|
-
`Provide a Stellar public key (starts with G, 56 characters).\nFree.`, inputSchema: z.object({
|
|
16
|
-
address: z
|
|
17
|
-
.string()
|
|
18
|
-
.describe("Stellar public key (G-address)"),
|
|
19
|
-
}),
|
|
20
|
-
},
|
|
21
|
-
async ({ address }) => {
|
|
22
|
-
logger.debug({ address }, "stellar-account invoked");
|
|
23
|
-
try {
|
|
24
|
-
const config = loadOrCreateWallet();
|
|
25
|
-
const res = await apiFetch(
|
|
26
|
-
config,
|
|
27
|
-
`/stellar-account?address=${encodeURIComponent(address)}`,
|
|
28
|
-
);
|
|
29
|
-
if (!res.ok) {
|
|
30
|
-
const body = await res.text();
|
|
31
|
-
return err(`Account lookup error ${res.status}: ${body}`);
|
|
32
|
-
}
|
|
33
|
-
return ok(await res.json());
|
|
34
|
-
} catch (e) {
|
|
35
|
-
logger.error({ err: e }, "stellar-account error");
|
|
36
|
-
return err(`Account lookup failed: ${String(e)}`);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
);
|
|
40
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import { loadOrCreateWallet } from "../lib/wallet.js";
|
|
4
|
-
import { apiFetch } from "../lib/api-fetch.js";
|
|
5
|
-
import { ok, err } from "../lib/format.js";
|
|
6
|
-
import { logger } from "../lib/logger.js";
|
|
7
|
-
|
|
8
|
-
export function registerStellarAssetTool(server: McpServer): void {
|
|
9
|
-
server.registerTool(
|
|
10
|
-
"stellar-asset",
|
|
11
|
-
{
|
|
12
|
-
title: "Stellar Asset Info",
|
|
13
|
-
description:
|
|
14
|
-
`Look up any Stellar asset: supply, trustlines, rating, issuer org, and more.\n` +
|
|
15
|
-
`Combines on-chain data (Horizon) with analytics (StellarExpert).\n` +
|
|
16
|
-
`Examples: "USDC", "AQUA", "yUSDC", or "CODE:ISSUER".\nFree.`, inputSchema: z.object({
|
|
17
|
-
asset: z
|
|
18
|
-
.string()
|
|
19
|
-
.describe('Asset to look up (e.g. "USDC", "XLM", "AQUA", "CODE:ISSUER")'),
|
|
20
|
-
}),
|
|
21
|
-
},
|
|
22
|
-
async ({ asset }) => {
|
|
23
|
-
logger.debug({ asset }, "stellar-asset invoked");
|
|
24
|
-
try {
|
|
25
|
-
const config = loadOrCreateWallet();
|
|
26
|
-
const res = await apiFetch(
|
|
27
|
-
config,
|
|
28
|
-
`/stellar-asset?asset=${encodeURIComponent(asset)}`,
|
|
29
|
-
);
|
|
30
|
-
if (!res.ok) {
|
|
31
|
-
const body = await res.text();
|
|
32
|
-
return err(`Asset lookup error ${res.status}: ${body}`);
|
|
33
|
-
}
|
|
34
|
-
return ok(await res.json());
|
|
35
|
-
} catch (e) {
|
|
36
|
-
logger.error({ err: e }, "stellar-asset error");
|
|
37
|
-
return err(`Asset lookup failed: ${String(e)}`);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
);
|
|
41
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import { loadOrCreateWallet } from "../lib/wallet.js";
|
|
4
|
-
import { apiFetch } from "../lib/api-fetch.js";
|
|
5
|
-
import { ok, err } from "../lib/format.js";
|
|
6
|
-
import { logger } from "../lib/logger.js";
|
|
7
|
-
|
|
8
|
-
export function registerStellarPoolsTool(server: McpServer): void {
|
|
9
|
-
server.registerTool(
|
|
10
|
-
"stellar-pools",
|
|
11
|
-
{
|
|
12
|
-
title: "Stellar Liquidity Pools",
|
|
13
|
-
description:
|
|
14
|
-
`Browse Stellar liquidity pools. Optionally filter by asset.\n` +
|
|
15
|
-
`Shows reserves, shares, trustlines, and fees.\nFree.`, inputSchema: z.object({
|
|
16
|
-
asset: z
|
|
17
|
-
.string()
|
|
18
|
-
.optional()
|
|
19
|
-
.describe('Filter by asset (e.g. "XLM", "USDC"). Omit for all pools.'),
|
|
20
|
-
limit: z.coerce.number()
|
|
21
|
-
.int()
|
|
22
|
-
.min(1)
|
|
23
|
-
.max(200)
|
|
24
|
-
.default(10)
|
|
25
|
-
.describe("Number of pools (1-200)"),
|
|
26
|
-
}),
|
|
27
|
-
},
|
|
28
|
-
async ({ asset, limit }) => {
|
|
29
|
-
logger.debug({ asset, limit }, "stellar-pools invoked");
|
|
30
|
-
try {
|
|
31
|
-
const config = loadOrCreateWallet();
|
|
32
|
-
const params = new URLSearchParams({ limit: String(limit) });
|
|
33
|
-
if (asset) params.set("asset", asset);
|
|
34
|
-
const res = await apiFetch(config, `/stellar-pools?${params}`);
|
|
35
|
-
if (!res.ok) {
|
|
36
|
-
const body = await res.text();
|
|
37
|
-
return err(`Pools error ${res.status}: ${body}`);
|
|
38
|
-
}
|
|
39
|
-
return ok(await res.json());
|
|
40
|
-
} catch (e) {
|
|
41
|
-
logger.error({ err: e }, "stellar-pools error");
|
|
42
|
-
return err(`Pools failed: ${String(e)}`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
);
|
|
46
|
-
}
|
package/src/tools/stocks.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import { loadOrCreateWallet } from "../lib/wallet.js";
|
|
4
|
-
import { apiFetch } from "../lib/api-fetch.js";
|
|
5
|
-
import { okPaid, err } from "../lib/format.js";
|
|
6
|
-
import { logger } from "../lib/logger.js";
|
|
7
|
-
import { TOOL_PRICES } from "../lib/config.js";
|
|
8
|
-
import { withBudget } from "../lib/budget.js";
|
|
9
|
-
import { withCache } from "../lib/cache.js";
|
|
10
|
-
|
|
11
|
-
export function registerStocksTool(server: McpServer): void {
|
|
12
|
-
server.registerTool(
|
|
13
|
-
"stocks",
|
|
14
|
-
{
|
|
15
|
-
title: "Stock Quotes",
|
|
16
|
-
description: `Get real-time stock price and market data for any ticker symbol.\nCost: $${TOOL_PRICES.stocks} USDC per query (paid via Stellar MPP).`, inputSchema: z.object({
|
|
17
|
-
symbol: z
|
|
18
|
-
.string()
|
|
19
|
-
.describe("Stock ticker symbol (e.g. AAPL, TSLA, MSFT)"),
|
|
20
|
-
}),
|
|
21
|
-
},
|
|
22
|
-
async ({ symbol }) => {
|
|
23
|
-
logger.debug({ symbol }, "stocks tool invoked");
|
|
24
|
-
return withCache("stocks", { symbol }, () =>
|
|
25
|
-
withBudget("stocks", async () => {
|
|
26
|
-
try {
|
|
27
|
-
const config = loadOrCreateWallet();
|
|
28
|
-
const res = await apiFetch(
|
|
29
|
-
config,
|
|
30
|
-
`/stocks?symbol=${encodeURIComponent(symbol)}`,
|
|
31
|
-
);
|
|
32
|
-
if (!res.ok) {
|
|
33
|
-
const body = await res.text();
|
|
34
|
-
return err(`Stocks API error ${res.status}: ${body}`);
|
|
35
|
-
}
|
|
36
|
-
return okPaid(await res.json());
|
|
37
|
-
} catch (e: unknown) {
|
|
38
|
-
logger.error({ err: e }, "stocks tool error");
|
|
39
|
-
return err(`Stocks query failed: ${String(e)}`);
|
|
40
|
-
}
|
|
41
|
-
}),
|
|
42
|
-
);
|
|
43
|
-
},
|
|
44
|
-
);
|
|
45
|
-
}
|
package/src/tools/swap-quote.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import { loadOrCreateWallet } from "../lib/wallet.js";
|
|
4
|
-
import { apiFetch } from "../lib/api-fetch.js";
|
|
5
|
-
import { ok, err } from "../lib/format.js";
|
|
6
|
-
import { logger } from "../lib/logger.js";
|
|
7
|
-
|
|
8
|
-
export function registerSwapQuoteTool(server: McpServer): void {
|
|
9
|
-
server.registerTool(
|
|
10
|
-
"swap-quote",
|
|
11
|
-
{
|
|
12
|
-
title: "Stellar Swap Quote",
|
|
13
|
-
description:
|
|
14
|
-
`Find the best swap path between any two Stellar assets using the native DEX.\n` +
|
|
15
|
-
`Shows rate, path hops, and slippage tips.\n` +
|
|
16
|
-
`Examples: swap 100 XLM to USDC, swap 50 USDC to EURC.\n` +
|
|
17
|
-
`Well-known assets: XLM, USDC, EURC, AQUA, yUSDC, BLND, SHX.\nFree.`, inputSchema: z.object({
|
|
18
|
-
from: z.string().describe('Source asset (e.g. "XLM", "USDC")'),
|
|
19
|
-
to: z.string().describe('Destination asset (e.g. "USDC", "EURC")'),
|
|
20
|
-
amount: z.string().describe("Amount to swap"),
|
|
21
|
-
mode: z
|
|
22
|
-
.enum(["send", "receive"])
|
|
23
|
-
.default("send")
|
|
24
|
-
.describe('"send" = you fix what you send; "receive" = you fix what you get'),
|
|
25
|
-
}),
|
|
26
|
-
},
|
|
27
|
-
async ({ from, to, amount, mode }) => {
|
|
28
|
-
logger.debug({ from, to, amount, mode }, "swap-quote invoked");
|
|
29
|
-
try {
|
|
30
|
-
const config = loadOrCreateWallet();
|
|
31
|
-
const params = new URLSearchParams({ from, to, amount, mode });
|
|
32
|
-
const res = await apiFetch(config, `/swap-quote?${params}`);
|
|
33
|
-
if (!res.ok) {
|
|
34
|
-
const body = await res.text();
|
|
35
|
-
return err(`Swap quote error ${res.status}: ${body}`);
|
|
36
|
-
}
|
|
37
|
-
return ok(await res.json());
|
|
38
|
-
} catch (e) {
|
|
39
|
-
logger.error({ err: e }, "swap-quote error");
|
|
40
|
-
return err(`Swap quote failed: ${String(e)}`);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
);
|
|
44
|
-
}
|
package/src/tools/tools-list.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import { TOOL_PRICES, FREE_TOOLS } from "../lib/config.js";
|
|
4
|
-
import { ok } from "../lib/format.js";
|
|
5
|
-
|
|
6
|
-
export function registerToolsListTool(server: McpServer): void {
|
|
7
|
-
server.registerTool(
|
|
8
|
-
"tools",
|
|
9
|
-
{
|
|
10
|
-
title: "List Tools",
|
|
11
|
-
description: "List all XLMTools tools with their per-call cost in USDC.", inputSchema: z.object({}),
|
|
12
|
-
},
|
|
13
|
-
async () => {
|
|
14
|
-
return ok({
|
|
15
|
-
paid: Object.entries(TOOL_PRICES).map(([tool, cost]) => ({ tool, cost_usdc: cost })),
|
|
16
|
-
free: Array.from(FREE_TOOLS),
|
|
17
|
-
network: "stellar:testnet",
|
|
18
|
-
payment: "MPP charge mode — USDC auto-deducted per call",
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
);
|
|
22
|
-
}
|
package/src/tools/wallet-tool.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import { Horizon } from "@stellar/stellar-sdk";
|
|
4
|
-
import { loadOrCreateWallet } from "../lib/wallet.js";
|
|
5
|
-
import { ok, err } from "../lib/format.js";
|
|
6
|
-
import { logger } from "../lib/logger.js";
|
|
7
|
-
|
|
8
|
-
export function registerWalletTool(server: McpServer): void {
|
|
9
|
-
server.registerTool(
|
|
10
|
-
"wallet",
|
|
11
|
-
{
|
|
12
|
-
title: "XLMTools Wallet",
|
|
13
|
-
description:
|
|
14
|
-
"Show your Stellar wallet address, current USDC balance, and how to fund it. Free.", inputSchema: z.object({}),
|
|
15
|
-
},
|
|
16
|
-
async () => {
|
|
17
|
-
logger.debug("wallet tool invoked");
|
|
18
|
-
try {
|
|
19
|
-
const config = loadOrCreateWallet();
|
|
20
|
-
const horizon = new Horizon.Server(
|
|
21
|
-
"https://horizon-testnet.stellar.org"
|
|
22
|
-
);
|
|
23
|
-
const account = await horizon.loadAccount(config.stellarPublicKey);
|
|
24
|
-
|
|
25
|
-
const xlm = account.balances.find(
|
|
26
|
-
(b) => b.asset_type === "native"
|
|
27
|
-
);
|
|
28
|
-
const usdc = account.balances.find(
|
|
29
|
-
(b) =>
|
|
30
|
-
b.asset_type === "credit_alphanum4" &&
|
|
31
|
-
(b as { asset_code?: string }).asset_code === "USDC"
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
return ok({
|
|
35
|
-
address: config.stellarPublicKey,
|
|
36
|
-
xlm_balance: xlm?.balance ?? "0",
|
|
37
|
-
usdc_balance:
|
|
38
|
-
usdc?.balance ?? "0 (no USDC trustline yet)",
|
|
39
|
-
fund_instructions: [
|
|
40
|
-
"1. Get testnet XLM: https://lab.stellar.org/account/fund",
|
|
41
|
-
"2. Get testnet USDC: https://faucet.circle.com (select Stellar Testnet)",
|
|
42
|
-
`3. Send USDC to: ${config.stellarPublicKey}`,
|
|
43
|
-
],
|
|
44
|
-
});
|
|
45
|
-
} catch (e: unknown) {
|
|
46
|
-
logger.error({ err: e }, "wallet tool error");
|
|
47
|
-
return err(`Failed to load account: ${String(e)}`);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
);
|
|
51
|
-
}
|
package/src/tools/weather.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import { loadOrCreateWallet } from "../lib/wallet.js";
|
|
4
|
-
import { apiFetch } from "../lib/api-fetch.js";
|
|
5
|
-
import { ok, err } from "../lib/format.js";
|
|
6
|
-
|
|
7
|
-
export function registerWeatherTool(server: McpServer): void {
|
|
8
|
-
server.registerTool(
|
|
9
|
-
"weather",
|
|
10
|
-
{
|
|
11
|
-
title: "Weather",
|
|
12
|
-
description: "Current weather and conditions for any city. Free.", inputSchema: z.object({
|
|
13
|
-
location: z.string().describe("City name (e.g. Lagos, London, New York)"),
|
|
14
|
-
}),
|
|
15
|
-
},
|
|
16
|
-
async ({ location }) => {
|
|
17
|
-
try {
|
|
18
|
-
const config = loadOrCreateWallet();
|
|
19
|
-
const res = await apiFetch(config, `/weather?location=${encodeURIComponent(location)}`);
|
|
20
|
-
if (!res.ok) return err(`Weather API error: ${res.status}`);
|
|
21
|
-
return ok(await res.json());
|
|
22
|
-
} catch (e) { return err(String(e)); }
|
|
23
|
-
}
|
|
24
|
-
);
|
|
25
|
-
}
|
package/src/tools/youtube.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import { loadOrCreateWallet } from "../lib/wallet.js";
|
|
4
|
-
import { apiFetch } from "../lib/api-fetch.js";
|
|
5
|
-
import { okPaid, err } from "../lib/format.js";
|
|
6
|
-
import { logger } from "../lib/logger.js";
|
|
7
|
-
import { TOOL_PRICES } from "../lib/config.js";
|
|
8
|
-
import { withBudget } from "../lib/budget.js";
|
|
9
|
-
import { withCache } from "../lib/cache.js";
|
|
10
|
-
|
|
11
|
-
export function registerYoutubeTool(server: McpServer): void {
|
|
12
|
-
server.registerTool(
|
|
13
|
-
"youtube",
|
|
14
|
-
{
|
|
15
|
-
title: "YouTube Search / Lookup",
|
|
16
|
-
description: `Search YouTube videos or look up a specific video by ID. Provide either query or id.\nCost: $${TOOL_PRICES.youtube} USDC per call (paid via Stellar MPP).`, inputSchema: z.object({
|
|
17
|
-
query: z.string().optional().describe("Search query to find videos"),
|
|
18
|
-
id: z.string().optional().describe("YouTube video ID for direct lookup"),
|
|
19
|
-
}),
|
|
20
|
-
},
|
|
21
|
-
async ({ query, id }) => {
|
|
22
|
-
logger.debug({ query, id }, "youtube tool invoked");
|
|
23
|
-
if (!query && !id) {
|
|
24
|
-
return err("Provide either query or id");
|
|
25
|
-
}
|
|
26
|
-
const params: Record<string, unknown> = { query, id };
|
|
27
|
-
return withCache("youtube", params, () =>
|
|
28
|
-
withBudget("youtube", async () => {
|
|
29
|
-
try {
|
|
30
|
-
const config = loadOrCreateWallet();
|
|
31
|
-
const qs = new URLSearchParams();
|
|
32
|
-
if (query) qs.set("q", query);
|
|
33
|
-
if (id) qs.set("id", id);
|
|
34
|
-
const res = await apiFetch(
|
|
35
|
-
config,
|
|
36
|
-
`/youtube?${qs.toString()}`,
|
|
37
|
-
);
|
|
38
|
-
if (!res.ok) {
|
|
39
|
-
const body = await res.text();
|
|
40
|
-
return err(`YouTube API error ${res.status}: ${body}`);
|
|
41
|
-
}
|
|
42
|
-
return okPaid(await res.json());
|
|
43
|
-
} catch (e: unknown) {
|
|
44
|
-
logger.error({ err: e }, "youtube tool error");
|
|
45
|
-
return err(`YouTube lookup failed: ${String(e)}`);
|
|
46
|
-
}
|
|
47
|
-
}),
|
|
48
|
-
);
|
|
49
|
-
},
|
|
50
|
-
);
|
|
51
|
-
}
|
package/tsconfig.json
DELETED