@t402/mcp 2.4.0 → 2.6.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.
@@ -31,25 +31,58 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var tools_exports = {};
32
32
  __export(tools_exports, {
33
33
  GASLESS_SUPPORTED_NETWORKS: () => GASLESS_SUPPORTED_NETWORKS,
34
+ TON_BRIDGE_TOOLS: () => TON_BRIDGE_TOOLS,
34
35
  TOOL_DEFINITIONS: () => TOOL_DEFINITIONS,
36
+ UNIFIED_TOOL_DEFINITIONS: () => UNIFIED_TOOL_DEFINITIONS,
37
+ WDK_TOOL_DEFINITIONS: () => WDK_TOOL_DEFINITIONS,
38
+ autoPayInputSchema: () => autoPayInputSchema,
35
39
  bridgeInputSchema: () => bridgeInputSchema,
40
+ createTonBridgeToolSet: () => createTonBridgeToolSet,
41
+ executeAutoPay: () => executeAutoPay,
42
+ executeAutoPayDemo: () => executeAutoPayDemo,
36
43
  executeBridge: () => executeBridge,
37
44
  executeGetAllBalances: () => executeGetAllBalances,
38
45
  executeGetBalance: () => executeGetBalance,
39
46
  executeGetBridgeFee: () => executeGetBridgeFee,
40
47
  executePay: () => executePay,
41
48
  executePayGasless: () => executePayGasless,
49
+ executePaymentPlan: () => executePaymentPlan,
50
+ executePaymentPlanDemo: () => executePaymentPlanDemo,
51
+ executeSmartPay: () => executeSmartPay,
52
+ executeSmartPayDemo: () => executeSmartPayDemo,
53
+ executeTonBridgeTool: () => executeTonBridgeTool,
54
+ executeWdkGetBalances: () => executeWdkGetBalances,
55
+ executeWdkGetBalancesDemo: () => executeWdkGetBalancesDemo,
56
+ executeWdkGetWallet: () => executeWdkGetWallet,
57
+ executeWdkGetWalletDemo: () => executeWdkGetWalletDemo,
58
+ executeWdkSwap: () => executeWdkSwap,
59
+ executeWdkSwapDemo: () => executeWdkSwapDemo,
60
+ executeWdkTransfer: () => executeWdkTransfer,
61
+ executeWdkTransferDemo: () => executeWdkTransferDemo,
42
62
  formatAllBalancesResult: () => formatAllBalancesResult,
63
+ formatAutoPayResult: () => formatAutoPayResult,
43
64
  formatBalanceResult: () => formatBalanceResult,
44
65
  formatBridgeFeeResult: () => formatBridgeFeeResult,
45
66
  formatBridgeResult: () => formatBridgeResult,
46
67
  formatGaslessPaymentResult: () => formatGaslessPaymentResult,
68
+ formatPaymentPlanResult: () => formatPaymentPlanResult,
47
69
  formatPaymentResult: () => formatPaymentResult,
70
+ formatSmartPayResult: () => formatSmartPayResult,
71
+ formatWdkBalancesResult: () => formatWdkBalancesResult,
72
+ formatWdkSwapResult: () => formatWdkSwapResult,
73
+ formatWdkTransferResult: () => formatWdkTransferResult,
74
+ formatWdkWalletResult: () => formatWdkWalletResult,
48
75
  getAllBalancesInputSchema: () => getAllBalancesInputSchema,
49
76
  getBalanceInputSchema: () => getBalanceInputSchema,
50
77
  getBridgeFeeInputSchema: () => getBridgeFeeInputSchema,
51
78
  payGaslessInputSchema: () => payGaslessInputSchema,
52
- payInputSchema: () => payInputSchema
79
+ payInputSchema: () => payInputSchema,
80
+ paymentPlanInputSchema: () => paymentPlanInputSchema,
81
+ smartPayInputSchema: () => smartPayInputSchema,
82
+ wdkGetBalancesInputSchema: () => wdkGetBalancesInputSchema,
83
+ wdkGetWalletInputSchema: () => wdkGetWalletInputSchema,
84
+ wdkSwapInputSchema: () => wdkSwapInputSchema,
85
+ wdkTransferInputSchema: () => wdkTransferInputSchema
53
86
  });
54
87
  module.exports = __toCommonJS(tools_exports);
55
88
 
@@ -1161,6 +1194,779 @@ function formatBridgeResult(result) {
1161
1194
  ].join("\n");
1162
1195
  }
1163
1196
 
