@t402/mcp 2.5.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.
@@ -1,4 +1,4 @@
1
- import { M as McpServerConfig } from '../types-CwwW_c2B.js';
1
+ import { M as McpServerConfig, e as TonMcpBridgeConfig } from '../ton-bridge-BN3RKhNy.js';
2
2
  import 'viem';
3
3
 
4
4
  /**
@@ -20,8 +20,16 @@ declare class T402McpServer {
20
20
  * Initialize the WDK instance from seed phrase
21
21
  */
22
22
  initWdk(): Promise<void>;
23
+ /** TON MCP bridge configuration */
24
+ private tonBridgeConfig;
23
25
  /**
24
- * Get all tool definitions (base + WDK if configured)
26
+ * Register TON bridge tools
27
+ *
28
+ * Enables AI agents to use @ton/mcp tools through the t402 MCP server.
29
+ */
30
+ registerTonBridge(config: TonMcpBridgeConfig): void;
31
+ /**
32
+ * Get all tool definitions (base + WDK if configured + unified if enabled + TON bridge if registered)
25
33
  */
26
34
  private getToolDefinitions;
27
35
  /**
@@ -72,6 +80,18 @@ declare class T402McpServer {
72
80
  * Handle t402/autoPay
73
81
  */
74
82
  private handleAutoPay;
83
+ /**
84
+ * Handle t402/smartPay
85
+ */
86
+ private handleSmartPay;
87
+ /**
88
+ * Handle t402/paymentPlan
89
+ */
90
+ private handlePaymentPlan;
91
+ /**
92
+ * Handle TON bridge tool calls
93
+ */
94
+ private handleTonBridgeTool;
75
95
  /**
76
96
  * Start the server using stdio transport
77
97
  */
@@ -1434,6 +1434,488 @@ function formatAutoPayResult(result) {
1434
1434
  return lines.join("\n");
1435
1435
  }
1436
1436
 
