@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.
- package/bin/t402-mcp.js +13 -3
- package/dist/cjs/index.d.ts +3 -2
- package/dist/cjs/index.js +486 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/server/index.d.ts +31 -1
- package/dist/cjs/server/index.js +486 -1
- package/dist/cjs/server/index.js.map +1 -1
- package/dist/cjs/tools/index.d.ts +403 -3
- package/dist/cjs/tools/index.js +431 -2
- package/dist/cjs/tools/index.js.map +1 -1
- package/dist/cjs/{types-CWK2p9_n.d.ts → types-CwwW_c2B.d.ts} +5 -1
- package/dist/esm/{chunk-5IVOABVF.mjs → chunk-5UOBQKXW.mjs} +410 -2
- package/dist/esm/chunk-5UOBQKXW.mjs.map +1 -0
- package/dist/esm/{chunk-U2V6MOSU.mjs → chunk-KTG47TRY.mjs} +123 -4
- package/dist/esm/chunk-KTG47TRY.mjs.map +1 -0
- package/dist/esm/index.d.mts +3 -2
- package/dist/esm/index.mjs +2 -2
- package/dist/esm/server/index.d.mts +31 -1
- package/dist/esm/server/index.mjs +2 -2
- package/dist/esm/tools/index.d.mts +403 -3
- package/dist/esm/tools/index.mjs +45 -3
- package/dist/esm/{types-CWK2p9_n.d.mts → types-CwwW_c2B.d.mts} +5 -1
- package/package.json +16 -14
- package/dist/esm/chunk-5IVOABVF.mjs.map +0 -1
- package/dist/esm/chunk-U2V6MOSU.mjs.map +0 -1
package/bin/t402-mcp.js
CHANGED
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
* T402_DEMO_MODE - Set to "true" to simulate transactions
|
|
15
15
|
* T402_BUNDLER_URL - ERC-4337 bundler URL for gasless transactions
|
|
16
16
|
* T402_PAYMASTER_URL - Paymaster URL for gasless transactions
|
|
17
|
+
* T402_WDK_SEED_PHRASE - WDK seed phrase (enables wallet tools)
|
|
18
|
+
* T402_WDK_CHAINS - Comma-separated chains for WDK (default: ethereum,arbitrum,base)
|
|
17
19
|
* T402_RPC_ETHEREUM - Custom RPC URL for Ethereum
|
|
18
20
|
* T402_RPC_BASE - Custom RPC URL for Base
|
|
19
21
|
* T402_RPC_ARBITRUM - Custom RPC URL for Arbitrum
|
|
@@ -31,15 +33,23 @@ async function main() {
|
|
|
31
33
|
console.error(` Demo Mode: ${config.demoMode ? 'enabled' : 'disabled'}`)
|
|
32
34
|
console.error(` Bundler URL: ${config.bundlerUrl ? 'configured' : 'not set'}`)
|
|
33
35
|
console.error(` Paymaster URL: ${config.paymasterUrl ? 'configured' : 'not set'}`)
|
|
36
|
+
console.error(` WDK Seed Phrase: ${config.seedPhrase ? 'configured' : 'not set'}`)
|
|
37
|
+
console.error(` WDK Chains: ${config.wdkChains ? config.wdkChains.join(', ') : 'default (ethereum, arbitrum, base)'}`)
|
|
34
38
|
|
|
35
39
|
if (config.rpcUrls) {
|
|
36
40
|
console.error(` Custom RPC URLs: ${Object.keys(config.rpcUrls).join(', ')}`)
|
|
37
41
|
}
|
|
38
42
|
|
|
39
|
-
if (
|
|
43
|
+
if (config.seedPhrase || config.demoMode) {
|
|
44
|
+
console.error(' WDK Tools: enabled (wdk/getWallet, wdk/getBalances, wdk/transfer, wdk/swap, t402/autoPay)')
|
|
45
|
+
} else {
|
|
46
|
+
console.error(' WDK Tools: disabled (set T402_WDK_SEED_PHRASE to enable)')
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (!config.privateKey && !config.demoMode && !config.seedPhrase) {
|
|
40
50
|
console.error('')
|
|
41
|
-
console.error('Warning: No private key configured.')
|
|
42
|
-
console.error('Set T402_PRIVATE_KEY env var or enable T402_DEMO_MODE=true')
|
|
51
|
+
console.error('Warning: No private key or seed phrase configured.')
|
|
52
|
+
console.error('Set T402_PRIVATE_KEY or T402_WDK_SEED_PHRASE env var, or enable T402_DEMO_MODE=true')
|
|
43
53
|
console.error('')
|
|
44
54
|
}
|
|
45
55
|
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export { T402McpServer, createT402McpServer, loadConfigFromEnv } from './server/index.js';
|
|
2
2
|
export { AllBalancesResult, BridgeInput, BridgeOptions, GASLESS_SUPPORTED_NETWORKS, GetAllBalancesInput, GetBalanceInput, GetBridgeFeeInput, PayGaslessInput, PayGaslessOptions, PayInput, PayOptions, TOOL_DEFINITIONS, bridgeInputSchema, executeBridge, executeGetAllBalances, executeGetBalance, executeGetBridgeFee, executePay, executePayGasless, formatAllBalancesResult, formatBalanceResult, formatBridgeFeeResult, formatBridgeResult, formatGaslessPaymentResult, formatPaymentResult, getAllBalancesInputSchema, getBalanceInputSchema, getBridgeFeeInputSchema, payGaslessInputSchema, payInputSchema } from './tools/index.js';
|
|
3
|
-
import { S as SupportedNetwork } from './types-
|
|
4
|
-
export { B as BridgeFeeQuote,
|
|
3
|
+
import { S as SupportedNetwork } from './types-CwwW_c2B.js';
|
|
4
|
+
export { B as BridgeFeeQuote, a as BridgeResult, C as ChainBalance, G as GaslessPaymentResult, M as McpServerConfig, P as PaymentParams, b as PaymentResult, T as TokenBalance, c as ToolContext } from './types-CwwW_c2B.js';
|
|
5
5
|
import { Address } from 'viem';
|
|
6
6
|
import 'zod';
|
|
7
|
+
import '@t402/wdk';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Constants and network configurations for t402 MCP Server
|
package/dist/cjs/index.js
CHANGED
|
@@ -1196,6 +1196,289 @@ function formatBridgeResult(result) {
|
|
|
1196
1196
|
].join("\n");
|
|
1197
1197
|
}
|
|
1198
1198
|
|
|
1199
|
+
// src/tools/wdkGetWallet.ts
|
|
1200
|
+
var import_zod7 = require("zod");
|
|
1201
|
+
var wdkGetWalletInputSchema = import_zod7.z.object({});
|
|
1202
|
+
async function executeWdkGetWallet(_input, wdk) {
|
|
1203
|
+
const signer = await wdk.getSigner("ethereum");
|
|
1204
|
+
const chains6 = wdk.getConfiguredChains();
|
|
1205
|
+
return {
|
|
1206
|
+
evmAddress: signer.address,
|
|
1207
|
+
chains: chains6.length > 0 ? chains6 : ["ethereum"]
|
|
1208
|
+
};
|
|
1209
|
+
}
|
|
1210
|
+
function executeWdkGetWalletDemo() {
|
|
1211
|
+
return {
|
|
1212
|
+
evmAddress: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
|
|
1213
|
+
chains: ["ethereum", "arbitrum", "base", "optimism"]
|
|
1214
|
+
};
|
|
1215
|
+
}
|
|
1216
|
+
function formatWdkWalletResult(info) {
|
|
1217
|
+
const lines = [
|
|
1218
|
+
"## WDK Wallet Info",
|
|
1219
|
+
"",
|
|
1220
|
+
`**EVM Address:** \`${info.evmAddress}\``,
|
|
1221
|
+
"",
|
|
1222
|
+
"### Supported Chains",
|
|
1223
|
+
...info.chains.map((c) => `- ${c}`)
|
|
1224
|
+
];
|
|
1225
|
+
return lines.join("\n");
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1228
|
+
// src/tools/wdkGetBalances.ts
|
|
1229
|
+
var import_zod8 = require("zod");
|
|
1230
|
+
var import_viem6 = require("viem");
|
|
1231
|
+
var wdkGetBalancesInputSchema = import_zod8.z.object({
|
|
1232
|
+
chains: import_zod8.z.array(import_zod8.z.string()).optional().describe("Optional list of chains to check. If not provided, checks all configured chains.")
|
|
1233
|
+
});
|
|
1234
|
+
function findTokenFormatted(tokens, symbol) {
|
|
1235
|
+
return tokens.find((t) => t.symbol === symbol)?.formatted ?? "0";
|
|
1236
|
+
}
|
|
1237
|
+
async function executeWdkGetBalances(input, wdk) {
|
|
1238
|
+
const balances = await wdk.getAggregatedBalances();
|
|
1239
|
+
const chains6 = balances.chains.filter((c) => !input.chains || input.chains.includes(c.chain)).map((c) => ({
|
|
1240
|
+
chain: c.chain,
|
|
1241
|
+
usdt0: findTokenFormatted(c.tokens, "USDT0"),
|
|
1242
|
+
usdc: findTokenFormatted(c.tokens, "USDC"),
|
|
1243
|
+
native: (0, import_viem6.formatUnits)(c.native, 18)
|
|
1244
|
+
}));
|
|
1245
|
+
return {
|
|
1246
|
+
chains: chains6,
|
|
1247
|
+
totalUsdt0: (0, import_viem6.formatUnits)(balances.totalUsdt0, 6),
|
|
1248
|
+
totalUsdc: (0, import_viem6.formatUnits)(balances.totalUsdc, 6)
|
|
1249
|
+
};
|
|
1250
|
+
}
|
|
1251
|
+
function executeWdkGetBalancesDemo() {
|
|
1252
|
+
return {
|
|
1253
|
+
chains: [
|
|
1254
|
+
{ chain: "ethereum", usdt0: "100.00", usdc: "250.00", native: "0.5" },
|
|
1255
|
+
{ chain: "arbitrum", usdt0: "500.00", usdc: "0", native: "0.01" },
|
|
1256
|
+
{ chain: "base", usdt0: "200.00", usdc: "100.00", native: "0.02" }
|
|
1257
|
+
],
|
|
1258
|
+
totalUsdt0: "800.00",
|
|
1259
|
+
totalUsdc: "350.00"
|
|
1260
|
+
};
|
|
1261
|
+
}
|
|
1262
|
+
function formatWdkBalancesResult(result) {
|
|
1263
|
+
const lines = [
|
|
1264
|
+
"## WDK Multi-Chain Balances",
|
|
1265
|
+
"",
|
|
1266
|
+
`**Total USDT0:** ${result.totalUsdt0}`,
|
|
1267
|
+
`**Total USDC:** ${result.totalUsdc}`,
|
|
1268
|
+
"",
|
|
1269
|
+
"### Per-Chain Breakdown",
|
|
1270
|
+
""
|
|
1271
|
+
];
|
|
1272
|
+
for (const chain of result.chains) {
|
|
1273
|
+
lines.push(`**${chain.chain}**`);
|
|
1274
|
+
lines.push(`- USDT0: ${chain.usdt0}`);
|
|
1275
|
+
lines.push(`- USDC: ${chain.usdc}`);
|
|
1276
|
+
lines.push(`- Native: ${chain.native}`);
|
|
1277
|
+
lines.push("");
|
|
1278
|
+
}
|
|
1279
|
+
return lines.join("\n");
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
// src/tools/wdkTransfer.ts
|
|
1283
|
+
var import_zod9 = require("zod");
|
|
1284
|
+
var wdkTransferInputSchema = import_zod9.z.object({
|
|
1285
|
+
to: import_zod9.z.string().describe("Recipient address"),
|
|
1286
|
+
amount: import_zod9.z.string().regex(/^\d+(\.\d+)?$/).describe("Amount to send (e.g., '10.50')"),
|
|
1287
|
+
token: import_zod9.z.enum(["USDC", "USDT", "USDT0"]).describe("Token to transfer"),
|
|
1288
|
+
chain: import_zod9.z.string().describe('Chain to execute transfer on (e.g., "ethereum", "arbitrum")')
|
|
1289
|
+
});
|
|
1290
|
+
async function executeWdkTransfer(input, wdk) {
|
|
1291
|
+
const signer = await wdk.getSigner(input.chain);
|
|
1292
|
+
const result = await signer.sendTransaction({
|
|
1293
|
+
to: input.to
|
|
1294
|
+
});
|
|
1295
|
+
const txHash = result.hash;
|
|
1296
|
+
const explorerUrl = getExplorerTxUrl(input.chain, txHash);
|
|
1297
|
+
return {
|
|
1298
|
+
txHash,
|
|
1299
|
+
amount: input.amount,
|
|
1300
|
+
token: input.token,
|
|
1301
|
+
chain: input.chain,
|
|
1302
|
+
to: input.to,
|
|
1303
|
+
explorerUrl
|
|
1304
|
+
};
|
|
1305
|
+
}
|
|
1306
|
+
function executeWdkTransferDemo(input) {
|
|
1307
|
+
const demoTxHash = "0xdemo" + Math.random().toString(16).slice(2, 10);
|
|
1308
|
+
return {
|
|
1309
|
+
txHash: demoTxHash,
|
|
1310
|
+
amount: input.amount,
|
|
1311
|
+
token: input.token,
|
|
1312
|
+
chain: input.chain,
|
|
1313
|
+
to: input.to,
|
|
1314
|
+
explorerUrl: `https://etherscan.io/tx/${demoTxHash}`
|
|
1315
|
+
};
|
|
1316
|
+
}
|
|
1317
|
+
function formatWdkTransferResult(result) {
|
|
1318
|
+
return [
|
|
1319
|
+
"## WDK Transfer Complete",
|
|
1320
|
+
"",
|
|
1321
|
+
`**Amount:** ${result.amount} ${result.token}`,
|
|
1322
|
+
`**Chain:** ${result.chain}`,
|
|
1323
|
+
`**To:** \`${result.to}\``,
|
|
1324
|
+
`**Tx Hash:** \`${result.txHash}\``,
|
|
1325
|
+
`**Explorer:** [View Transaction](${result.explorerUrl})`
|
|
1326
|
+
].join("\n");
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
// src/tools/wdkSwap.ts
|
|
1330
|
+
var import_zod10 = require("zod");
|
|
1331
|
+
var import_viem7 = require("viem");
|
|
1332
|
+
var wdkSwapInputSchema = import_zod10.z.object({
|
|
1333
|
+
fromToken: import_zod10.z.string().describe('Token to swap from (e.g., "ETH", "USDC")'),
|
|
1334
|
+
toToken: import_zod10.z.string().describe('Token to swap to (e.g., "USDT0", "USDC")'),
|
|
1335
|
+
amount: import_zod10.z.string().regex(/^\d+(\.\d+)?$/).describe("Amount to swap (e.g., '1.0')"),
|
|
1336
|
+
chain: import_zod10.z.string().describe('Chain to execute swap on (e.g., "ethereum", "arbitrum")')
|
|
1337
|
+
});
|
|
1338
|
+
async function executeWdkSwap(input, wdk) {
|
|
1339
|
+
const decimals = ["USDC", "USDT", "USDT0"].includes(input.fromToken.toUpperCase()) ? 6 : 18;
|
|
1340
|
+
const amountBigInt = (0, import_viem7.parseUnits)(input.amount, decimals);
|
|
1341
|
+
const quote = await wdk.getSwapQuote(input.chain, input.fromToken, amountBigInt);
|
|
1342
|
+
const result = await wdk.swapAndPay({
|
|
1343
|
+
chain: input.chain,
|
|
1344
|
+
fromToken: input.fromToken,
|
|
1345
|
+
amount: amountBigInt
|
|
1346
|
+
});
|
|
1347
|
+
const outputDecimals = ["USDC", "USDT", "USDT0"].includes(input.toToken.toUpperCase()) ? 6 : 18;
|
|
1348
|
+
const toAmount = (0, import_viem7.formatUnits)(result?.outputAmount ?? quote.outputAmount, outputDecimals);
|
|
1349
|
+
return {
|
|
1350
|
+
fromAmount: input.amount,
|
|
1351
|
+
fromToken: input.fromToken,
|
|
1352
|
+
toAmount,
|
|
1353
|
+
toToken: input.toToken,
|
|
1354
|
+
chain: input.chain,
|
|
1355
|
+
txHash: result?.txHash
|
|
1356
|
+
};
|
|
1357
|
+
}
|
|
1358
|
+
function executeWdkSwapDemo(input) {
|
|
1359
|
+
const inputAmount = parseFloat(input.amount);
|
|
1360
|
+
const outputAmount = (inputAmount * 0.997).toFixed(6);
|
|
1361
|
+
return {
|
|
1362
|
+
fromAmount: input.amount,
|
|
1363
|
+
fromToken: input.fromToken,
|
|
1364
|
+
toAmount: outputAmount,
|
|
1365
|
+
toToken: input.toToken,
|
|
1366
|
+
chain: input.chain,
|
|
1367
|
+
txHash: "0xdemo" + Math.random().toString(16).slice(2, 10)
|
|
1368
|
+
};
|
|
1369
|
+
}
|
|
1370
|
+
function formatWdkSwapResult(result) {
|
|
1371
|
+
const lines = [
|
|
1372
|
+
"## WDK Swap Result",
|
|
1373
|
+
"",
|
|
1374
|
+
`**From:** ${result.fromAmount} ${result.fromToken}`,
|
|
1375
|
+
`**To:** ${result.toAmount} ${result.toToken}`,
|
|
1376
|
+
`**Chain:** ${result.chain}`
|
|
1377
|
+
];
|
|
1378
|
+
if (result.txHash) {
|
|
1379
|
+
lines.push(`**Tx Hash:** \`${result.txHash}\``);
|
|
1380
|
+
}
|
|
1381
|
+
return lines.join("\n");
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1384
|
+
// src/tools/autoPay.ts
|
|
1385
|
+
var import_zod11 = require("zod");
|
|
1386
|
+
var import_wdk_protocol = require("@t402/wdk-protocol");
|
|
1387
|
+
var autoPayInputSchema = import_zod11.z.object({
|
|
1388
|
+
url: import_zod11.z.string().url().describe("URL to fetch (may return 402 Payment Required)"),
|
|
1389
|
+
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.'),
|
|
1390
|
+
preferredChain: import_zod11.z.string().optional().describe(
|
|
1391
|
+
'Preferred chain for payment (e.g., "arbitrum"). If not specified, uses first available.'
|
|
1392
|
+
)
|
|
1393
|
+
});
|
|
1394
|
+
async function executeAutoPay(input, wdk) {
|
|
1395
|
+
const chains6 = input.preferredChain ? [input.preferredChain] : ["ethereum", "arbitrum", "base"];
|
|
1396
|
+
const protocol = await import_wdk_protocol.T402Protocol.create(wdk, { chains: chains6 });
|
|
1397
|
+
const { response, receipt } = await protocol.fetch(input.url);
|
|
1398
|
+
if (receipt && input.maxAmount) {
|
|
1399
|
+
const paidAmount = parseFloat(receipt.amount) / 1e6;
|
|
1400
|
+
const maxAmount = parseFloat(input.maxAmount);
|
|
1401
|
+
if (paidAmount > maxAmount) {
|
|
1402
|
+
return {
|
|
1403
|
+
success: false,
|
|
1404
|
+
statusCode: 402,
|
|
1405
|
+
body: "",
|
|
1406
|
+
error: `Payment amount (${paidAmount}) exceeds max allowed (${maxAmount})`
|
|
1407
|
+
};
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
const contentType = response.headers.get("content-type") ?? void 0;
|
|
1411
|
+
let body = "";
|
|
1412
|
+
try {
|
|
1413
|
+
body = await response.text();
|
|
1414
|
+
if (body.length > 1e4) {
|
|
1415
|
+
body = body.slice(0, 1e4) + "\n... (truncated)";
|
|
1416
|
+
}
|
|
1417
|
+
} catch {
|
|
1418
|
+
body = "[Could not read response body]";
|
|
1419
|
+
}
|
|
1420
|
+
return {
|
|
1421
|
+
success: response.ok,
|
|
1422
|
+
statusCode: response.status,
|
|
1423
|
+
body,
|
|
1424
|
+
contentType,
|
|
1425
|
+
payment: receipt ? {
|
|
1426
|
+
network: receipt.network,
|
|
1427
|
+
scheme: receipt.scheme,
|
|
1428
|
+
amount: receipt.amount,
|
|
1429
|
+
payTo: receipt.payTo
|
|
1430
|
+
} : void 0
|
|
1431
|
+
};
|
|
1432
|
+
}
|
|
1433
|
+
function executeAutoPayDemo(input) {
|
|
1434
|
+
return {
|
|
1435
|
+
success: true,
|
|
1436
|
+
statusCode: 200,
|
|
1437
|
+
body: `[Demo] Premium content from ${input.url}
|
|
1438
|
+
|
|
1439
|
+
This is simulated content that would be returned after payment.`,
|
|
1440
|
+
contentType: "text/plain",
|
|
1441
|
+
payment: {
|
|
1442
|
+
network: "eip155:42161",
|
|
1443
|
+
scheme: "exact",
|
|
1444
|
+
amount: "1000000",
|
|
1445
|
+
payTo: "0xC88f67e776f16DcFBf42e6bDda1B82604448899B"
|
|
1446
|
+
}
|
|
1447
|
+
};
|
|
1448
|
+
}
|
|
1449
|
+
function formatAutoPayResult(result) {
|
|
1450
|
+
const lines = ["## AutoPay Result", ""];
|
|
1451
|
+
if (result.success) {
|
|
1452
|
+
lines.push(`**Status:** Success (${result.statusCode})`);
|
|
1453
|
+
} else {
|
|
1454
|
+
lines.push(`**Status:** Failed (${result.statusCode})`);
|
|
1455
|
+
}
|
|
1456
|
+
if (result.payment) {
|
|
1457
|
+
lines.push("");
|
|
1458
|
+
lines.push("### Payment Details");
|
|
1459
|
+
lines.push(`- **Network:** ${result.payment.network}`);
|
|
1460
|
+
lines.push(`- **Scheme:** ${result.payment.scheme}`);
|
|
1461
|
+
lines.push(`- **Amount:** ${result.payment.amount}`);
|
|
1462
|
+
lines.push(`- **Pay To:** \`${result.payment.payTo}\``);
|
|
1463
|
+
}
|
|
1464
|
+
if (result.error) {
|
|
1465
|
+
lines.push("");
|
|
1466
|
+
lines.push(`**Error:** ${result.error}`);
|
|
1467
|
+
}
|
|
1468
|
+
if (result.body) {
|
|
1469
|
+
lines.push("");
|
|
1470
|
+
lines.push("### Response Content");
|
|
1471
|
+
if (result.contentType) {
|
|
1472
|
+
lines.push(`_Content-Type: ${result.contentType}_`);
|
|
1473
|
+
}
|
|
1474
|
+
lines.push("");
|
|
1475
|
+
lines.push("```");
|
|
1476
|
+
lines.push(result.body);
|
|
1477
|
+
lines.push("```");
|
|
1478
|
+
}
|
|
1479
|
+
return lines.join("\n");
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1199
1482
|
// src/tools/index.ts
|
|
1200
1483
|
var TOOL_DEFINITIONS = {
|
|
1201
1484
|
"t402/getBalance": {
|
|
@@ -1396,12 +1679,117 @@ var TOOL_DEFINITIONS = {
|
|
|
1396
1679
|
}
|
|
1397
1680
|
}
|
|
1398
1681
|
};
|
|
1682
|
+
var WDK_TOOL_DEFINITIONS = {
|
|
1683
|
+
"wdk/getWallet": {
|
|
1684
|
+
name: "wdk/getWallet",
|
|
1685
|
+
description: "Get wallet information from the configured WDK wallet. Returns EVM address and supported chains. No parameters needed.",
|
|
1686
|
+
inputSchema: {
|
|
1687
|
+
type: "object",
|
|
1688
|
+
properties: {},
|
|
1689
|
+
required: []
|
|
1690
|
+
}
|
|
1691
|
+
},
|
|
1692
|
+
"wdk/getBalances": {
|
|
1693
|
+
name: "wdk/getBalances",
|
|
1694
|
+
description: "Get multi-chain token balances from the WDK wallet. Returns USDT0, USDC, and native token balances per chain plus aggregated totals.",
|
|
1695
|
+
inputSchema: {
|
|
1696
|
+
type: "object",
|
|
1697
|
+
properties: {
|
|
1698
|
+
chains: {
|
|
1699
|
+
type: "array",
|
|
1700
|
+
items: { type: "string" },
|
|
1701
|
+
description: 'Optional list of chains to check (e.g., ["ethereum", "arbitrum"]). If not provided, checks all configured chains.'
|
|
1702
|
+
}
|
|
1703
|
+
},
|
|
1704
|
+
required: []
|
|
1705
|
+
}
|
|
1706
|
+
},
|
|
1707
|
+
"wdk/transfer": {
|
|
1708
|
+
name: "wdk/transfer",
|
|
1709
|
+
description: "Send stablecoins (USDC, USDT, USDT0) from the WDK wallet to a recipient address on a specific chain.",
|
|
1710
|
+
inputSchema: {
|
|
1711
|
+
type: "object",
|
|
1712
|
+
properties: {
|
|
1713
|
+
to: {
|
|
1714
|
+
type: "string",
|
|
1715
|
+
description: "Recipient address"
|
|
1716
|
+
},
|
|
1717
|
+
amount: {
|
|
1718
|
+
type: "string",
|
|
1719
|
+
pattern: "^\\d+(\\.\\d+)?$",
|
|
1720
|
+
description: "Amount to send (e.g., '10.50')"
|
|
1721
|
+
},
|
|
1722
|
+
token: {
|
|
1723
|
+
type: "string",
|
|
1724
|
+
enum: ["USDC", "USDT", "USDT0"],
|
|
1725
|
+
description: "Token to transfer"
|
|
1726
|
+
},
|
|
1727
|
+
chain: {
|
|
1728
|
+
type: "string",
|
|
1729
|
+
description: 'Chain to execute transfer on (e.g., "ethereum", "arbitrum")'
|
|
1730
|
+
}
|
|
1731
|
+
},
|
|
1732
|
+
required: ["to", "amount", "token", "chain"]
|
|
1733
|
+
}
|
|
1734
|
+
},
|
|
1735
|
+
"wdk/swap": {
|
|
1736
|
+
name: "wdk/swap",
|
|
1737
|
+
description: "Swap tokens using the WDK Velora protocol. Supports swapping between stablecoins and native tokens.",
|
|
1738
|
+
inputSchema: {
|
|
1739
|
+
type: "object",
|
|
1740
|
+
properties: {
|
|
1741
|
+
fromToken: {
|
|
1742
|
+
type: "string",
|
|
1743
|
+
description: 'Token to swap from (e.g., "ETH", "USDC")'
|
|
1744
|
+
},
|
|
1745
|
+
toToken: {
|
|
1746
|
+
type: "string",
|
|
1747
|
+
description: 'Token to swap to (e.g., "USDT0", "USDC")'
|
|
1748
|
+
},
|
|
1749
|
+
amount: {
|
|
1750
|
+
type: "string",
|
|
1751
|
+
pattern: "^\\d+(\\.\\d+)?$",
|
|
1752
|
+
description: "Amount to swap (e.g., '1.0')"
|
|
1753
|
+
},
|
|
1754
|
+
chain: {
|
|
1755
|
+
type: "string",
|
|
1756
|
+
description: 'Chain to execute swap on (e.g., "ethereum", "arbitrum")'
|
|
1757
|
+
}
|
|
1758
|
+
},
|
|
1759
|
+
required: ["fromToken", "toToken", "amount", "chain"]
|
|
1760
|
+
}
|
|
1761
|
+
},
|
|
1762
|
+
"t402/autoPay": {
|
|
1763
|
+
name: "t402/autoPay",
|
|
1764
|
+
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.",
|
|
1765
|
+
inputSchema: {
|
|
1766
|
+
type: "object",
|
|
1767
|
+
properties: {
|
|
1768
|
+
url: {
|
|
1769
|
+
type: "string",
|
|
1770
|
+
description: "URL to fetch (may return 402 Payment Required)"
|
|
1771
|
+
},
|
|
1772
|
+
maxAmount: {
|
|
1773
|
+
type: "string",
|
|
1774
|
+
pattern: "^\\d+(\\.\\d+)?$",
|
|
1775
|
+
description: 'Maximum amount willing to pay (e.g., "10.00"). If not set, pays any amount.'
|
|
1776
|
+
},
|
|
1777
|
+
preferredChain: {
|
|
1778
|
+
type: "string",
|
|
1779
|
+
description: 'Preferred chain for payment (e.g., "arbitrum"). If not specified, uses first available.'
|
|
1780
|
+
}
|
|
1781
|
+
},
|
|
1782
|
+
required: ["url"]
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
};
|
|
1399
1786
|
|
|
1400
1787
|
// src/server/t402Server.ts
|
|
1401
1788
|
var T402McpServer = class {
|
|
1402
1789
|
constructor(config = {}) {
|
|
1403
1790
|
__publicField(this, "server");
|
|
1404
1791
|
__publicField(this, "config");
|
|
1792
|
+
__publicField(this, "wdk", null);
|
|
1405
1793
|
this.config = config;
|
|
1406
1794
|
this.server = new import_server.Server(
|
|
1407
1795
|
{
|
|
@@ -1416,13 +1804,41 @@ var T402McpServer = class {
|
|
|
1416
1804
|
);
|
|
1417
1805
|
this.setupHandlers();
|
|
1418
1806
|
}
|
|
1807
|
+
/**
|
|
1808
|
+
* Initialize the WDK instance from seed phrase
|
|
1809
|
+
*/
|
|
1810
|
+
async initWdk() {
|
|
1811
|
+
if (!this.config.seedPhrase) return;
|
|
1812
|
+
try {
|
|
1813
|
+
const { T402WDK } = await import("@t402/wdk");
|
|
1814
|
+
const rpcUrls = {};
|
|
1815
|
+
if (this.config.rpcUrls) {
|
|
1816
|
+
for (const [network, url] of Object.entries(this.config.rpcUrls)) {
|
|
1817
|
+
if (url) rpcUrls[network] = url;
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
this.wdk = new T402WDK(this.config.seedPhrase, rpcUrls);
|
|
1821
|
+
} catch {
|
|
1822
|
+
console.error("Warning: Failed to initialize WDK. WDK tools will not be available.");
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1825
|
+
/**
|
|
1826
|
+
* Get all tool definitions (base + WDK if configured)
|
|
1827
|
+
*/
|
|
1828
|
+
getToolDefinitions() {
|
|
1829
|
+
const tools = { ...TOOL_DEFINITIONS };
|
|
1830
|
+
if (this.wdk || this.config.demoMode) {
|
|
1831
|
+
Object.assign(tools, WDK_TOOL_DEFINITIONS);
|
|
1832
|
+
}
|
|
1833
|
+
return tools;
|
|
1834
|
+
}
|
|
1419
1835
|
/**
|
|
1420
1836
|
* Set up MCP request handlers
|
|
1421
1837
|
*/
|
|
1422
1838
|
setupHandlers() {
|
|
1423
1839
|
this.server.setRequestHandler(import_types.ListToolsRequestSchema, async () => {
|
|
1424
1840
|
return {
|
|
1425
|
-
tools: Object.values(
|
|
1841
|
+
tools: Object.values(this.getToolDefinitions())
|
|
1426
1842
|
};
|
|
1427
1843
|
});
|
|
1428
1844
|
this.server.setRequestHandler(import_types.CallToolRequestSchema, async (request) => {
|
|
@@ -1441,6 +1857,17 @@ var T402McpServer = class {
|
|
|
1441
1857
|
return await this.handleGetBridgeFee(args);
|
|
1442
1858
|
case "t402/bridge":
|
|
1443
1859
|
return await this.handleBridge(args);
|
|
1860
|
+
// WDK tools
|
|
1861
|
+
case "wdk/getWallet":
|
|
1862
|
+
return await this.handleWdkGetWallet(args);
|
|
1863
|
+
case "wdk/getBalances":
|
|
1864
|
+
return await this.handleWdkGetBalances(args);
|
|
1865
|
+
case "wdk/transfer":
|
|
1866
|
+
return await this.handleWdkTransfer(args);
|
|
1867
|
+
case "wdk/swap":
|
|
1868
|
+
return await this.handleWdkSwap(args);
|
|
1869
|
+
case "t402/autoPay":
|
|
1870
|
+
return await this.handleAutoPay(args);
|
|
1444
1871
|
default:
|
|
1445
1872
|
throw new Error(`Unknown tool: ${name}`);
|
|
1446
1873
|
}
|
|
@@ -1587,10 +2014,62 @@ var T402McpServer = class {
|
|
|
1587
2014
|
]
|
|
1588
2015
|
};
|
|
1589
2016
|
}
|
|
2017
|
+
// ---- WDK Tool Handlers ----
|
|
2018
|
+
/**
|
|
2019
|
+
* Handle wdk/getWallet
|
|
2020
|
+
*/
|
|
2021
|
+
async handleWdkGetWallet(args) {
|
|
2022
|
+
wdkGetWalletInputSchema.parse(args);
|
|
2023
|
+
const result = this.config.demoMode || !this.wdk ? executeWdkGetWalletDemo() : await executeWdkGetWallet({}, this.wdk);
|
|
2024
|
+
return {
|
|
2025
|
+
content: [{ type: "text", text: formatWdkWalletResult(result) }]
|
|
2026
|
+
};
|
|
2027
|
+
}
|
|
2028
|
+
/**
|
|
2029
|
+
* Handle wdk/getBalances
|
|
2030
|
+
*/
|
|
2031
|
+
async handleWdkGetBalances(args) {
|
|
2032
|
+
const input = wdkGetBalancesInputSchema.parse(args);
|
|
2033
|
+
const result = this.config.demoMode || !this.wdk ? executeWdkGetBalancesDemo() : await executeWdkGetBalances(input, this.wdk);
|
|
2034
|
+
return {
|
|
2035
|
+
content: [{ type: "text", text: formatWdkBalancesResult(result) }]
|
|
2036
|
+
};
|
|
2037
|
+
}
|
|
2038
|
+
/**
|
|
2039
|
+
* Handle wdk/transfer
|
|
2040
|
+
*/
|
|
2041
|
+
async handleWdkTransfer(args) {
|
|
2042
|
+
const input = wdkTransferInputSchema.parse(args);
|
|
2043
|
+
const result = this.config.demoMode || !this.wdk ? executeWdkTransferDemo(input) : await executeWdkTransfer(input, this.wdk);
|
|
2044
|
+
return {
|
|
2045
|
+
content: [{ type: "text", text: formatWdkTransferResult(result) }]
|
|
2046
|
+
};
|
|
2047
|
+
}
|
|
2048
|
+
/**
|
|
2049
|
+
* Handle wdk/swap
|
|
2050
|
+
*/
|
|
2051
|
+
async handleWdkSwap(args) {
|
|
2052
|
+
const input = wdkSwapInputSchema.parse(args);
|
|
2053
|
+
const result = this.config.demoMode || !this.wdk ? executeWdkSwapDemo(input) : await executeWdkSwap(input, this.wdk);
|
|
2054
|
+
return {
|
|
2055
|
+
content: [{ type: "text", text: formatWdkSwapResult(result) }]
|
|
2056
|
+
};
|
|
2057
|
+
}
|
|
2058
|
+
/**
|
|
2059
|
+
* Handle t402/autoPay
|
|
2060
|
+
*/
|
|
2061
|
+
async handleAutoPay(args) {
|
|
2062
|
+
const input = autoPayInputSchema.parse(args);
|
|
2063
|
+
const result = this.config.demoMode || !this.wdk ? executeAutoPayDemo(input) : await executeAutoPay(input, this.wdk);
|
|
2064
|
+
return {
|
|
2065
|
+
content: [{ type: "text", text: formatAutoPayResult(result) }]
|
|
2066
|
+
};
|
|
2067
|
+
}
|
|
1590
2068
|
/**
|
|
1591
2069
|
* Start the server using stdio transport
|
|
1592
2070
|
*/
|
|
1593
2071
|
async run() {
|
|
2072
|
+
await this.initWdk();
|
|
1594
2073
|
const transport = new import_stdio.StdioServerTransport();
|
|
1595
2074
|
await this.server.connect(transport);
|
|
1596
2075
|
console.error("t402 MCP Server running on stdio");
|
|
@@ -1613,6 +2092,12 @@ function loadConfigFromEnv() {
|
|
|
1613
2092
|
if (process.env.T402_PAYMASTER_URL) {
|
|
1614
2093
|
config.paymasterUrl = process.env.T402_PAYMASTER_URL;
|
|
1615
2094
|
}
|
|
2095
|
+
if (process.env.T402_WDK_SEED_PHRASE) {
|
|
2096
|
+
config.seedPhrase = process.env.T402_WDK_SEED_PHRASE;
|
|
2097
|
+
}
|
|
2098
|
+
if (process.env.T402_WDK_CHAINS) {
|
|
2099
|
+
config.wdkChains = process.env.T402_WDK_CHAINS.split(",").map((c) => c.trim());
|
|
2100
|
+
}
|
|
1616
2101
|
const rpcUrls = {};
|
|
1617
2102
|
const networks = [
|
|
1618
2103
|
"ethereum",
|