1197
+ // src/tools/wdkGetWallet.ts
1198
+ var import_zod7 = require("zod");
1199
+ var wdkGetWalletInputSchema = import_zod7.z.object({});
1200
+ async function executeWdkGetWallet(_input, wdk) {
1201
+ const signer = await wdk.getSigner("ethereum");
1202
+ const chains6 = wdk.getConfiguredChains();
1203
+ return {
1204
+ evmAddress: signer.address,
1205
+ chains: chains6.length > 0 ? chains6 : ["ethereum"]
1206
+ };
1207
+ }
1208
+ function executeWdkGetWalletDemo() {
1209
+ return {
1210
+ evmAddress: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
1211
+ chains: ["ethereum", "arbitrum", "base", "optimism"]
1212
+ };
1213
+ }
1214
+ function formatWdkWalletResult(info) {
1215
+ const lines = [
1216
+ "## WDK Wallet Info",
1217
+ "",
1218
+ `**EVM Address:** \`${info.evmAddress}\``,
1219
+ "",
1220
+ "### Supported Chains",
1221
+ ...info.chains.map((c) => `- ${c}`)
1222
+ ];
1223
+ return lines.join("\n");
1224
+ }
1225
+
1226
+ // src/tools/wdkGetBalances.ts
1227
+ var import_zod8 = require("zod");
1228
+ var import_viem6 = require("viem");
1229
+ var wdkGetBalancesInputSchema = import_zod8.z.object({
1230
+ chains: import_zod8.z.array(import_zod8.z.string()).optional().describe("Optional list of chains to check. If not provided, checks all configured chains.")
1231
+ });
1232
+ function findTokenFormatted(tokens, symbol) {
1233
+ return tokens.find((t) => t.symbol === symbol)?.formatted ?? "0";
1234
+ }
1235
+ async function executeWdkGetBalances(input, wdk) {
1236
+ const balances = await wdk.getAggregatedBalances();
1237
+ const chains6 = balances.chains.filter((c) => !input.chains || input.chains.includes(c.chain)).map((c) => ({
1238
+ chain: c.chain,
1239
+ usdt0: findTokenFormatted(c.tokens, "USDT0"),
1240
+ usdc: findTokenFormatted(c.tokens, "USDC"),
1241
+ native: (0, import_viem6.formatUnits)(c.native, 18)
1242
+ }));
1243
+ return {
1244
+ chains: chains6,
1245
+ totalUsdt0: (0, import_viem6.formatUnits)(balances.totalUsdt0, 6),
1246
+ totalUsdc: (0, import_viem6.formatUnits)(balances.totalUsdc, 6)
1247
+ };
1248
+ }
1249
+ function executeWdkGetBalancesDemo() {
1250
+ return {
1251
+ chains: [
1252
+ { chain: "ethereum", usdt0: "100.00", usdc: "250.00", native: "0.5" },
1253
+ { chain: "arbitrum", usdt0: "500.00", usdc: "0", native: "0.01" },
1254
+ { chain: "base", usdt0: "200.00", usdc: "100.00", native: "0.02" }
1255
+ ],
1256
+ totalUsdt0: "800.00",
1257
+ totalUsdc: "350.00"
1258
+ };
1259
+ }
1260
+ function formatWdkBalancesResult(result) {
1261
+ const lines = [
1262
+ "## WDK Multi-Chain Balances",
1263
+ "",
1264
+ `**Total USDT0:** ${result.totalUsdt0}`,
1265
+ `**Total USDC:** ${result.totalUsdc}`,
1266
+ "",
1267
+ "### Per-Chain Breakdown",
1268
+ ""
1269
+ ];
1270
+ for (const chain of result.chains) {
1271
+ lines.push(`**${chain.chain}**`);
1272
+ lines.push(`- USDT0: ${chain.usdt0}`);
1273
+ lines.push(`- USDC: ${chain.usdc}`);
1274
+ lines.push(`- Native: ${chain.native}`);
1275
+ lines.push("");
1276
+ }
1277
+ return lines.join("\n");
1278
+ }
1279
+
1280
+ // src/tools/wdkTransfer.ts
1281
+ var import_zod9 = require("zod");
1282
+ var wdkTransferInputSchema = import_zod9.z.object({
1283
+ to: import_zod9.z.string().describe("Recipient address"),
1284
+ amount: import_zod9.z.string().regex(/^\d+(\.\d+)?$/).describe("Amount to send (e.g., '10.50')"),
1285
+ token: import_zod9.z.enum(["USDC", "USDT", "USDT0"]).describe("Token to transfer"),
1286
+ chain: import_zod9.z.string().describe('Chain to execute transfer on (e.g., "ethereum", "arbitrum")')
1287
+ });
1288
+ async function executeWdkTransfer(input, wdk) {
1289
+ const signer = await wdk.getSigner(input.chain);
1290
+ const result = await signer.sendTransaction({
1291
+ to: input.to
1292
+ });
1293
+ const txHash = result.hash;
1294
+ const explorerUrl = getExplorerTxUrl(input.chain, txHash);
1295
+ return {
1296
+ txHash,
1297
+ amount: input.amount,
1298
+ token: input.token,
1299
+ chain: input.chain,
1300
+ to: input.to,
1301
+ explorerUrl
1302
+ };
1303
+ }
1304
+ function executeWdkTransferDemo(input) {
1305
+ const demoTxHash = "0xdemo" + Math.random().toString(16).slice(2, 10);
1306
+ return {
1307
+ txHash: demoTxHash,
1308
+ amount: input.amount,
1309
+ token: input.token,
1310
+ chain: input.chain,
1311
+ to: input.to,
1312
+ explorerUrl: `https://etherscan.io/tx/${demoTxHash}`
1313
+ };
1314
+ }
1315
+ function formatWdkTransferResult(result) {
1316
+ return [
1317
+ "## WDK Transfer Complete",
1318
+ "",
1319
+ `**Amount:** ${result.amount} ${result.token}`,
1320
+ `**Chain:** ${result.chain}`,
1321
+ `**To:** \`${result.to}\``,
1322
+ `**Tx Hash:** \`${result.txHash}\``,
1323
+ `**Explorer:** [View Transaction](${result.explorerUrl})`
1324
+ ].join("\n");
1325
+ }
1326
+
1327
+ // src/tools/wdkSwap.ts
1328
+ var import_zod10 = require("zod");
1329
+ var import_viem7 = require("viem");
1330
+ var wdkSwapInputSchema = import_zod10.z.object({
1331
+ fromToken: import_zod10.z.string().describe('Token to swap from (e.g., "ETH", "USDC")'),
1332
+ toToken: import_zod10.z.string().describe('Token to swap to (e.g., "USDT0", "USDC")'),
1333
+ amount: import_zod10.z.string().regex(/^\d+(\.\d+)?$/).describe("Amount to swap (e.g., '1.0')"),
1334
+ chain: import_zod10.z.string().describe('Chain to execute swap on (e.g., "ethereum", "arbitrum")')
1335
+ });
1336
+ async function executeWdkSwap(input, wdk) {
1337
+ const decimals = ["USDC", "USDT", "USDT0"].includes(input.fromToken.toUpperCase()) ? 6 : 18;
1338
+ const amountBigInt = (0, import_viem7.parseUnits)(input.amount, decimals);
1339
+ const quote = await wdk.getSwapQuote(input.chain, input.fromToken, amountBigInt);
1340
+ const result = await wdk.swapAndPay({
1341
+ chain: input.chain,
1342
+ fromToken: input.fromToken,
1343
+ amount: amountBigInt
1344
+ });
1345
+ const outputDecimals = ["USDC", "USDT", "USDT0"].includes(input.toToken.toUpperCase()) ? 6 : 18;
1346
+ const toAmount = (0, import_viem7.formatUnits)(result?.outputAmount ?? quote.outputAmount, outputDecimals);
1347
+ return {
1348
+ fromAmount: input.amount,
1349
+ fromToken: input.fromToken,
1350
+ toAmount,
1351
+ toToken: input.toToken,
1352
+ chain: input.chain,
1353
+ txHash: result?.txHash
1354
+ };
1355
+ }
1356
+ function executeWdkSwapDemo(input) {
1357
+ const inputAmount = parseFloat(input.amount);
1358
+ const outputAmount = (inputAmount * 0.997).toFixed(6);
1359
+ return {
1360
+ fromAmount: input.amount,
1361
+ fromToken: input.fromToken,
1362
+ toAmount: outputAmount,
1363
+ toToken: input.toToken,
1364
+ chain: input.chain,
1365
+ txHash: "0xdemo" + Math.random().toString(16).slice(2, 10)
1366
+ };
1367
+ }
1368
+ function formatWdkSwapResult(result) {
1369
+ const lines = [
1370
+ "## WDK Swap Result",
1371
+ "",
1372
+ `**From:** ${result.fromAmount} ${result.fromToken}`,
1373
+ `**To:** ${result.toAmount} ${result.toToken}`,
1374
+ `**Chain:** ${result.chain}`
1375
+ ];
1376
+ if (result.txHash) {
1377
+ lines.push(`**Tx Hash:** \`${result.txHash}\``);
1378
+ }
1379
+ return lines.join("\n");
1380
+ }
1381
+
1382
+ // src/tools/autoPay.ts
1383
+ var import_zod11 = require("zod");
1384
+ var import_wdk_protocol = require("@t402/wdk-protocol");
1385
+ var autoPayInputSchema = import_zod11.z.object({
1386
+ url: import_zod11.z.string().url().describe("URL to fetch (may return 402 Payment Required)"),
1387
+ maxAmount: import_zod11.z.string().regex(/^\d+(\.\d+)?$/).optional().describe('Maximum amount willing to pay (e.g., "10.00"). If not set, pays any amount.'),
1388
+ preferredChain: import_zod11.z.string().optional().describe(
1389
+ 'Preferred chain for payment (e.g., "arbitrum"). If not specified, uses first available.'
1390
+ )
1391
+ });
1392
+ async function executeAutoPay(input, wdk) {
1393
+ const chains6 = input.preferredChain ? [input.preferredChain] : ["ethereum", "arbitrum", "base"];
1394
+ const protocol = await import_wdk_protocol.T402Protocol.create(wdk, { chains: chains6 });
1395
+ const { response, receipt } = await protocol.fetch(input.url);
1396
+ if (receipt && input.maxAmount) {
1397
+ const paidAmount = parseFloat(receipt.amount) / 1e6;
1398
+ const maxAmount = parseFloat(input.maxAmount);
1399
+ if (paidAmount > maxAmount) {
1400
+ return {
1401
+ success: false,
1402
+ statusCode: 402,
1403
+ body: "",
1404
+ error: `Payment amount (${paidAmount}) exceeds max allowed (${maxAmount})`
1405
+ };
1406
+ }
1407
+ }
1408
+ const contentType = response.headers.get("content-type") ?? void 0;
1409
+ let body = "";
1410
+ try {
1411
+ body = await response.text();
1412
+ if (body.length > 1e4) {
1413
+ body = body.slice(0, 1e4) + "\n... (truncated)";
1414
+ }
1415
+ } catch {
1416
+ body = "[Could not read response body]";
1417
+ }
1418
+ return {
1419
+ success: response.ok,
1420
+ statusCode: response.status,
1421
+ body,
1422
+ contentType,
1423
+ payment: receipt ? {
1424
+ network: receipt.network,
1425
+ scheme: receipt.scheme,
1426
+ amount: receipt.amount,
1427
+ payTo: receipt.payTo
1428
+ } : void 0
1429
+ };
1430
+ }
1431
+ function executeAutoPayDemo(input) {
1432
+ return {
1433
+ success: true,
1434
+ statusCode: 200,
1435
+ body: `[Demo] Premium content from ${input.url}
1436
+
1437
+ This is simulated content that would be returned after payment.`,
1438
+ contentType: "text/plain",
1439
+ payment: {
1440
+ network: "eip155:42161",
1441
+ scheme: "exact",
1442
+ amount: "1000000",
1443
+ payTo: "0xC88f67e776f16DcFBf42e6bDda1B82604448899B"
1444
+ }
1445
+ };
1446
+ }
1447
+ function formatAutoPayResult(result) {
1448
+ const lines = ["## AutoPay Result", ""];
1449
+ if (result.success) {
1450
+ lines.push(`**Status:** Success (${result.statusCode})`);
1451
+ } else {
1452
+ lines.push(`**Status:** Failed (${result.statusCode})`);
1453
+ }
1454
+ if (result.payment) {
1455
+ lines.push("");
1456
+ lines.push("### Payment Details");
1457
+ lines.push(`- **Network:** ${result.payment.network}`);
1458
+ lines.push(`- **Scheme:** ${result.payment.scheme}`);
1459
+ lines.push(`- **Amount:** ${result.payment.amount}`);
1460
+ lines.push(`- **Pay To:** \`${result.payment.payTo}\``);
1461
+ }
1462
+ if (result.error) {
1463
+ lines.push("");
1464
+ lines.push(`**Error:** ${result.error}`);
1465
+ }
1466
+ if (result.body) {
1467
+ lines.push("");
1468
+ lines.push("### Response Content");
1469
+ if (result.contentType) {
1470
+ lines.push(`_Content-Type: ${result.contentType}_`);
1471
+ }
1472
+ lines.push("");
1473
+ lines.push("```");
1474
+ lines.push(result.body);
1475
+ lines.push("```");
1476
+ }
1477
+ return lines.join("\n");
1478
+ }
1479
+
1480
+ // src/tools/ton-bridge.ts
1481
+ var TON_BRIDGE_TOOLS = {
1482
+ "ton/getBalance": {
1483
+ name: "ton/getBalance",
1484
+ description: "Get TON and Jetton balances for a wallet address on the TON blockchain.",
1485
+ inputSchema: {
1486
+ type: "object",
1487
+ properties: {
1488
+ address: {
1489
+ type: "string",
1490
+ description: "TON wallet address (friendly or raw format)"
1491
+ }
1492
+ },
1493
+ required: ["address"]
1494
+ }
1495
+ },
1496
+ "ton/transfer": {
1497
+ name: "ton/transfer",
1498
+ description: "Send TON to a recipient address on the TON blockchain.",
1499
+ inputSchema: {
1500
+ type: "object",
1501
+ properties: {
1502
+ to: {
1503
+ type: "string",
1504
+ description: "Recipient TON address"
1505
+ },
1506
+ amount: {
1507
+ type: "string",
1508
+ description: 'Amount of TON to send (e.g., "1.5")'
1509
+ },
1510
+ memo: {
1511
+ type: "string",
1512
+ description: "Optional memo/comment for the transfer"
1513
+ }
1514
+ },
1515
+ required: ["to", "amount"]
1516
+ }
1517
+ },
1518
+ "ton/getJettonBalance": {
1519
+ name: "ton/getJettonBalance",
1520
+ description: "Get the balance of a specific Jetton (TON token) for a wallet address.",
1521
+ inputSchema: {
1522
+ type: "object",
1523
+ properties: {
1524
+ address: {
1525
+ type: "string",
1526
+ description: "TON wallet address"
1527
+ },
1528
+ jettonMaster: {
1529
+ type: "string",
1530
+ description: "Jetton master contract address"
1531
+ }
1532
+ },
1533
+ required: ["address", "jettonMaster"]
1534
+ }
1535
+ },
1536
+ "ton/swapJettons": {
1537
+ name: "ton/swapJettons",
1538
+ description: "Swap Jettons (TON tokens) using DEX aggregation on the TON network. Returns a raw transaction JSON to be sent via sendTransaction.",
1539
+ inputSchema: {
1540
+ type: "object",
1541
+ properties: {
1542
+ from: {
1543
+ type: "string",
1544
+ description: 'Source Jetton master address (or "TON" for native TON)'
1545
+ },
1546
+ to: {
1547
+ type: "string",
1548
+ description: 'Destination Jetton master address (or "TON" for native TON)'
1549
+ },
1550
+ amount: {
1551
+ type: "string",
1552
+ description: 'Amount to swap in human-readable format (e.g., "1.5")'
1553
+ },
1554
+ slippage: {
1555
+ type: "string",
1556
+ description: 'Slippage tolerance (e.g., "0.5" for 0.5%)'
1557
+ }
1558
+ },
1559
+ required: ["from", "to", "amount"]
1560
+ }
1561
+ },
1562
+ "ton/getTransactionStatus": {
1563
+ name: "ton/getTransactionStatus",
1564
+ description: "Check the status and details of a TON transaction by its hash.",
1565
+ inputSchema: {
1566
+ type: "object",
1567
+ properties: {
1568
+ txHash: {
1569
+ type: "string",
1570
+ description: "Transaction hash (BOC hash or message hash)"
1571
+ }
1572
+ },
1573
+ required: ["txHash"]
1574
+ }
1575
+ }
1576
+ };
1577
+ async function executeTonBridgeTool(toolName, args, config) {
1578
+ if (config.demoMode) {
1579
+ return executeTonBridgeToolDemo(toolName, args);
1580
+ }
1581
+ if (config.tonMcpEndpoint) {
1582
+ return proxyToTonMcp(toolName, args, config.tonMcpEndpoint);
1583
+ }
1584
+ if (config.tonApiKey) {
1585
+ return executeTonBridgeToolDirect(toolName, args, config.tonApiKey);
1586
+ }
1587
+ return {
1588
+ content: [
1589
+ {
1590
+ type: "text",
1591
+ text: `Error: TON MCP bridge not configured. Set tonMcpEndpoint or tonApiKey.`
1592
+ }
1593
+ ],
1594
+ isError: true
1595
+ };
1596
+ }
1597
+ function executeTonBridgeToolDemo(toolName, args) {
1598
+ const responses = {
1599
+ "ton/getBalance": `[DEMO] TON Balance for ${args.address ?? "unknown"}:
1600
+ - TON: 5.25
1601
+ - USDT0: 100.00`,
1602
+ "ton/transfer": `[DEMO] Transfer sent:
1603
+ - To: ${args.to ?? "unknown"}
1604
+ - Amount: ${args.amount ?? "0"} TON
1605
+ - TX: demo-ton-tx-hash-${Date.now().toString(36)}`,
1606
+ "ton/getJettonBalance": `[DEMO] Jetton Balance:
1607
+ - Address: ${args.address ?? "unknown"}
1608
+ - Jetton: ${args.jettonMaster ?? "unknown"}
1609
+ - Balance: 50.00`,
1610
+ "ton/swapJettons": `[DEMO] Swap quote received:
1611
+ - From: ${args.from ?? "unknown"}
1612
+ - To: ${args.to ?? "unknown"}
1613
+ - Amount: ${args.amount ?? "0"}
1614
+ - Transaction: {"validUntil":${Math.floor(Date.now() / 1e3) + 300},"messages":[{"address":"EQDemo...","amount":"${args.amount ?? "0"}","payload":"base64..."}]}`,
1615
+ "ton/getTransactionStatus": `[DEMO] Transaction Status:
1616
+ - Hash: ${args.txHash ?? "unknown"}
1617
+ - Status: Confirmed
1618
+ - Block: 12345678`
1619
+ };
1620
+ return {
1621
+ content: [
1622
+ {
1623
+ type: "text",
1624
+ text: responses[toolName] ?? `[DEMO] Unknown TON tool: ${toolName}`
1625
+ }
1626
+ ]
1627
+ };
1628
+ }
1629
+ async function proxyToTonMcp(toolName, args, endpoint) {
1630
+ try {
1631
+ const response = await fetch(endpoint, {
1632
+ method: "POST",
1633
+ headers: { "Content-Type": "application/json" },
1634
+ body: JSON.stringify({
1635
+ jsonrpc: "2.0",
1636
+ id: 1,
1637
+ method: "tools/call",
1638
+ params: { name: toolName, arguments: args }
1639
+ })
1640
+ });
1641
+ if (!response.ok) {
1642
+ throw new Error(`TON MCP server returned ${response.status}`);
1643
+ }
1644
+ const result = await response.json();
1645
+ if (result.error) {
1646
+ throw new Error(result.error.message);
1647
+ }
1648
+ return result.result ?? { content: [{ type: "text", text: "No result" }] };
1649
+ } catch (error) {
1650
+ const message = error instanceof Error ? error.message : String(error);
1651
+ return {
1652
+ content: [{ type: "text", text: `Error proxying to @ton/mcp: ${message}` }],
1653
+ isError: true
1654
+ };
1655
+ }
1656
+ }
1657
+ async function executeTonBridgeToolDirect(toolName, args, apiKey) {
1658
+ const baseUrl = "https://toncenter.com/api/v2";
1659
+ try {
1660
+ switch (toolName) {
1661
+ case "ton/getBalance": {
1662
+ const response = await fetch(
1663
+ `${baseUrl}/getAddressBalance?address=${encodeURIComponent(String(args.address))}&api_key=${apiKey}`
1664
+ );
1665
+ const data = await response.json();
1666
+ const balanceNano = BigInt(data.result);
1667
+ const balanceTon = Number(balanceNano) / 1e9;
1668
+ return {
1669
+ content: [{ type: "text", text: `TON Balance: ${balanceTon.toFixed(4)} TON` }]
1670
+ };
1671
+ }
1672
+ case "ton/getTransactionStatus": {
1673
+ const response = await fetch(
1674
+ `${baseUrl}/getTransactions?hash=${encodeURIComponent(String(args.txHash))}&limit=1&api_key=${apiKey}`
1675
+ );
1676
+ const data = await response.json();
1677
+ if (data.result.length === 0) {
1678
+ return {
1679
+ content: [{ type: "text", text: "Transaction not found" }]
1680
+ };
1681
+ }
1682
+ return {
1683
+ content: [
1684
+ {
1685
+ type: "text",
1686
+ text: `Transaction found:
1687
+ ${JSON.stringify(data.result[0], null, 2)}`
1688
+ }
1689
+ ]
1690
+ };
1691
+ }
1692
+ default:
1693
+ return {
1694
+ content: [
1695
+ {
1696
+ type: "text",
1697
+ text: `Direct execution of ${toolName} is not supported. Configure tonMcpEndpoint to proxy to @ton/mcp.`
1698
+ }
1699
+ ],
1700
+ isError: true
1701
+ };
1702
+ }
1703
+ } catch (error) {
1704
+ const message = error instanceof Error ? error.message : String(error);
1705
+ return {
1706
+ content: [{ type: "text", text: `Error executing TON API call: ${message}` }],
1707
+ isError: true
1708
+ };
1709
+ }
1710
+ }
1711
+ function createTonBridgeToolSet(config) {
1712
+ return {
1713
+ definitions: TON_BRIDGE_TOOLS,
1714
+ async handleToolCall(name, args) {
1715
+ return executeTonBridgeTool(name, args, config);
1716
+ }
1717
+ };
1718
+ }
1719
+
1720
+ // src/tools/unified.ts
1721
+ var import_zod12 = require("zod");
1722
+ var import_wdk_protocol2 = require("@t402/wdk-protocol");
1723
+ var smartPayInputSchema = import_zod12.z.object({
1724
+ url: import_zod12.z.string().url().describe("URL of the 402-protected resource"),
1725
+ maxBridgeFee: import_zod12.z.string().regex(/^\d+(\.\d+)?$/).optional().describe("Maximum acceptable bridge fee in native token (optional)"),
1726
+ preferredNetwork: import_zod12.z.string().optional().describe("Preferred network for payment (optional)")
1727
+ });
1728
+ var paymentPlanInputSchema = import_zod12.z.object({
1729
+ paymentRequired: import_zod12.z.object({
1730
+ scheme: import_zod12.z.string().optional(),
1731
+ network: import_zod12.z.string().optional(),
1732
+ maxAmountRequired: import_zod12.z.string().optional(),
1733
+ resource: import_zod12.z.string().optional(),
1734
+ description: import_zod12.z.string().optional(),
1735
+ payTo: import_zod12.z.string().optional(),
1736
+ maxDeadline: import_zod12.z.number().optional()
1737
+ }).passthrough().describe("The 402 PaymentRequired response")
1738
+ });
1739
+ var UNIFIED_TOOL_DEFINITIONS = {
1740
+ "t402/smartPay": {
1741
+ name: "t402/smartPay",
1742
+ description: "Intelligent payment that automatically checks balance, bridges if needed, and pays. Handles the entire payment flow for 402-protected resources.",
1743
+ inputSchema: {
1744
+ type: "object",
1745
+ properties: {
1746
+ url: { type: "string", description: "URL of the 402-protected resource" },
1747
+ maxBridgeFee: {
1748
+ type: "string",
1749
+ description: "Maximum acceptable bridge fee in native token (optional)"
1750
+ },
1751
+ preferredNetwork: {
1752
+ type: "string",
1753
+ description: "Preferred network for payment (optional)"
1754
+ }
1755
+ },
1756
+ required: ["url"]
1757
+ }
1758
+ },
1759
+ "t402/paymentPlan": {
1760
+ name: "t402/paymentPlan",
1761
+ description: "Analyze a 402 response and create an optimal payment plan considering balances across all chains. Returns recommended network, bridge requirements, and balance overview.",
1762
+ inputSchema: {
1763
+ type: "object",
1764
+ properties: {
1765
+ paymentRequired: {
1766
+ type: "object",
1767
+ description: "The 402 PaymentRequired response"
1768
+ }
1769
+ },
1770
+ required: ["paymentRequired"]
1771
+ }
1772
+ }
1773
+ };
1774
+ async function executeSmartPay(input, wdk) {
1775
+ const steps = [];
1776
+ const chains6 = input.preferredNetwork ? [input.preferredNetwork] : ["ethereum", "arbitrum", "base"];
1777
+ steps.push({
1778
+ action: "check_balance",
1779
+ status: "success",
1780
+ detail: `Checking balances on ${chains6.join(", ")}`
1781
+ });
1782
+ const protocol = await import_wdk_protocol2.T402Protocol.create(wdk, { chains: chains6 });
1783
+ steps.push({
1784
+ action: "fetch",
1785
+ status: "success",
1786
+ detail: `Fetching ${input.url}`
1787
+ });
1788
+ const { response, receipt } = await protocol.fetch(input.url);
1789
+ if (receipt) {
1790
+ steps.push({
1791
+ action: "pay",
1792
+ status: "success",
1793
+ detail: `Payment made: ${receipt.amount} on ${receipt.network}`
1794
+ });
1795
+ }
1796
+ const contentType = response.headers.get("content-type") ?? void 0;
1797
+ let body = "";
1798
+ try {
1799
+ body = await response.text();
1800
+ if (body.length > 1e4) {
1801
+ body = body.slice(0, 1e4) + "\n... (truncated)";
1802
+ }
1803
+ } catch {
1804
+ body = "[Could not read response body]";
1805
+ }
1806
+ return {
1807
+ success: response.ok,
1808
+ statusCode: response.status,
1809
+ body,
1810
+ contentType,
1811
+ steps,
1812
+ payment: receipt ? {
1813
+ network: receipt.network,
1814
+ scheme: receipt.scheme,
1815
+ amount: receipt.amount,
1816
+ payTo: receipt.payTo
1817
+ } : void 0
1818
+ };
1819
+ }
1820
+ function executeSmartPayDemo(input) {
1821
+ const network = input.preferredNetwork ?? "arbitrum";
1822
+ return {
1823
+ success: true,
1824
+ statusCode: 200,
1825
+ body: `[Demo] Premium content from ${input.url}
1826
+
1827
+ This is simulated content returned after smart payment.`,
1828
+ contentType: "text/plain",
1829
+ steps: [
1830
+ { action: "check_balance", status: "success", detail: `Checked balances on ${network}` },
1831
+ { action: "check_price", status: "success", detail: "Resource costs 1.00 USDT0" },
1832
+ { action: "pay", status: "success", detail: `Paid 1000000 USDT0 on eip155:42161` },
1833
+ { action: "fetch", status: "success", detail: `Fetched ${input.url}` }
1834
+ ],
1835
+ payment: {
1836
+ network: "eip155:42161",
1837
+ scheme: "exact",
1838
+ amount: "1000000",
1839
+ payTo: "0xC88f67e776f16DcFBf42e6bDda1B82604448899B"
1840
+ }
1841
+ };
1842
+ }
1843
+ async function executePaymentPlan(input, wdk) {
1844
+ const targetNetwork = input.paymentRequired.network;
1845
+ const requiredAmount = input.paymentRequired.maxAmountRequired;
1846
+ const aggregated = await wdk.getAggregatedBalances();
1847
+ const balances = aggregated.chains.map((chain) => {
1848
+ const usdt0 = chain.tokens.find((t) => t.symbol === "USDT0");
1849
+ const usdc = chain.tokens.find((t) => t.symbol === "USDC");
1850
+ return {
1851
+ chain: chain.chain,
1852
+ usdt0: usdt0?.formatted ?? "0",
1853
+ usdc: usdc?.formatted ?? "0"
1854
+ };
1855
+ });
1856
+ const requiredBigint = requiredAmount ? BigInt(requiredAmount) : 0n;
1857
+ const bestChain = await wdk.findBestChainForPayment(requiredBigint);
1858
+ if (bestChain) {
1859
+ const needsBridge = targetNetwork ? !bestChain.chain.includes(targetNetwork) : false;
1860
+ return {
1861
+ viable: true,
1862
+ recommendedNetwork: bestChain.chain,
1863
+ availableBalance: bestChain.balance.toString(),
1864
+ bridgeRequired: needsBridge,
1865
+ bridgeDetails: needsBridge ? {
1866
+ fromChain: bestChain.chain,
1867
+ toChain: targetNetwork ?? bestChain.chain,
1868
+ amount: requiredAmount ?? "0",
1869
+ estimatedFee: "0.001"
1870
+ } : void 0,
1871
+ balances
1872
+ };
1873
+ }
1874
+ return {
1875
+ viable: false,
1876
+ bridgeRequired: false,
1877
+ balances,
1878
+ reason: "Insufficient balance across all chains"
1879
+ };
1880
+ }
1881
+ function executePaymentPlanDemo(_input) {
1882
+ return {
1883
+ viable: true,
1884
+ recommendedNetwork: "arbitrum",
1885
+ availableBalance: "500000000",
1886
+ bridgeRequired: false,
1887
+ balances: [
1888
+ { chain: "ethereum", usdt0: "100.00", usdc: "250.00" },
1889
+ { chain: "arbitrum", usdt0: "500.00", usdc: "0" },
1890
+ { chain: "base", usdt0: "50.00", usdc: "100.00" }
1891
+ ]
1892
+ };
1893
+ }
1894
+ function formatSmartPayResult(result) {
1895
+ const lines = ["## SmartPay Result", ""];
1896
+ if (result.success) {
1897
+ lines.push(`**Status:** Success (${result.statusCode})`);
1898
+ } else {
1899
+ lines.push(`**Status:** Failed (${result.statusCode})`);
1900
+ }
1901
+ if (result.steps.length > 0) {
1902
+ lines.push("");
1903
+ lines.push("### Steps");
1904
+ for (const step of result.steps) {
1905
+ const icon = step.status === "success" ? "[OK]" : step.status === "skipped" ? "[SKIP]" : "[FAIL]";
1906
+ lines.push(`- ${icon} **${step.action}**: ${step.detail}`);
1907
+ }
1908
+ }
1909
+ if (result.payment) {
1910
+ lines.push("");
1911
+ lines.push("### Payment Details");
1912
+ lines.push(`- **Network:** ${result.payment.network}`);
1913
+ lines.push(`- **Scheme:** ${result.payment.scheme}`);
1914
+ lines.push(`- **Amount:** ${result.payment.amount}`);
1915
+ lines.push(`- **Pay To:** \`${result.payment.payTo}\``);
1916
+ }
1917
+ if (result.error) {
1918
+ lines.push("");
1919
+ lines.push(`**Error:** ${result.error}`);
1920
+ }
1921
+ if (result.body) {
1922
+ lines.push("");
1923
+ lines.push("### Response Content");
1924
+ if (result.contentType) {
1925
+ lines.push(`_Content-Type: ${result.contentType}_`);
1926
+ }
1927
+ lines.push("");
1928
+ lines.push("```");
1929
+ lines.push(result.body);
1930
+ lines.push("```");
1931
+ }
1932
+ return lines.join("\n");
1933
+ }
1934
+ function formatPaymentPlanResult(result) {
1935
+ const lines = ["## Payment Plan", ""];
1936
+ if (result.viable) {
1937
+ lines.push(`**Viable:** Yes`);
1938
+ if (result.recommendedNetwork) {
1939
+ lines.push(`**Recommended Network:** ${result.recommendedNetwork}`);
1940
+ }
1941
+ if (result.availableBalance) {
1942
+ lines.push(`**Available Balance:** ${result.availableBalance}`);
1943
+ }
1944
+ } else {
1945
+ lines.push(`**Viable:** No`);
1946
+ if (result.reason) {
1947
+ lines.push(`**Reason:** ${result.reason}`);
1948
+ }
1949
+ }
1950
+ if (result.bridgeRequired && result.bridgeDetails) {
1951
+ lines.push("");
1952
+ lines.push("### Bridge Required");
1953
+ lines.push(`- **From:** ${result.bridgeDetails.fromChain}`);
1954
+ lines.push(`- **To:** ${result.bridgeDetails.toChain}`);
1955
+ lines.push(`- **Amount:** ${result.bridgeDetails.amount}`);
1956
+ lines.push(`- **Estimated Fee:** ${result.bridgeDetails.estimatedFee}`);
1957
+ }
1958
+ if (result.balances.length > 0) {
1959
+ lines.push("");
1960
+ lines.push("### Chain Balances");
1961
+ lines.push("| Chain | USDT0 | USDC |");
1962
+ lines.push("|-------|-------|------|");
1963
+ for (const b of result.balances) {
1964
+ lines.push(`| ${b.chain} | ${b.usdt0} | ${b.usdc} |`);
1965
+ }
1966
+ }
1967
+ return lines.join("\n");
1968
+ }
1969
+
1164
1970
  // src/tools/index.ts
