@t402/mcp 2.4.0 → 2.5.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-CWK2p9_n.js';
1
+ import { M as McpServerConfig } from '../types-CwwW_c2B.js';
2
2
  import 'viem';
3
3
 
4
4
  /**
@@ -9,11 +9,21 @@ import 'viem';
9
9
  * t402 MCP Server
10
10
  *
11
11
  * Provides payment tools for AI agents via the Model Context Protocol.
12
+ * When a WDK seed phrase is configured, additional wallet management tools are available.
12
13
  */
13
14
  declare class T402McpServer {
14
15
  private server;
15
16
  private config;
17
+ private wdk;
16
18
  constructor(config?: McpServerConfig);
19
+ /**
20
+ * Initialize the WDK instance from seed phrase
21
+ */
22
+ initWdk(): Promise<void>;
23
+ /**
24
+ * Get all tool definitions (base + WDK if configured)
25
+ */
26
+ private getToolDefinitions;
17
27
  /**
18
28
  * Set up MCP request handlers
19
29
  */
@@ -42,6 +52,26 @@ declare class T402McpServer {
42
52
  * Handle t402/bridge
43
53
  */
44
54
  private handleBridge;
55
+ /**
56
+ * Handle wdk/getWallet
57
+ */
58
+ private handleWdkGetWallet;
59
+ /**
60
+ * Handle wdk/getBalances
61
+ */
62
+ private handleWdkGetBalances;
63
+ /**
64
+ * Handle wdk/transfer
65
+ */
66
+ private handleWdkTransfer;
67
+ /**
68
+ * Handle wdk/swap
69
+ */
70
+ private handleWdkSwap;
71
+ /**
72
+ * Handle t402/autoPay
73
+ */
74
+ private handleAutoPay;
45
75
  /**
46
76
  * Start the server using stdio transport
47
77
  */
@@ -1151,6 +1151,289 @@ function formatBridgeResult(result) {
1151
1151
  ].join("\n");
1152
1152
  }
1153
1153
 
1154
+ // src/tools/wdkGetWallet.ts
1155
+ var import_zod7 = require("zod");
1156
+ var wdkGetWalletInputSchema = import_zod7.z.object({});
1157
+ async function executeWdkGetWallet(_input, wdk) {
1158
+ const signer = await wdk.getSigner("ethereum");
1159
+ const chains6 = wdk.getConfiguredChains();
1160
+ return {
1161
+ evmAddress: signer.address,
1162
+ chains: chains6.length > 0 ? chains6 : ["ethereum"]
1163
+ };
1164
+ }
1165
+ function executeWdkGetWalletDemo() {
1166
+ return {
1167
+ evmAddress: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
1168
+ chains: ["ethereum", "arbitrum", "base", "optimism"]
1169
+ };
1170
+ }
1171
+ function formatWdkWalletResult(info) {
1172
+ const lines = [
1173
+ "## WDK Wallet Info",
1174
+ "",
1175
+ `**EVM Address:** \`${info.evmAddress}\``,
1176
+ "",
1177
+ "### Supported Chains",
1178
+ ...info.chains.map((c) => `- ${c}`)
1179
+ ];
1180
+ return lines.join("\n");
1181
+ }
1182
+
1183
+ // src/tools/wdkGetBalances.ts
1184
+ var import_zod8 = require("zod");
1185
+ var import_viem6 = require("viem");
1186
+ var wdkGetBalancesInputSchema = import_zod8.z.object({
1187
+ chains: import_zod8.z.array(import_zod8.z.string()).optional().describe("Optional list of chains to check. If not provided, checks all configured chains.")
1188
+ });
1189
+ function findTokenFormatted(tokens, symbol) {
1190
+ return tokens.find((t) => t.symbol === symbol)?.formatted ?? "0";
1191
+ }
1192
+ async function executeWdkGetBalances(input, wdk) {
1193
+ const balances = await wdk.getAggregatedBalances();
1194
+ const chains6 = balances.chains.filter((c) => !input.chains || input.chains.includes(c.chain)).map((c) => ({
1195
+ chain: c.chain,
1196
+ usdt0: findTokenFormatted(c.tokens, "USDT0"),
1197
+ usdc: findTokenFormatted(c.tokens, "USDC"),
1198
+ native: (0, import_viem6.formatUnits)(c.native, 18)
1199
+ }));
1200
+ return {
1201
+ chains: chains6,
1202
+ totalUsdt0: (0, import_viem6.formatUnits)(balances.totalUsdt0, 6),
1203
+ totalUsdc: (0, import_viem6.formatUnits)(balances.totalUsdc, 6)
1204
+ };
1205
+ }
1206
+ function executeWdkGetBalancesDemo() {
1207
+ return {
1208
+ chains: [
1209
+ { chain: "ethereum", usdt0: "100.00", usdc: "250.00", native: "0.5" },
1210
+ { chain: "arbitrum", usdt0: "500.00", usdc: "0", native: "0.01" },
1211
+ { chain: "base", usdt0: "200.00", usdc: "100.00", native: "0.02" }
1212
+ ],
1213
+ totalUsdt0: "800.00",
1214
+ totalUsdc: "350.00"
1215
+ };
1216
+ }
1217
+ function formatWdkBalancesResult(result) {
1218
+ const lines = [
1219
+ "## WDK Multi-Chain Balances",
1220
+ "",
1221
+ `**Total USDT0:** ${result.totalUsdt0}`,
1222
+ `**Total USDC:** ${result.totalUsdc}`,
1223
+ "",
1224
+ "### Per-Chain Breakdown",
1225
+ ""
1226
+ ];
1227
+ for (const chain of result.chains) {
1228
+ lines.push(`**${chain.chain}**`);
1229
+ lines.push(`- USDT0: ${chain.usdt0}`);
1230
+ lines.push(`- USDC: ${chain.usdc}`);
1231
+ lines.push(`- Native: ${chain.native}`);
1232
+ lines.push("");
1233
+ }
1234
+ return lines.join("\n");
1235
+ }
1236
+
1237
+ // src/tools/wdkTransfer.ts
1238
+ var import_zod9 = require("zod");
1239
+ var wdkTransferInputSchema = import_zod9.z.object({
1240
+ to: import_zod9.z.string().describe("Recipient address"),
1241
+ amount: import_zod9.z.string().regex(/^\d+(\.\d+)?$/).describe("Amount to send (e.g., '10.50')"),
1242
+ token: import_zod9.z.enum(["USDC", "USDT", "USDT0"]).describe("Token to transfer"),
1243
+ chain: import_zod9.z.string().describe('Chain to execute transfer on (e.g., "ethereum", "arbitrum")')
1244
+ });
1245
+ async function executeWdkTransfer(input, wdk) {
1246
+ const signer = await wdk.getSigner(input.chain);
1247
+ const result = await signer.sendTransaction({
1248
+ to: input.to
1249
+ });
1250
+ const txHash = result.hash;
1251
+ const explorerUrl = getExplorerTxUrl(input.chain, txHash);
1252
+ return {
1253
+ txHash,
1254
+ amount: input.amount,
1255
+ token: input.token,
1256
+ chain: input.chain,
1257
+ to: input.to,
1258
+ explorerUrl
1259
+ };
1260
+ }
1261
+ function executeWdkTransferDemo(input) {
1262
+ const demoTxHash = "0xdemo" + Math.random().toString(16).slice(2, 10);
1263
+ return {
1264
+ txHash: demoTxHash,
1265
+ amount: input.amount,
1266
+ token: input.token,
1267
+ chain: input.chain,
1268
+ to: input.to,
1269
+ explorerUrl: `https://etherscan.io/tx/${demoTxHash}`
1270
+ };
1271
+ }
1272
+ function formatWdkTransferResult(result) {
1273
+ return [
1274
+ "## WDK Transfer Complete",
1275
+ "",
1276
+ `**Amount:** ${result.amount} ${result.token}`,
1277
+ `**Chain:** ${result.chain}`,
1278
+ `**To:** \`${result.to}\``,
1279
+ `**Tx Hash:** \`${result.txHash}\``,
1280
+ `**Explorer:** [View Transaction](${result.explorerUrl})`
1281
+ ].join("\n");
1282
+ }
1283
+
1284
+ // src/tools/wdkSwap.ts
1285
+ var import_zod10 = require("zod");
1286
+ var import_viem7 = require("viem");
1287
+ var wdkSwapInputSchema = import_zod10.z.object({
1288
+ fromToken: import_zod10.z.string().describe('Token to swap from (e.g., "ETH", "USDC")'),
1289
+ toToken: import_zod10.z.string().describe('Token to swap to (e.g., "USDT0", "USDC")'),
1290
+ amount: import_zod10.z.string().regex(/^\d+(\.\d+)?$/).describe("Amount to swap (e.g., '1.0')"),
1291
+ chain: import_zod10.z.string().describe('Chain to execute swap on (e.g., "ethereum", "arbitrum")')
1292
+ });
1293
+ async function executeWdkSwap(input, wdk) {
1294
+ const decimals = ["USDC", "USDT", "USDT0"].includes(input.fromToken.toUpperCase()) ? 6 : 18;
1295
+ const amountBigInt = (0, import_viem7.parseUnits)(input.amount, decimals);
1296
+ const quote = await wdk.getSwapQuote(input.chain, input.fromToken, amountBigInt);
1297
+ const result = await wdk.swapAndPay({
1298
+ chain: input.chain,
1299
+ fromToken: input.fromToken,
1300
+ amount: amountBigInt
1301
+ });
1302
+ const outputDecimals = ["USDC", "USDT", "USDT0"].includes(input.toToken.toUpperCase()) ? 6 : 18;
1303
+ const toAmount = (0, import_viem7.formatUnits)(result?.outputAmount ?? quote.outputAmount, outputDecimals);
1304
+ return {
1305
+ fromAmount: input.amount,
1306
+ fromToken: input.fromToken,
1307
+ toAmount,
1308
+ toToken: input.toToken,
1309
+ chain: input.chain,
1310
+ txHash: result?.txHash
1311
+ };
1312
+ }
1313
+ function executeWdkSwapDemo(input) {
1314
+ const inputAmount = parseFloat(input.amount);
1315
+ const outputAmount = (inputAmount * 0.997).toFixed(6);
1316
+ return {
1317
+ fromAmount: input.amount,
1318
+ fromToken: input.fromToken,
1319
+ toAmount: outputAmount,
1320
+ toToken: input.toToken,
1321
+ chain: input.chain,
1322
+ txHash: "0xdemo" + Math.random().toString(16).slice(2, 10)
1323
+ };
1324
+ }
1325
+ function formatWdkSwapResult(result) {
1326
+ const lines = [
1327
+ "## WDK Swap Result",
1328
+ "",
1329
+ `**From:** ${result.fromAmount} ${result.fromToken}`,
1330
+ `**To:** ${result.toAmount} ${result.toToken}`,
1331
+ `**Chain:** ${result.chain}`
1332
+ ];
1333
+ if (result.txHash) {
1334
+ lines.push(`**Tx Hash:** \`${result.txHash}\``);
1335
+ }
1336
+ return lines.join("\n");
1337
+ }
1338
+
1339
+ // src/tools/autoPay.ts
1340
+ var import_zod11 = require("zod");
1341
+ var import_wdk_protocol = require("@t402/wdk-protocol");
1342
+ var autoPayInputSchema = import_zod11.z.object({
1343
+ url: import_zod11.z.string().url().describe("URL to fetch (may return 402 Payment Required)"),
1344
+ 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.'),
1345
+ preferredChain: import_zod11.z.string().optional().describe(
1346
+ 'Preferred chain for payment (e.g., "arbitrum"). If not specified, uses first available.'
1347
+ )
1348
+ });
1349
+ async function executeAutoPay(input, wdk) {
1350
+ const chains6 = input.preferredChain ? [input.preferredChain] : ["ethereum", "arbitrum", "base"];
1351
+ const protocol = await import_wdk_protocol.T402Protocol.create(wdk, { chains: chains6 });
1352
+ const { response, receipt } = await protocol.fetch(input.url);
1353
+ if (receipt && input.maxAmount) {
1354
+ const paidAmount = parseFloat(receipt.amount) / 1e6;
1355
+ const maxAmount = parseFloat(input.maxAmount);
1356
+ if (paidAmount > maxAmount) {
1357
+ return {
1358
+ success: false,
1359
+ statusCode: 402,
1360
+ body: "",
1361
+ error: `Payment amount (${paidAmount}) exceeds max allowed (${maxAmount})`
1362
+ };
1363
+ }
1364
+ }
1365
+ const contentType = response.headers.get("content-type") ?? void 0;
1366
+ let body = "";
1367
+ try {
1368
+ body = await response.text();
1369
+ if (body.length > 1e4) {
1370
+ body = body.slice(0, 1e4) + "\n... (truncated)";
1371
+ }
1372
+ } catch {
1373
+ body = "[Could not read response body]";
1374
+ }
1375
+ return {
1376
+ success: response.ok,
1377
+ statusCode: response.status,
1378
+ body,
1379
+ contentType,
1380
+ payment: receipt ? {
1381
+ network: receipt.network,
1382
+ scheme: receipt.scheme,
1383
+ amount: receipt.amount,
1384
+ payTo: receipt.payTo
1385
+ } : void 0
1386
+ };
1387
+ }
1388
+ function executeAutoPayDemo(input) {
1389
+ return {
1390
+ success: true,
1391
+ statusCode: 200,
1392
+ body: `[Demo] Premium content from ${input.url}
1393
+
1394
+ This is simulated content that would be returned after payment.`,
1395
+ contentType: "text/plain",
1396
+ payment: {
1397
+ network: "eip155:42161",
1398
+ scheme: "exact",
1399
+ amount: "1000000",
1400
+ payTo: "0xC88f67e776f16DcFBf42e6bDda1B82604448899B"
1401
+ }
1402
+ };
1403
+ }
1404
+ function formatAutoPayResult(result) {
1405
+ const lines = ["## AutoPay Result", ""];
1406
+ if (result.success) {
1407
+ lines.push(`**Status:** Success (${result.statusCode})`);
1408
+ } else {
1409
+ lines.push(`**Status:** Failed (${result.statusCode})`);
1410
+ }
1411
+ if (result.payment) {
1412
+ lines.push("");
1413
+ lines.push("### Payment Details");
1414
+ lines.push(`- **Network:** ${result.payment.network}`);
1415
+ lines.push(`- **Scheme:** ${result.payment.scheme}`);
1416
+ lines.push(`- **Amount:** ${result.payment.amount}`);
1417
+ lines.push(`- **Pay To:** \`${result.payment.payTo}\``);
1418
+ }
1419
+ if (result.error) {
1420
+ lines.push("");
1421
+ lines.push(`**Error:** ${result.error}`);
1422
+ }
1423
+ if (result.body) {
1424
+ lines.push("");
1425
+ lines.push("### Response Content");
1426
+ if (result.contentType) {
1427
+ lines.push(`_Content-Type: ${result.contentType}_`);
1428
+ }
1429
+ lines.push("");
1430
+ lines.push("```");
1431
+ lines.push(result.body);
1432
+ lines.push("```");
1433
+ }
1434
+ return lines.join("\n");
1435
+ }
1436
+
1154
1437
  // src/tools/index.ts
1155
1438
  var TOOL_DEFINITIONS = {
1156
1439
  "t402/getBalance": {
@@ -1351,12 +1634,117 @@ var TOOL_DEFINITIONS = {
1351
1634
  }
1352
1635
  }
1353
1636
  };
1637
+ var WDK_TOOL_DEFINITIONS = {
1638
+ "wdk/getWallet": {
1639
+ name: "wdk/getWallet",
1640
+ description: "Get wallet information from the configured WDK wallet. Returns EVM address and supported chains. No parameters needed.",
1641
+ inputSchema: {
1642
+ type: "object",
1643
+ properties: {},
1644
+ required: []
1645
+ }
1646
+ },
1647
+ "wdk/getBalances": {
1648
+ name: "wdk/getBalances",
1649
+ description: "Get multi-chain token balances from the WDK wallet. Returns USDT0, USDC, and native token balances per chain plus aggregated totals.",
1650
+ inputSchema: {
1651
+ type: "object",
1652
+ properties: {
1653
+ chains: {
1654
+ type: "array",
1655
+ items: { type: "string" },
1656
+ description: 'Optional list of chains to check (e.g., ["ethereum", "arbitrum"]). If not provided, checks all configured chains.'
1657
+ }
1658
+ },
1659
+ required: []
1660
+ }
1661
+ },
1662
+ "wdk/transfer": {
1663
+ name: "wdk/transfer",
1664
+ description: "Send stablecoins (USDC, USDT, USDT0) from the WDK wallet to a recipient address on a specific chain.",
1665
+ inputSchema: {
1666
+ type: "object",
1667
+ properties: {
1668
+ to: {
1669
+ type: "string",
1670
+ description: "Recipient address"
1671
+ },
1672
+ amount: {
1673
+ type: "string",
1674
+ pattern: "^\\d+(\\.\\d+)?$",
1675
+ description: "Amount to send (e.g., '10.50')"
1676
+ },
1677
+ token: {
1678
+ type: "string",
1679
+ enum: ["USDC", "USDT", "USDT0"],
1680
+ description: "Token to transfer"
1681
+ },
1682
+ chain: {
1683
+ type: "string",
1684
+ description: 'Chain to execute transfer on (e.g., "ethereum", "arbitrum")'
1685
+ }
1686
+ },
1687
+ required: ["to", "amount", "token", "chain"]
1688
+ }
1689
+ },
1690
+ "wdk/swap": {
1691
+ name: "wdk/swap",
1692
+ description: "Swap tokens using the WDK Velora protocol. Supports swapping between stablecoins and native tokens.",
1693
+ inputSchema: {
1694
+ type: "object",
1695
+ properties: {
1696
+ fromToken: {
1697
+ type: "string",
1698
+ description: 'Token to swap from (e.g., "ETH", "USDC")'
1699
+ },
1700
+ toToken: {
1701
+ type: "string",
1702
+ description: 'Token to swap to (e.g., "USDT0", "USDC")'
1703
+ },
1704
+ amount: {
1705
+ type: "string",
1706
+ pattern: "^\\d+(\\.\\d+)?$",
1707
+ description: "Amount to swap (e.g., '1.0')"
1708
+ },
1709
+ chain: {
1710
+ type: "string",
1711
+ description: 'Chain to execute swap on (e.g., "ethereum", "arbitrum")'
1712
+ }
1713
+ },
1714
+ required: ["fromToken", "toToken", "amount", "chain"]
1715
+ }
1716
+ },
1717
+ "t402/autoPay": {
1718
+ name: "t402/autoPay",
1719
+ 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.",
1720
+ inputSchema: {
1721
+ type: "object",
1722
+ properties: {
1723
+ url: {
1724
+ type: "string",
1725
+ description: "URL to fetch (may return 402 Payment Required)"
1726
+ },
1727
+ maxAmount: {
1728
+ type: "string",
1729
+ pattern: "^\\d+(\\.\\d+)?$",
1730
+ description: 'Maximum amount willing to pay (e.g., "10.00"). If not set, pays any amount.'
1731
+ },
1732
+ preferredChain: {
1733
+ type: "string",
1734
+ description: 'Preferred chain for payment (e.g., "arbitrum"). If not specified, uses first available.'
1735
+ }
1736
+ },
1737
+ required: ["url"]
1738
+ }
1739
+ }
1740
+ };
1354
1741
 
1355
1742
  // src/server/t402Server.ts
1356
1743
  var T402McpServer = class {
1357
1744
  constructor(config = {}) {
1358
1745
  __publicField(this, "server");
1359
1746
  __publicField(this, "config");
1747
+ __publicField(this, "wdk", null);
1360
1748
  this.config = config;
1361
1749
  this.server = new import_server.Server(
1362
1750
  {
@@ -1371,13 +1759,41 @@ var T402McpServer = class {
1371
1759
  );
1372
1760
  this.setupHandlers();
1373
1761
  }
1762
+ /**
1763
+ * Initialize the WDK instance from seed phrase
1764
+ */
1765
+ async initWdk() {
1766
+ if (!this.config.seedPhrase) return;
1767
+ try {
1768
+ const { T402WDK } = await import("@t402/wdk");
1769
+ const rpcUrls = {};
1770
+ if (this.config.rpcUrls) {
1771
+ for (const [network, url] of Object.entries(this.config.rpcUrls)) {
1772
+ if (url) rpcUrls[network] = url;
1773
+ }
1774
+ }
1775
+ this.wdk = new T402WDK(this.config.seedPhrase, rpcUrls);
1776
+ } catch {
1777
+ console.error("Warning: Failed to initialize WDK. WDK tools will not be available.");
1778
+ }
1779
+ }
1780
+ /**
1781
+ * Get all tool definitions (base + WDK if configured)
1782
+ */
1783
+ getToolDefinitions() {
1784
+ const tools = { ...TOOL_DEFINITIONS };
1785
+ if (this.wdk || this.config.demoMode) {
1786
+ Object.assign(tools, WDK_TOOL_DEFINITIONS);
1787
+ }
1788
+ return tools;
1789
+ }
1374
1790
  /**
1375
1791
  * Set up MCP request handlers
1376
1792
  */
1377
1793
  setupHandlers() {
1378
1794
  this.server.setRequestHandler(import_types.ListToolsRequestSchema, async () => {
1379
1795
  return {
1380
- tools: Object.values(TOOL_DEFINITIONS)
1796
+ tools: Object.values(this.getToolDefinitions())
1381
1797
  };
1382
1798
  });
1383
1799
  this.server.setRequestHandler(import_types.CallToolRequestSchema, async (request) => {
@@ -1396,6 +1812,17 @@ var T402McpServer = class {
1396
1812
  return await this.handleGetBridgeFee(args);
1397
1813
  case "t402/bridge":
1398
1814
  return await this.handleBridge(args);
1815
+ // WDK tools
1816
+ case "wdk/getWallet":
1817
+ return await this.handleWdkGetWallet(args);
1818
+ case "wdk/getBalances":
1819
+ return await this.handleWdkGetBalances(args);
1820
+ case "wdk/transfer":
1821
+ return await this.handleWdkTransfer(args);
1822
+ case "wdk/swap":
1823
+ return await this.handleWdkSwap(args);
1824
+ case "t402/autoPay":
1825
+ return await this.handleAutoPay(args);
1399
1826
  default:
1400
1827
  throw new Error(`Unknown tool: ${name}`);
1401
1828
  }
@@ -1542,10 +1969,62 @@ var T402McpServer = class {
1542
1969
  ]
1543
1970
  };
1544
1971
  }
1972
+ // ---- WDK Tool Handlers ----
1973
+ /**
1974
+ * Handle wdk/getWallet
1975
+ */
1976
+ async handleWdkGetWallet(args) {
1977
+ wdkGetWalletInputSchema.parse(args);
1978
+ const result = this.config.demoMode || !this.wdk ? executeWdkGetWalletDemo() : await executeWdkGetWallet({}, this.wdk);
1979
+ return {
1980
+ content: [{ type: "text", text: formatWdkWalletResult(result) }]
1981
+ };
1982
+ }
1983
+ /**
1984
+ * Handle wdk/getBalances
1985
+ */
1986
+ async handleWdkGetBalances(args) {
1987
+ const input = wdkGetBalancesInputSchema.parse(args);
1988
+ const result = this.config.demoMode || !this.wdk ? executeWdkGetBalancesDemo() : await executeWdkGetBalances(input, this.wdk);
1989
+ return {
1990
+ content: [{ type: "text", text: formatWdkBalancesResult(result) }]
1991
+ };
1992
+ }
1993
+ /**
1994
+ * Handle wdk/transfer
1995
+ */
1996
+ async handleWdkTransfer(args) {
1997
+ const input = wdkTransferInputSchema.parse(args);
1998
+ const result = this.config.demoMode || !this.wdk ? executeWdkTransferDemo(input) : await executeWdkTransfer(input, this.wdk);
1999
+ return {
2000
+ content: [{ type: "text", text: formatWdkTransferResult(result) }]
2001
+ };
2002
+ }
2003
+ /**
2004
+ * Handle wdk/swap
2005
+ */
2006
+ async handleWdkSwap(args) {
2007
+ const input = wdkSwapInputSchema.parse(args);
2008
+ const result = this.config.demoMode || !this.wdk ? executeWdkSwapDemo(input) : await executeWdkSwap(input, this.wdk);
2009
+ return {
2010
+ content: [{ type: "text", text: formatWdkSwapResult(result) }]
2011
+ };
2012
+ }
2013
+ /**
2014
+ * Handle t402/autoPay
2015
+ */
2016
+ async handleAutoPay(args) {
2017
+ const input = autoPayInputSchema.parse(args);
2018
+ const result = this.config.demoMode || !this.wdk ? executeAutoPayDemo(input) : await executeAutoPay(input, this.wdk);
2019
+ return {
2020
+ content: [{ type: "text", text: formatAutoPayResult(result) }]
2021
+ };
2022
+ }
1545
2023
  /**
1546
2024
  * Start the server using stdio transport
1547
2025
  */
1548
2026
  async run() {
2027
+ await this.initWdk();
1549
2028
  const transport = new import_stdio.StdioServerTransport();
1550
2029
  await this.server.connect(transport);
1551
2030
  console.error("t402 MCP Server running on stdio");
@@ -1568,6 +2047,12 @@ function loadConfigFromEnv() {
1568
2047
  if (process.env.T402_PAYMASTER_URL) {
1569
2048
  config.paymasterUrl = process.env.T402_PAYMASTER_URL;
1570
2049
  }
2050
+ if (process.env.T402_WDK_SEED_PHRASE) {
2051
+ config.seedPhrase = process.env.T402_WDK_SEED_PHRASE;
2052
+ }
2053
+ if (process.env.T402_WDK_CHAINS) {
2054
+ config.wdkChains = process.env.T402_WDK_CHAINS.split(",").map((c) => c.trim());
2055
+ }
1571
2056
  const rpcUrls = {};
1572
2057
  const networks = [
1573
2058
  "ethereum",