1437
+ // src/tools/ton-bridge.ts
1438
+ var TON_BRIDGE_TOOLS = {
1439
+ "ton/getBalance": {
1440
+ name: "ton/getBalance",
1441
+ description: "Get TON and Jetton balances for a wallet address on the TON blockchain.",
1442
+ inputSchema: {
1443
+ type: "object",
1444
+ properties: {
1445
+ address: {
1446
+ type: "string",
1447
+ description: "TON wallet address (friendly or raw format)"
1448
+ }
1449
+ },
1450
+ required: ["address"]
1451
+ }
1452
+ },
1453
+ "ton/transfer": {
1454
+ name: "ton/transfer",
1455
+ description: "Send TON to a recipient address on the TON blockchain.",
1456
+ inputSchema: {
1457
+ type: "object",
1458
+ properties: {
1459
+ to: {
1460
+ type: "string",
1461
+ description: "Recipient TON address"
1462
+ },
1463
+ amount: {
1464
+ type: "string",
1465
+ description: 'Amount of TON to send (e.g., "1.5")'
1466
+ },
1467
+ memo: {
1468
+ type: "string",
1469
+ description: "Optional memo/comment for the transfer"
1470
+ }
1471
+ },
1472
+ required: ["to", "amount"]
1473
+ }
1474
+ },
1475
+ "ton/getJettonBalance": {
1476
+ name: "ton/getJettonBalance",
1477
+ description: "Get the balance of a specific Jetton (TON token) for a wallet address.",
1478
+ inputSchema: {
1479
+ type: "object",
1480
+ properties: {
1481
+ address: {
1482
+ type: "string",
1483
+ description: "TON wallet address"
1484
+ },
1485
+ jettonMaster: {
1486
+ type: "string",
1487
+ description: "Jetton master contract address"
1488
+ }
1489
+ },
1490
+ required: ["address", "jettonMaster"]
1491
+ }
1492
+ },
1493
+ "ton/swapJettons": {
1494
+ name: "ton/swapJettons",
1495
+ description: "Swap Jettons (TON tokens) using DEX aggregation on the TON network. Returns a raw transaction JSON to be sent via sendTransaction.",
1496
+ inputSchema: {
1497
+ type: "object",
1498
+ properties: {
1499
+ from: {
1500
+ type: "string",
1501
+ description: 'Source Jetton master address (or "TON" for native TON)'
1502
+ },
1503
+ to: {
1504
+ type: "string",
1505
+ description: 'Destination Jetton master address (or "TON" for native TON)'
1506
+ },
1507
+ amount: {
1508
+ type: "string",
1509
+ description: 'Amount to swap in human-readable format (e.g., "1.5")'
1510
+ },
1511
+ slippage: {
1512
+ type: "string",
1513
+ description: 'Slippage tolerance (e.g., "0.5" for 0.5%)'
1514
+ }
1515
+ },
1516
+ required: ["from", "to", "amount"]
1517
+ }
1518
+ },
1519
+ "ton/getTransactionStatus": {
1520
+ name: "ton/getTransactionStatus",
1521
+ description: "Check the status and details of a TON transaction by its hash.",
1522
+ inputSchema: {
1523
+ type: "object",
1524
+ properties: {
1525
+ txHash: {
1526
+ type: "string",
1527
+ description: "Transaction hash (BOC hash or message hash)"
1528
+ }
1529
+ },
1530
+ required: ["txHash"]
1531
+ }
1532
+ }
1533
+ };
1534
+ async function executeTonBridgeTool(toolName, args, config) {
1535
+ if (config.demoMode) {
1536
+ return executeTonBridgeToolDemo(toolName, args);
1537
+ }
1538
+ if (config.tonMcpEndpoint) {
1539
+ return proxyToTonMcp(toolName, args, config.tonMcpEndpoint);
1540
+ }
1541
+ if (config.tonApiKey) {
1542
+ return executeTonBridgeToolDirect(toolName, args, config.tonApiKey);
1543
+ }
1544
+ return {
1545
+ content: [
1546
+ {
1547
+ type: "text",
1548
+ text: `Error: TON MCP bridge not configured. Set tonMcpEndpoint or tonApiKey.`
1549
+ }
1550
+ ],
1551
+ isError: true
1552
+ };
1553
+ }
1554
+ function executeTonBridgeToolDemo(toolName, args) {
1555
+ const responses = {
1556
+ "ton/getBalance": `[DEMO] TON Balance for ${args.address ?? "unknown"}:
1557
+ - TON: 5.25
1558
+ - USDT0: 100.00`,
1559
+ "ton/transfer": `[DEMO] Transfer sent:
1560
+ - To: ${args.to ?? "unknown"}
1561
+ - Amount: ${args.amount ?? "0"} TON
1562
+ - TX: demo-ton-tx-hash-${Date.now().toString(36)}`,
1563
+ "ton/getJettonBalance": `[DEMO] Jetton Balance:
1564
+ - Address: ${args.address ?? "unknown"}
1565
+ - Jetton: ${args.jettonMaster ?? "unknown"}
1566
+ - Balance: 50.00`,
1567
+ "ton/swapJettons": `[DEMO] Swap quote received:
1568
+ - From: ${args.from ?? "unknown"}
1569
+ - To: ${args.to ?? "unknown"}
1570
+ - Amount: ${args.amount ?? "0"}
1571
+ - Transaction: {"validUntil":${Math.floor(Date.now() / 1e3) + 300},"messages":[{"address":"EQDemo...","amount":"${args.amount ?? "0"}","payload":"base64..."}]}`,
1572
+ "ton/getTransactionStatus": `[DEMO] Transaction Status:
1573
+ - Hash: ${args.txHash ?? "unknown"}
1574
+ - Status: Confirmed
1575
+ - Block: 12345678`
1576
+ };
1577
+ return {
1578
+ content: [
1579
+ {
1580
+ type: "text",
1581
+ text: responses[toolName] ?? `[DEMO] Unknown TON tool: ${toolName}`
1582
+ }
1583
+ ]
1584
+ };
1585
+ }
1586
+ async function proxyToTonMcp(toolName, args, endpoint) {
1587
+ try {
1588
+ const response = await fetch(endpoint, {
1589
+ method: "POST",
1590
+ headers: { "Content-Type": "application/json" },
1591
+ body: JSON.stringify({
1592
+ jsonrpc: "2.0",
1593
+ id: 1,
1594
+ method: "tools/call",
1595
+ params: { name: toolName, arguments: args }
1596
+ })
1597
+ });
1598
+ if (!response.ok) {
1599
+ throw new Error(`TON MCP server returned ${response.status}`);
1600
+ }
1601
+ const result = await response.json();
1602
+ if (result.error) {
1603
+ throw new Error(result.error.message);
1604
+ }
1605
+ return result.result ?? { content: [{ type: "text", text: "No result" }] };
1606
+ } catch (error) {
1607
+ const message = error instanceof Error ? error.message : String(error);
1608
+ return {
1609
+ content: [{ type: "text", text: `Error proxying to @ton/mcp: ${message}` }],
1610
+ isError: true
1611
+ };
1612
+ }
1613
+ }
1614
+ async function executeTonBridgeToolDirect(toolName, args, apiKey) {
1615
+ const baseUrl = "https://toncenter.com/api/v2";
1616
+ try {
1617
+ switch (toolName) {
1618
+ case "ton/getBalance": {
1619
+ const response = await fetch(
1620
+ `${baseUrl}/getAddressBalance?address=${encodeURIComponent(String(args.address))}&api_key=${apiKey}`
1621
+ );
1622
+ const data = await response.json();
1623
+ const balanceNano = BigInt(data.result);
1624
+ const balanceTon = Number(balanceNano) / 1e9;
1625
+ return {
1626
+ content: [{ type: "text", text: `TON Balance: ${balanceTon.toFixed(4)} TON` }]
1627
+ };
1628
+ }
1629
+ case "ton/getTransactionStatus": {
1630
+ const response = await fetch(
1631
+ `${baseUrl}/getTransactions?hash=${encodeURIComponent(String(args.txHash))}&limit=1&api_key=${apiKey}`
1632
+ );
1633
+ const data = await response.json();
1634
+ if (data.result.length === 0) {
1635
+ return {
1636
+ content: [{ type: "text", text: "Transaction not found" }]
1637
+ };
1638
+ }
1639
+ return {
1640
+ content: [
1641
+ {
1642
+ type: "text",
1643
+ text: `Transaction found:
1644
+ ${JSON.stringify(data.result[0], null, 2)}`
1645
+ }
1646
+ ]
1647
+ };
1648
+ }
1649
+ default:
1650
+ return {
1651
+ content: [
1652
+ {
1653
+ type: "text",
1654
+ text: `Direct execution of ${toolName} is not supported. Configure tonMcpEndpoint to proxy to @ton/mcp.`
1655
+ }
1656
+ ],
1657
+ isError: true
1658
+ };
1659
+ }
1660
+ } catch (error) {
1661
+ const message = error instanceof Error ? error.message : String(error);
1662
+ return {
1663
+ content: [{ type: "text", text: `Error executing TON API call: ${message}` }],
1664
+ isError: true
1665
+ };
1666
+ }
1667
+ }
1668
+
1669
+ // src/tools/unified.ts
1670
+ var import_zod12 = require("zod");
1671
+ var import_wdk_protocol2 = require("@t402/wdk-protocol");
1672
+ var smartPayInputSchema = import_zod12.z.object({
1673
+ url: import_zod12.z.string().url().describe("URL of the 402-protected resource"),
1674
+ maxBridgeFee: import_zod12.z.string().regex(/^\d+(\.\d+)?$/).optional().describe("Maximum acceptable bridge fee in native token (optional)"),
1675
+ preferredNetwork: import_zod12.z.string().optional().describe("Preferred network for payment (optional)")
1676
+ });
1677
+ var paymentPlanInputSchema = import_zod12.z.object({
1678
+ paymentRequired: import_zod12.z.object({
1679
+ scheme: import_zod12.z.string().optional(),
1680
+ network: import_zod12.z.string().optional(),
1681
+ maxAmountRequired: import_zod12.z.string().optional(),
1682
+ resource: import_zod12.z.string().optional(),
1683
+ description: import_zod12.z.string().optional(),
1684
+ payTo: import_zod12.z.string().optional(),
1685
+ maxDeadline: import_zod12.z.number().optional()
1686
+ }).passthrough().describe("The 402 PaymentRequired response")
1687
+ });
1688
+ var UNIFIED_TOOL_DEFINITIONS = {
1689
+ "t402/smartPay": {
1690
+ name: "t402/smartPay",
1691
+ description: "Intelligent payment that automatically checks balance, bridges if needed, and pays. Handles the entire payment flow for 402-protected resources.",
1692
+ inputSchema: {
1693
+ type: "object",
1694
+ properties: {
1695
+ url: { type: "string", description: "URL of the 402-protected resource" },
1696
+ maxBridgeFee: {
1697
+ type: "string",
1698
+ description: "Maximum acceptable bridge fee in native token (optional)"
1699
+ },
1700
+ preferredNetwork: {
1701
+ type: "string",
1702
+ description: "Preferred network for payment (optional)"
1703
+ }
1704
+ },
1705
+ required: ["url"]
1706
+ }
1707
+ },
1708
+ "t402/paymentPlan": {
1709
+ name: "t402/paymentPlan",
1710
+ description: "Analyze a 402 response and create an optimal payment plan considering balances across all chains. Returns recommended network, bridge requirements, and balance overview.",
1711
+ inputSchema: {
1712
+ type: "object",
1713
+ properties: {
1714
+ paymentRequired: {
1715
+ type: "object",
1716
+ description: "The 402 PaymentRequired response"
1717
+ }
1718
+ },
1719
+ required: ["paymentRequired"]
1720
+ }
1721
+ }
1722
+ };
1723
+ async function executeSmartPay(input, wdk) {
1724
+ const steps = [];
1725
+ const chains6 = input.preferredNetwork ? [input.preferredNetwork] : ["ethereum", "arbitrum", "base"];
1726
+ steps.push({
1727
+ action: "check_balance",
1728
+ status: "success",
1729
+ detail: `Checking balances on ${chains6.join(", ")}`
1730
+ });
1731
+ const protocol = await import_wdk_protocol2.T402Protocol.create(wdk, { chains: chains6 });
1732
+ steps.push({
1733
+ action: "fetch",
1734
+ status: "success",
1735
+ detail: `Fetching ${input.url}`
1736
+ });
1737
+ const { response, receipt } = await protocol.fetch(input.url);
1738
+ if (receipt) {
1739
+ steps.push({
1740
+ action: "pay",
1741
+ status: "success",
1742
+ detail: `Payment made: ${receipt.amount} on ${receipt.network}`
1743
+ });
1744
+ }
1745
+ const contentType = response.headers.get("content-type") ?? void 0;
1746
+ let body = "";
1747
+ try {
1748
+ body = await response.text();
1749
+ if (body.length > 1e4) {
1750
+ body = body.slice(0, 1e4) + "\n... (truncated)";
1751
+ }
1752
+ } catch {
1753
+ body = "[Could not read response body]";
1754
+ }
1755
+ return {
1756
+ success: response.ok,
1757
+ statusCode: response.status,
1758
+ body,
1759
+ contentType,
1760
+ steps,
1761
+ payment: receipt ? {
1762
+ network: receipt.network,
1763
+ scheme: receipt.scheme,
1764
+ amount: receipt.amount,
1765
+ payTo: receipt.payTo
1766
+ } : void 0
1767
+ };
1768
+ }
1769
+ function executeSmartPayDemo(input) {
1770
+ const network = input.preferredNetwork ?? "arbitrum";
1771
+ return {
1772
+ success: true,
1773
+ statusCode: 200,
1774
+ body: `[Demo] Premium content from ${input.url}
1775
+
1776
+ This is simulated content returned after smart payment.`,
1777
+ contentType: "text/plain",
1778
+ steps: [
1779
+ { action: "check_balance", status: "success", detail: `Checked balances on ${network}` },
1780
+ { action: "check_price", status: "success", detail: "Resource costs 1.00 USDT0" },
1781
+ { action: "pay", status: "success", detail: `Paid 1000000 USDT0 on eip155:42161` },
1782
+ { action: "fetch", status: "success", detail: `Fetched ${input.url}` }
1783
+ ],
1784
+ payment: {
1785
+ network: "eip155:42161",
1786
+ scheme: "exact",
1787
+ amount: "1000000",
1788
+ payTo: "0xC88f67e776f16DcFBf42e6bDda1B82604448899B"
1789
+ }
1790
+ };
1791
+ }
1792
+ async function executePaymentPlan(input, wdk) {
1793
+ const targetNetwork = input.paymentRequired.network;
1794
+ const requiredAmount = input.paymentRequired.maxAmountRequired;
1795
+ const aggregated = await wdk.getAggregatedBalances();
1796
+ const balances = aggregated.chains.map((chain) => {
1797
+ const usdt0 = chain.tokens.find((t) => t.symbol === "USDT0");
1798
+ const usdc = chain.tokens.find((t) => t.symbol === "USDC");
1799
+ return {
1800
+ chain: chain.chain,
1801
+ usdt0: usdt0?.formatted ?? "0",
1802
+ usdc: usdc?.formatted ?? "0"
1803
+ };
1804
+ });
1805
+ const requiredBigint = requiredAmount ? BigInt(requiredAmount) : 0n;
1806
+ const bestChain = await wdk.findBestChainForPayment(requiredBigint);
1807
+ if (bestChain) {
1808
+ const needsBridge = targetNetwork ? !bestChain.chain.includes(targetNetwork) : false;
1809
+ return {
1810
+ viable: true,
1811
+ recommendedNetwork: bestChain.chain,
1812
+ availableBalance: bestChain.balance.toString(),
1813
+ bridgeRequired: needsBridge,
1814
+ bridgeDetails: needsBridge ? {
1815
+ fromChain: bestChain.chain,
1816
+ toChain: targetNetwork ?? bestChain.chain,
1817
+ amount: requiredAmount ?? "0",
1818
+ estimatedFee: "0.001"
1819
+ } : void 0,
1820
+ balances
1821
+ };
1822
+ }
1823
+ return {
1824
+ viable: false,
1825
+ bridgeRequired: false,
1826
+ balances,
1827
+ reason: "Insufficient balance across all chains"
1828
+ };
1829
+ }
1830
+ function executePaymentPlanDemo(_input) {
1831
+ return {
1832
+ viable: true,
1833
+ recommendedNetwork: "arbitrum",
1834
+ availableBalance: "500000000",
1835
+ bridgeRequired: false,
1836
+ balances: [
1837
+ { chain: "ethereum", usdt0: "100.00", usdc: "250.00" },
1838
+ { chain: "arbitrum", usdt0: "500.00", usdc: "0" },
1839
+ { chain: "base", usdt0: "50.00", usdc: "100.00" }
1840
+ ]
1841
+ };
1842
+ }
1843
+ function formatSmartPayResult(result) {
1844
+ const lines = ["## SmartPay Result", ""];
1845
+ if (result.success) {
1846
+ lines.push(`**Status:** Success (${result.statusCode})`);
1847
+ } else {
1848
+ lines.push(`**Status:** Failed (${result.statusCode})`);
1849
+ }
1850
+ if (result.steps.length > 0) {
1851
+ lines.push("");
1852
+ lines.push("### Steps");
1853
+ for (const step of result.steps) {
1854
+ const icon = step.status === "success" ? "[OK]" : step.status === "skipped" ? "[SKIP]" : "[FAIL]";
1855
+ lines.push(`- ${icon} **${step.action}**: ${step.detail}`);
1856
+ }
1857
+ }
1858
+ if (result.payment) {
1859
+ lines.push("");
1860
+ lines.push("### Payment Details");
1861
+ lines.push(`- **Network:** ${result.payment.network}`);
1862
+ lines.push(`- **Scheme:** ${result.payment.scheme}`);
1863
+ lines.push(`- **Amount:** ${result.payment.amount}`);
1864
+ lines.push(`- **Pay To:** \`${result.payment.payTo}\``);
1865
+ }
1866
+ if (result.error) {
1867
+ lines.push("");
1868
+ lines.push(`**Error:** ${result.error}`);
1869
+ }
1870
+ if (result.body) {
1871
+ lines.push("");
1872
+ lines.push("### Response Content");
1873
+ if (result.contentType) {
1874
+ lines.push(`_Content-Type: ${result.contentType}_`);
1875
+ }
1876
+ lines.push("");
1877
+ lines.push("```");
1878
+ lines.push(result.body);
1879
+ lines.push("```");
1880
+ }
1881
+ return lines.join("\n");
1882
+ }
1883
+ function formatPaymentPlanResult(result) {
1884
+ const lines = ["## Payment Plan", ""];
1885
+ if (result.viable) {
1886
+ lines.push(`**Viable:** Yes`);
1887
+ if (result.recommendedNetwork) {
1888
+ lines.push(`**Recommended Network:** ${result.recommendedNetwork}`);
1889
+ }
1890
+ if (result.availableBalance) {
1891
+ lines.push(`**Available Balance:** ${result.availableBalance}`);
1892
+ }
1893
+ } else {
1894
+ lines.push(`**Viable:** No`);
1895
+ if (result.reason) {
1896
+ lines.push(`**Reason:** ${result.reason}`);
1897
+ }
1898
+ }
1899
+ if (result.bridgeRequired && result.bridgeDetails) {
1900
+ lines.push("");
1901
+ lines.push("### Bridge Required");
1902
+ lines.push(`- **From:** ${result.bridgeDetails.fromChain}`);
1903
+ lines.push(`- **To:** ${result.bridgeDetails.toChain}`);
1904
+ lines.push(`- **Amount:** ${result.bridgeDetails.amount}`);
1905
+ lines.push(`- **Estimated Fee:** ${result.bridgeDetails.estimatedFee}`);
1906
+ }
1907
+ if (result.balances.length > 0) {
1908
+ lines.push("");
1909
+ lines.push("### Chain Balances");
1910
+ lines.push("| Chain | USDT0 | USDC |");
1911
+ lines.push("|-------|-------|------|");
1912
+ for (const b of result.balances) {
1913
+ lines.push(`| ${b.chain} | ${b.usdt0} | ${b.usdc} |`);
1914
+ }
1915
+ }
1916
+ return lines.join("\n");
1917
+ }
1918
+
1437
1919
  // src/tools/index.ts