1165
1971
  var TOOL_DEFINITIONS = {
1166
1972
  "t402/getBalance": {
@@ -1361,27 +2167,164 @@ var TOOL_DEFINITIONS = {
1361
2167
  }
1362
2168
  }
1363
2169
  };
2170
+ var WDK_TOOL_DEFINITIONS = {
2171
+ "wdk/getWallet": {
2172
+ name: "wdk/getWallet",
2173
+ description: "Get wallet information from the configured WDK wallet. Returns EVM address and supported chains. No parameters needed.",
2174
+ inputSchema: {
2175
+ type: "object",
2176
+ properties: {},
2177
+ required: []
2178
+ }
2179
+ },
2180
+ "wdk/getBalances": {
2181
+ name: "wdk/getBalances",
2182
+ description: "Get multi-chain token balances from the WDK wallet. Returns USDT0, USDC, and native token balances per chain plus aggregated totals.",
2183
+ inputSchema: {
2184
+ type: "object",
2185
+ properties: {
2186
+ chains: {
2187
+ type: "array",
2188
+ items: { type: "string" },
2189
+ description: 'Optional list of chains to check (e.g., ["ethereum", "arbitrum"]). If not provided, checks all configured chains.'
2190
+ }
2191
+ },
2192
+ required: []
2193
+ }
2194
+ },
2195
+ "wdk/transfer": {
2196
+ name: "wdk/transfer",
2197
+ description: "Send stablecoins (USDC, USDT, USDT0) from the WDK wallet to a recipient address on a specific chain.",
2198
+ inputSchema: {
2199
+ type: "object",
2200
+ properties: {
2201
+ to: {
2202
+ type: "string",
2203
+ description: "Recipient address"
2204
+ },
2205
+ amount: {
2206
+ type: "string",
2207
+ pattern: "^\\d+(\\.\\d+)?$",
2208
+ description: "Amount to send (e.g., '10.50')"
2209
+ },
2210
+ token: {
2211
+ type: "string",
2212
+ enum: ["USDC", "USDT", "USDT0"],
2213
+ description: "Token to transfer"
2214
+ },
2215
+ chain: {
2216
+ type: "string",
2217
+ description: 'Chain to execute transfer on (e.g., "ethereum", "arbitrum")'
2218
+ }
2219
+ },
2220
+ required: ["to", "amount", "token", "chain"]
2221
+ }
2222
+ },
2223
+ "wdk/swap": {
2224
+ name: "wdk/swap",
2225
+ description: "Swap tokens using the WDK Velora protocol. Supports swapping between stablecoins and native tokens.",
2226
+ inputSchema: {
2227
+ type: "object",
2228
+ properties: {
2229
+ fromToken: {
2230
+ type: "string",
2231
+ description: 'Token to swap from (e.g., "ETH", "USDC")'
2232
+ },
2233
+ toToken: {
2234
+ type: "string",
2235
+ description: 'Token to swap to (e.g., "USDT0", "USDC")'
2236
+ },
2237
+ amount: {
2238
+ type: "string",
2239
+ pattern: "^\\d+(\\.\\d+)?$",
2240
+ description: "Amount to swap (e.g., '1.0')"
2241
+ },
2242
+ chain: {
2243
+ type: "string",
2244
+ description: 'Chain to execute swap on (e.g., "ethereum", "arbitrum")'
2245
+ }
2246
+ },
2247
+ required: ["fromToken", "toToken", "amount", "chain"]
2248
+ }
2249
+ },
2250
+ "t402/autoPay": {
2251
+ name: "t402/autoPay",
2252
+ description: "Smart payment orchestrator. Fetches a URL, automatically handles HTTP 402 Payment Required responses by signing and submitting payment using the WDK wallet, and returns the paid content. The killer tool for AI agents.",
2253
+ inputSchema: {
2254
+ type: "object",
2255
+ properties: {
2256
+ url: {
2257
+ type: "string",
2258
+ description: "URL to fetch (may return 402 Payment Required)"
2259
+ },
2260
+ maxAmount: {
2261
+ type: "string",
2262
+ pattern: "^\\d+(\\.\\d+)?$",
2263
+ description: 'Maximum amount willing to pay (e.g., "10.00"). If not set, pays any amount.'
2264
+ },
2265
+ preferredChain: {
2266
+ type: "string",
2267
+ description: 'Preferred chain for payment (e.g., "arbitrum"). If not specified, uses first available.'
2268
+ }
2269
+ },
2270
+ required: ["url"]
2271
+ }
2272
+ }
2273
+ };
1364
2274
  // Annotate the CommonJS export names for ESM import in node:
1365
2275
  0 && (module.exports = {
1366
2276
  GASLESS_SUPPORTED_NETWORKS,
2277
+ TON_BRIDGE_TOOLS,
1367
2278
  TOOL_DEFINITIONS,
2279
+ UNIFIED_TOOL_DEFINITIONS,
2280
+ WDK_TOOL_DEFINITIONS,
2281
+ autoPayInputSchema,
1368
2282
  bridgeInputSchema,
2283
+ createTonBridgeToolSet,
2284
+ executeAutoPay,
2285
+ executeAutoPayDemo,
1369
2286
  executeBridge,
1370
2287
  executeGetAllBalances,
1371
2288
  executeGetBalance,
1372
2289
  executeGetBridgeFee,
1373
2290
  executePay,
1374
2291
  executePayGasless,
2292
+ executePaymentPlan,
2293
+ executePaymentPlanDemo,
2294
+ executeSmartPay,
2295
+ executeSmartPayDemo,
2296
+ executeTonBridgeTool,
2297
+ executeWdkGetBalances,
2298
+ executeWdkGetBalancesDemo,
2299
+ executeWdkGetWallet,
2300
+ executeWdkGetWalletDemo,
2301
+ executeWdkSwap,
2302
+ executeWdkSwapDemo,
2303
+ executeWdkTransfer,
2304
+ executeWdkTransferDemo,
1375
2305
  formatAllBalancesResult,
2306
+ formatAutoPayResult,
1376
2307
  formatBalanceResult,
1377
2308
  formatBridgeFeeResult,
1378
2309
  formatBridgeResult,
1379
2310
  formatGaslessPaymentResult,
2311
+ formatPaymentPlanResult,
1380
2312
  formatPaymentResult,
2313
+ formatSmartPayResult,
2314
+ formatWdkBalancesResult,
2315
+ formatWdkSwapResult,
2316
+ formatWdkTransferResult,
2317
+ formatWdkWalletResult,
1381
2318
  getAllBalancesInputSchema,
1382
2319
  getBalanceInputSchema,
1383
2320
  getBridgeFeeInputSchema,
1384
2321
  payGaslessInputSchema,
1385
- payInputSchema
2322
+ payInputSchema,
2323
+ paymentPlanInputSchema,
2324
+ smartPayInputSchema,
2325
+ wdkGetBalancesInputSchema,
2326
+ wdkGetWalletInputSchema,
2327
+ wdkSwapInputSchema,
2328
+ wdkTransferInputSchema
1386
2329
  });
1387
2330
  //# sourceMappingURL=index.js.map