1438
1920
  var TOOL_DEFINITIONS = {
1439
1921
  "t402/getBalance": {
@@ -1745,6 +2227,8 @@ var T402McpServer = class {
1745
2227
  __publicField(this, "server");
1746
2228
  __publicField(this, "config");
1747
2229
  __publicField(this, "wdk", null);
2230
+ /** TON MCP bridge configuration */
2231
+ __publicField(this, "tonBridgeConfig", null);
1748
2232
  this.config = config;
1749
2233
  this.server = new import_server.Server(
1750
2234
  {
@@ -1778,13 +2262,27 @@ var T402McpServer = class {
1778
2262
  }
1779
2263
  }
1780
2264
  /**
1781
- * Get all tool definitions (base + WDK if configured)
2265
+ * Register TON bridge tools
2266
+ *
2267
+ * Enables AI agents to use @ton/mcp tools through the t402 MCP server.
2268
+ */
2269
+ registerTonBridge(config) {
2270
+ this.tonBridgeConfig = config;
2271
+ }
2272
+ /**
2273
+ * Get all tool definitions (base + WDK if configured + unified if enabled + TON bridge if registered)
1782
2274
  */
1783
2275
  getToolDefinitions() {
1784
2276
  const tools = { ...TOOL_DEFINITIONS };
1785
2277
  if (this.wdk || this.config.demoMode) {
1786
2278
  Object.assign(tools, WDK_TOOL_DEFINITIONS);
1787
2279
  }
2280
+ if (this.config.unifiedMode && (this.wdk || this.config.demoMode)) {
2281
+ Object.assign(tools, UNIFIED_TOOL_DEFINITIONS);
2282
+ }
2283
+ if (this.tonBridgeConfig) {
2284
+ Object.assign(tools, TON_BRIDGE_TOOLS);
2285
+ }
1788
2286
  return tools;
1789
2287
  }
1790
2288
  /**
@@ -1823,6 +2321,18 @@ var T402McpServer = class {
1823
2321
  return await this.handleWdkSwap(args);
1824
2322
  case "t402/autoPay":
1825
2323
  return await this.handleAutoPay(args);
2324
+ // Unified tools
2325
+ case "t402/smartPay":
2326
+ return await this.handleSmartPay(args);
2327
+ case "t402/paymentPlan":
2328
+ return await this.handlePaymentPlan(args);
2329
+ // TON bridge tools
2330
+ case "ton/getBalance":
2331
+ case "ton/transfer":
2332
+ case "ton/getJettonBalance":
2333
+ case "ton/swapJettons":
2334
+ case "ton/getTransactionStatus":
2335
+ return await this.handleTonBridgeTool(name, args);
1826
2336
  default:
1827
2337
  throw new Error(`Unknown tool: ${name}`);
1828
2338
  }
@@ -2020,6 +2530,37 @@ var T402McpServer = class {
2020
2530
  content: [{ type: "text", text: formatAutoPayResult(result) }]
2021
2531
  };
2022
2532
  }
2533
+ // ---- Unified Tool Handlers ----
2534
+ /**
2535
+ * Handle t402/smartPay
2536
+ */
2537
+ async handleSmartPay(args) {
2538
+ const input = smartPayInputSchema.parse(args);
2539
+ const result = this.config.demoMode || !this.wdk ? executeSmartPayDemo(input) : await executeSmartPay(input, this.wdk);
2540
+ return {
2541
+ content: [{ type: "text", text: formatSmartPayResult(result) }]
2542
+ };
2543
+ }
2544
+ /**
2545
+ * Handle t402/paymentPlan
2546
+ */
2547
+ async handlePaymentPlan(args) {
2548
+ const input = paymentPlanInputSchema.parse(args);
2549
+ const result = this.config.demoMode || !this.wdk ? executePaymentPlanDemo(input) : await executePaymentPlan(input, this.wdk);
2550
+ return {
2551
+ content: [{ type: "text", text: formatPaymentPlanResult(result) }]
2552
+ };
2553
+ }
2554
+ // ---- TON Bridge Tool Handler ----
2555
+ /**
2556
+ * Handle TON bridge tool calls
2557
+ */
2558
+ async handleTonBridgeTool(name, args) {
2559
+ if (!this.tonBridgeConfig) {
2560
+ throw new Error("TON bridge not configured. Call registerTonBridge() to enable TON tools.");
2561
+ }
2562
+ return executeTonBridgeTool(name, args ?? {}, this.tonBridgeConfig);
2563
+ }
2023
2564
  /**
2024
2565
  * Start the server using stdio transport
2025
2566
  */
@@ -2053,6 +2594,9 @@ function loadConfigFromEnv() {
2053
2594
  if (process.env.T402_WDK_CHAINS) {
2054
2595
  config.wdkChains = process.env.T402_WDK_CHAINS.split(",").map((c) => c.trim());
2055
2596
  }
2597
+ if (process.env.T402_UNIFIED_MODE === "true") {
2598
+ config.unifiedMode = true;
2599
+ }
2056
2600
  const rpcUrls = {};
2057
2601
  const networks = [
2058
2602
  "ethereum",
@@ -2074,6 +2618,12 @@ function loadConfigFromEnv() {
2074
2618
  if (Object.keys(rpcUrls).length > 0) {
2075
2619
  config.rpcUrls = rpcUrls;
2076
2620
  }
2621
+ if (process.env.T402_TON_MCP_ENDPOINT) {
2622
+ config.tonMcpEndpoint = process.env.T402_TON_MCP_ENDPOINT;
2623
+ }
2624
+ if (process.env.T402_TON_API_KEY) {
2625
+ config.tonApiKey = process.env.T402_TON_API_KEY;
2626
+ }
2077
2627
  return config;
2078
2628
  }
2079
2629
  // Annotate the CommonJS export names for ESM import in node: