agentpay-mcp 1.2.0 → 3.1.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/.env.example +37 -0
- package/LICENSE +21 -0
- package/README.md +380 -31
- package/claude_desktop_config.json +17 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +166 -0
- package/dist/index.js.map +1 -0
- package/dist/session/manager.d.ts +90 -0
- package/dist/session/manager.d.ts.map +1 -0
- package/dist/session/manager.js +262 -0
- package/dist/session/manager.js.map +1 -0
- package/dist/session/types.d.ts +113 -0
- package/dist/session/types.d.ts.map +1 -0
- package/dist/session/types.js +16 -0
- package/dist/session/types.js.map +1 -0
- package/dist/tools/deploy.d.ts +49 -0
- package/dist/tools/deploy.d.ts.map +1 -0
- package/dist/tools/deploy.js +123 -0
- package/dist/tools/deploy.js.map +1 -0
- package/dist/tools/history.d.ts +59 -0
- package/dist/tools/history.d.ts.map +1 -0
- package/dist/tools/history.js +202 -0
- package/dist/tools/history.js.map +1 -0
- package/dist/tools/payments.d.ts +71 -0
- package/dist/tools/payments.d.ts.map +1 -0
- package/dist/tools/payments.js +158 -0
- package/dist/tools/payments.js.map +1 -0
- package/dist/tools/session.d.ts +240 -0
- package/dist/tools/session.d.ts.map +1 -0
- package/dist/tools/session.js +678 -0
- package/dist/tools/session.js.map +1 -0
- package/dist/tools/wallet.d.ts +107 -0
- package/dist/tools/wallet.d.ts.map +1 -0
- package/dist/tools/wallet.js +271 -0
- package/dist/tools/wallet.js.map +1 -0
- package/dist/tools/x402.d.ts +90 -0
- package/dist/tools/x402.d.ts.map +1 -0
- package/dist/tools/x402.js +268 -0
- package/dist/tools/x402.js.map +1 -0
- package/dist/utils/client.d.ts +46 -0
- package/dist/utils/client.d.ts.map +1 -0
- package/dist/utils/client.js +123 -0
- package/dist/utils/client.js.map +1 -0
- package/dist/utils/format.d.ts +59 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js +161 -0
- package/dist/utils/format.js.map +1 -0
- package/package.json +58 -12
- package/index.d.ts +0 -1
- package/index.js +0 -13
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.x402PayTool = exports.X402PaySchema = void 0;
|
|
4
|
+
exports.handleX402Pay = handleX402Pay;
|
|
5
|
+
/**
|
|
6
|
+
* x402.ts — x402_pay tool.
|
|
7
|
+
*
|
|
8
|
+
* Fetches a URL, automatically handling 402 Payment Required responses
|
|
9
|
+
* by paying with the Agent Wallet and retrying the request.
|
|
10
|
+
*
|
|
11
|
+
* v1.1.0: Auto-session detection. If an active x402 V2 session covers the
|
|
12
|
+
* requested URL, session headers are injected and no new payment is made.
|
|
13
|
+
* Pass skip_session_check=true to force a fresh payment regardless.
|
|
14
|
+
*/
|
|
15
|
+
const zod_1 = require("zod");
|
|
16
|
+
const agentwallet_sdk_1 = require("agentwallet-sdk");
|
|
17
|
+
const client_js_1 = require("../utils/client.js");
|
|
18
|
+
const format_js_1 = require("../utils/format.js");
|
|
19
|
+
const session_js_1 = require("./session.js");
|
|
20
|
+
const manager_js_1 = require("../session/manager.js");
|
|
21
|
+
// ─── Schema ────────────────────────────────────────────────────────────────
|
|
22
|
+
exports.X402PaySchema = zod_1.z.object({
|
|
23
|
+
url: zod_1.z
|
|
24
|
+
.string()
|
|
25
|
+
.url()
|
|
26
|
+
.describe('URL to fetch. If it returns HTTP 402, payment is handled automatically.'),
|
|
27
|
+
method: zod_1.z
|
|
28
|
+
.enum(['GET', 'POST', 'PUT', 'PATCH', 'DELETE'])
|
|
29
|
+
.optional()
|
|
30
|
+
.default('GET')
|
|
31
|
+
.describe('HTTP method (default: GET)'),
|
|
32
|
+
headers: zod_1.z
|
|
33
|
+
.record(zod_1.z.string())
|
|
34
|
+
.optional()
|
|
35
|
+
.describe('Additional HTTP request headers as key-value pairs'),
|
|
36
|
+
body: zod_1.z
|
|
37
|
+
.string()
|
|
38
|
+
.optional()
|
|
39
|
+
.describe('Request body (for POST/PUT/PATCH). Use JSON string for JSON APIs.'),
|
|
40
|
+
max_payment_eth: zod_1.z
|
|
41
|
+
.string()
|
|
42
|
+
.optional()
|
|
43
|
+
.describe('Maximum ETH equivalent to pay for this request. ' +
|
|
44
|
+
'Rejects the payment if the required amount exceeds this. ' +
|
|
45
|
+
'E.g. "0.001" to cap at 0.001 ETH.'),
|
|
46
|
+
timeout_ms: zod_1.z
|
|
47
|
+
.number()
|
|
48
|
+
.int()
|
|
49
|
+
.min(1000)
|
|
50
|
+
.max(60000)
|
|
51
|
+
.optional()
|
|
52
|
+
.default(30000)
|
|
53
|
+
.describe('Request timeout in milliseconds (default: 30000, max: 60000)'),
|
|
54
|
+
skip_session_check: zod_1.z
|
|
55
|
+
.boolean()
|
|
56
|
+
.optional()
|
|
57
|
+
.default(false)
|
|
58
|
+
.describe('Skip auto-session detection and always make a fresh x402 payment. ' +
|
|
59
|
+
'Default: false. When false, if an active session covers this URL, ' +
|
|
60
|
+
'the session token is used instead of paying again (x402 V2 behaviour).'),
|
|
61
|
+
});
|
|
62
|
+
// ─── Tool definition ───────────────────────────────────────────────────────
|
|
63
|
+
exports.x402PayTool = {
|
|
64
|
+
name: 'x402_pay',
|
|
65
|
+
description: 'Fetch a URL and automatically handle HTTP 402 Payment Required responses. ' +
|
|
66
|
+
'If an active x402 V2 session covers this URL, the session token is used instead ' +
|
|
67
|
+
'of making a new payment (no on-chain cost). ' +
|
|
68
|
+
'If no session exists, the Agent Wallet pays the required amount and retries. ' +
|
|
69
|
+
'Payment is rejected if it exceeds your wallet\'s spend limits or the max_payment_eth cap. ' +
|
|
70
|
+
'Powered by the x402 protocol on Base network. ' +
|
|
71
|
+
'Tip: Use x402_session_start to pay once for a session and save on repeated calls.',
|
|
72
|
+
inputSchema: {
|
|
73
|
+
type: 'object',
|
|
74
|
+
properties: {
|
|
75
|
+
url: {
|
|
76
|
+
type: 'string',
|
|
77
|
+
description: 'URL to fetch (HTTP 402 responses are handled automatically)',
|
|
78
|
+
},
|
|
79
|
+
method: {
|
|
80
|
+
type: 'string',
|
|
81
|
+
enum: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'],
|
|
82
|
+
description: 'HTTP method (default: GET)',
|
|
83
|
+
default: 'GET',
|
|
84
|
+
},
|
|
85
|
+
headers: {
|
|
86
|
+
type: 'object',
|
|
87
|
+
additionalProperties: { type: 'string' },
|
|
88
|
+
description: 'Additional request headers',
|
|
89
|
+
},
|
|
90
|
+
body: {
|
|
91
|
+
type: 'string',
|
|
92
|
+
description: 'Request body string (for POST/PUT/PATCH)',
|
|
93
|
+
},
|
|
94
|
+
max_payment_eth: {
|
|
95
|
+
type: 'string',
|
|
96
|
+
description: 'Maximum payment cap in ETH (e.g. "0.001")',
|
|
97
|
+
},
|
|
98
|
+
timeout_ms: {
|
|
99
|
+
type: 'number',
|
|
100
|
+
description: 'Timeout in milliseconds (default: 30000)',
|
|
101
|
+
default: 30000,
|
|
102
|
+
},
|
|
103
|
+
skip_session_check: {
|
|
104
|
+
type: 'boolean',
|
|
105
|
+
description: 'Skip session auto-detection and force a fresh x402 payment',
|
|
106
|
+
default: false,
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
required: ['url'],
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
// ─── Handler ───────────────────────────────────────────────────────────────
|
|
113
|
+
async function handleX402Pay(input) {
|
|
114
|
+
try {
|
|
115
|
+
const wallet = (0, client_js_1.getWallet)();
|
|
116
|
+
const config = (0, client_js_1.getConfig)();
|
|
117
|
+
const timeoutMs = input.timeout_ms ?? 30000;
|
|
118
|
+
// ── Auto-session detection (x402 V2 behaviour) ──────────────────────
|
|
119
|
+
// If there's an active session for this URL and the caller hasn't
|
|
120
|
+
// explicitly asked to skip it, use the session token instead of paying.
|
|
121
|
+
if (!input.skip_session_check) {
|
|
122
|
+
const activeSession = (0, session_js_1.findSessionForUrl)(input.url);
|
|
123
|
+
if (activeSession) {
|
|
124
|
+
const sessionHeaders = (0, session_js_1.buildSessionHeaders)(activeSession);
|
|
125
|
+
const method = input.method ?? 'GET';
|
|
126
|
+
const mergedHeaders = {
|
|
127
|
+
'Accept': 'application/json, text/plain, */*',
|
|
128
|
+
...sessionHeaders,
|
|
129
|
+
...(input.headers ?? {}),
|
|
130
|
+
};
|
|
131
|
+
if (input.body && ['POST', 'PUT', 'PATCH'].includes(method)) {
|
|
132
|
+
if (!mergedHeaders['Content-Type']) {
|
|
133
|
+
mergedHeaders['Content-Type'] = 'application/json';
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const requestInit = {
|
|
137
|
+
method,
|
|
138
|
+
headers: mergedHeaders,
|
|
139
|
+
...(input.body ? { body: input.body } : {}),
|
|
140
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
141
|
+
};
|
|
142
|
+
const response = await fetch(input.url, requestInit);
|
|
143
|
+
// If server accepted the session (2xx/3xx), record it and return
|
|
144
|
+
if (response.status !== 402) {
|
|
145
|
+
const responseText = await response.text();
|
|
146
|
+
(0, manager_js_1.recordSessionCall)(activeSession.sessionId);
|
|
147
|
+
const MAX_LEN = 8000;
|
|
148
|
+
const truncated = responseText.length > MAX_LEN;
|
|
149
|
+
const displayText = truncated
|
|
150
|
+
? responseText.slice(0, MAX_LEN) + '\n\n... [response truncated]'
|
|
151
|
+
: responseText;
|
|
152
|
+
const ttlRemaining = activeSession.expiresAt - Math.floor(Date.now() / 1000);
|
|
153
|
+
let out = `🌐 **x402 Fetch Result** (session)\n\n`;
|
|
154
|
+
out += ` URL: ${input.url}\n`;
|
|
155
|
+
out += ` Method: ${method}\n`;
|
|
156
|
+
out += ` Status: ${response.status} ${response.statusText}\n`;
|
|
157
|
+
out += ` Network: ${(0, format_js_1.chainName)(config.chainId)}\n`;
|
|
158
|
+
out += `\n🔐 **Session Used** (no payment)\n`;
|
|
159
|
+
out += ` Session ID: ${activeSession.sessionId}\n`;
|
|
160
|
+
if (activeSession.label)
|
|
161
|
+
out += ` Label: ${activeSession.label}\n`;
|
|
162
|
+
out += ` TTL: ${Math.ceil(ttlRemaining / 60)}m remaining\n`;
|
|
163
|
+
out += ` Calls: ${activeSession.callCount}\n`;
|
|
164
|
+
out += `\n📄 **Response Body**\n`;
|
|
165
|
+
out += '```\n' + displayText + '\n```';
|
|
166
|
+
return { content: [(0, format_js_1.textContent)(out)] };
|
|
167
|
+
}
|
|
168
|
+
// Server returned 402 despite session headers — fall through to payment
|
|
169
|
+
// (session may be invalid on the server side)
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
// ── Standard x402 payment flow ────────────────────────────────────────
|
|
173
|
+
// Parse optional max payment cap
|
|
174
|
+
let maxPaymentWei;
|
|
175
|
+
if (input.max_payment_eth) {
|
|
176
|
+
const cap = parseFloat(input.max_payment_eth);
|
|
177
|
+
if (isNaN(cap) || cap <= 0) {
|
|
178
|
+
throw new Error(`Invalid max_payment_eth: "${input.max_payment_eth}"`);
|
|
179
|
+
}
|
|
180
|
+
maxPaymentWei = BigInt(Math.round(cap * 1e18));
|
|
181
|
+
}
|
|
182
|
+
// Track payment result
|
|
183
|
+
let paymentMade = false;
|
|
184
|
+
let paymentAmount = 0n;
|
|
185
|
+
let paymentTxHash = '';
|
|
186
|
+
let paymentRecipient = '';
|
|
187
|
+
// Create x402 client with budget controls
|
|
188
|
+
const x402Client = (0, agentwallet_sdk_1.createX402Client)(wallet, {
|
|
189
|
+
autoPay: true,
|
|
190
|
+
maxRetries: 1,
|
|
191
|
+
// If cap is set, use it as globalPerRequestMax
|
|
192
|
+
globalPerRequestMax: maxPaymentWei,
|
|
193
|
+
onBeforePayment: (req, url) => {
|
|
194
|
+
const amount = BigInt(req.amount);
|
|
195
|
+
if (maxPaymentWei && amount > maxPaymentWei) {
|
|
196
|
+
throw new Error(`Payment required (${amount} wei) exceeds max_payment_eth cap ` +
|
|
197
|
+
`(${maxPaymentWei} wei = ${input.max_payment_eth} ETH). ` +
|
|
198
|
+
`Increase max_payment_eth or the payment will not proceed.`);
|
|
199
|
+
}
|
|
200
|
+
return true;
|
|
201
|
+
},
|
|
202
|
+
onPaymentComplete: (log) => {
|
|
203
|
+
paymentMade = true;
|
|
204
|
+
paymentAmount = log.amount;
|
|
205
|
+
paymentTxHash = log.txHash;
|
|
206
|
+
paymentRecipient = log.recipient;
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
// Build request options
|
|
210
|
+
const method = input.method ?? 'GET';
|
|
211
|
+
const headers = {
|
|
212
|
+
'Accept': 'application/json, text/plain, */*',
|
|
213
|
+
...(input.headers ?? {}),
|
|
214
|
+
};
|
|
215
|
+
if (input.body && ['POST', 'PUT', 'PATCH'].includes(method)) {
|
|
216
|
+
if (!headers['Content-Type']) {
|
|
217
|
+
headers['Content-Type'] = 'application/json';
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
const requestInit = {
|
|
221
|
+
method,
|
|
222
|
+
headers,
|
|
223
|
+
...(input.body ? { body: input.body } : {}),
|
|
224
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
225
|
+
};
|
|
226
|
+
// Execute request with x402 handling
|
|
227
|
+
const response = await x402Client.fetch(input.url, requestInit);
|
|
228
|
+
const responseText = await response.text();
|
|
229
|
+
// Truncate very large responses for readability
|
|
230
|
+
const MAX_RESPONSE_LEN = 8000;
|
|
231
|
+
const truncated = responseText.length > MAX_RESPONSE_LEN;
|
|
232
|
+
const displayText = truncated
|
|
233
|
+
? responseText.slice(0, MAX_RESPONSE_LEN) + '\n\n... [response truncated]'
|
|
234
|
+
: responseText;
|
|
235
|
+
let out = `🌐 **x402 Fetch Result**\n\n`;
|
|
236
|
+
out += ` URL: ${input.url}\n`;
|
|
237
|
+
out += ` Method: ${method}\n`;
|
|
238
|
+
out += ` Status: ${response.status} ${response.statusText}\n`;
|
|
239
|
+
out += ` Network: ${(0, format_js_1.chainName)(config.chainId)}\n`;
|
|
240
|
+
if (paymentMade) {
|
|
241
|
+
out += `\n💳 **Payment Made**\n`;
|
|
242
|
+
out += ` Amount: ${paymentAmount.toString()} (base units)\n`;
|
|
243
|
+
out += ` Recipient: ${paymentRecipient}\n`;
|
|
244
|
+
out += ` TX Hash: ${paymentTxHash}\n`;
|
|
245
|
+
out += `\n💡 Tip: Use x402_session_start to pay once for a session and skip per-call payments.\n`;
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
out += `\n✅ No payment required\n`;
|
|
249
|
+
}
|
|
250
|
+
out += `\n📄 **Response Body**\n`;
|
|
251
|
+
out += '```\n' + displayText + '\n```';
|
|
252
|
+
return { content: [(0, format_js_1.textContent)(out)] };
|
|
253
|
+
}
|
|
254
|
+
catch (error) {
|
|
255
|
+
// Check for AbortError (timeout)
|
|
256
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
|
257
|
+
return {
|
|
258
|
+
content: [(0, format_js_1.textContent)(`❌ x402_pay failed: Request timed out after ${input.timeout_ms ?? 30000}ms`)],
|
|
259
|
+
isError: true,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
return {
|
|
263
|
+
content: [(0, format_js_1.textContent)((0, format_js_1.formatError)(error, 'x402_pay'))],
|
|
264
|
+
isError: true,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
//# sourceMappingURL=x402.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"x402.js","sourceRoot":"","sources":["../../src/tools/x402.ts"],"names":[],"mappings":";;;AAyHA,sCAkLC;AA3SD;;;;;;;;;GASG;AACH,6BAAwB;AACxB,qDAAmD;AACnD,kDAA0D;AAC1D,kDAAyE;AACzE,6CAAsE;AACtE,sDAA0D;AAE1D,8EAA8E;AAEjE,QAAA,aAAa,GAAG,OAAC,CAAC,MAAM,CAAC;IACpC,GAAG,EAAE,OAAC;SACH,MAAM,EAAE;SACR,GAAG,EAAE;SACL,QAAQ,CAAC,yEAAyE,CAAC;IACtF,MAAM,EAAE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,qBAAS,EAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;QAEnD,IAAI,WAAW,EAAE,CAAC;YAChB,GAAG,IAAI,yBAAyB,CAAC;YACjC,GAAG,IAAI,gBAAgB,aAAa,CAAC,QAAQ,EAAE,iBAAiB,CAAC;YACjE,GAAG,IAAI,gBAAgB,gBAAgB,IAAI,CAAC;YAC5C,GAAG,IAAI,gBAAgB,aAAa,IAAI,CAAC;YACzC,GAAG,IAAI,0FAA0F,CAAC;QACpG,CAAC;aAAM,CAAC;YACN,GAAG,IAAI,2BAA2B,CAAC;QACrC,CAAC;QAED,GAAG,IAAI,0BAA0B,CAAC;QAClC,GAAG,IAAI,OAAO,GAAG,WAAW,GAAG,OAAO,CAAC;QAEvC,OAAO,EAAE,OAAO,EAAE,CAAC,IAAA,uBAAW,EAAC,GAAG,CAAC,CAAC,EAAE,CAAC;IACzC,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,iCAAiC;QACjC,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;YAC1D,OAAO;gBACL,OAAO,EAAE,CAAC,IAAA,uBAAW,EAAC,8CAA8C,KAAK,CAAC,UAAU,IAAI,KAAK,IAAI,CAAC,CAAC;gBACnG,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;QACD,OAAO;YACL,OAAO,EAAE,CAAC,IAAA,uBAAW,EAAC,IAAA,uBAAW,EAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC;YACtD,OAAO,EAAE,IAAI;SACd,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentWalletClient setup for AgentPay MCP.
|
|
3
|
+
* Reads config from environment variables and creates a configured wallet instance.
|
|
4
|
+
*/
|
|
5
|
+
import { type Address } from 'viem';
|
|
6
|
+
import { createWallet } from 'agentwallet-sdk';
|
|
7
|
+
export interface AgentPayConfig {
|
|
8
|
+
/** Agent hot wallet private key (0x-prefixed hex) */
|
|
9
|
+
agentPrivateKey: `0x${string}`;
|
|
10
|
+
/** Deployed AgentAccountV2 address */
|
|
11
|
+
walletAddress: Address;
|
|
12
|
+
/** Chain ID (default: 8453 Base Mainnet) */
|
|
13
|
+
chainId: number;
|
|
14
|
+
/** RPC URL (falls back to public Base RPC) */
|
|
15
|
+
rpcUrl: string;
|
|
16
|
+
/** Factory address (for deploy_wallet tool only) */
|
|
17
|
+
factoryAddress?: Address;
|
|
18
|
+
/** NFT contract address (for deploy_wallet tool only) */
|
|
19
|
+
nftContractAddress?: Address;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Load configuration from environment variables.
|
|
23
|
+
* Only AGENT_PRIVATE_KEY and AGENT_WALLET_ADDRESS are required to get started.
|
|
24
|
+
*/
|
|
25
|
+
export declare function loadConfig(): AgentPayConfig;
|
|
26
|
+
export type AgentWalletInstance = ReturnType<typeof createWallet>;
|
|
27
|
+
/**
|
|
28
|
+
* Create an AgentWallet instance from config.
|
|
29
|
+
* Returns the wallet bound to the configured chain + RPC.
|
|
30
|
+
*/
|
|
31
|
+
export declare function createAgentWallet(config: AgentPayConfig): AgentWalletInstance;
|
|
32
|
+
/**
|
|
33
|
+
* Get the singleton AgentPay config (loaded once from env).
|
|
34
|
+
* Throws a descriptive error if env vars are missing.
|
|
35
|
+
*/
|
|
36
|
+
export declare function getConfig(): AgentPayConfig;
|
|
37
|
+
/**
|
|
38
|
+
* Get the singleton AgentWallet instance.
|
|
39
|
+
* Lazily initialized on first call.
|
|
40
|
+
*/
|
|
41
|
+
export declare function getWallet(): AgentWalletInstance;
|
|
42
|
+
/**
|
|
43
|
+
* Reset singletons (for testing only).
|
|
44
|
+
*/
|
|
45
|
+
export declare function _resetSingletons(): void;
|
|
46
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/utils/client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAA4B,KAAK,OAAO,EAAc,MAAM,MAAM,CAAC;AAG1E,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAqB/C,MAAM,WAAW,cAAc;IAC7B,qDAAqD;IACrD,eAAe,EAAE,KAAK,MAAM,EAAE,CAAC;IAC/B,sCAAsC;IACtC,aAAa,EAAE,OAAO,CAAC;IACvB,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAC;IAChB,8CAA8C;IAC9C,MAAM,EAAE,MAAM,CAAC;IACf,oDAAoD;IACpD,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,yDAAyD;IACzD,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAID;;;GAGG;AACH,wBAAgB,UAAU,IAAI,cAAc,CAiD3C;AAID,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;AAElE;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,cAAc,GAAG,mBAAmB,CAyB7E;AAOD;;;GAGG;AACH,wBAAgB,SAAS,IAAI,cAAc,CAK1C;AAED;;;GAGG;AACH,wBAAgB,SAAS,IAAI,mBAAmB,CAK/C;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAGvC"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadConfig = loadConfig;
|
|
4
|
+
exports.createAgentWallet = createAgentWallet;
|
|
5
|
+
exports.getConfig = getConfig;
|
|
6
|
+
exports.getWallet = getWallet;
|
|
7
|
+
exports._resetSingletons = _resetSingletons;
|
|
8
|
+
/**
|
|
9
|
+
* AgentWalletClient setup for AgentPay MCP.
|
|
10
|
+
* Reads config from environment variables and creates a configured wallet instance.
|
|
11
|
+
*/
|
|
12
|
+
const viem_1 = require("viem");
|
|
13
|
+
const accounts_1 = require("viem/accounts");
|
|
14
|
+
const chains_1 = require("viem/chains");
|
|
15
|
+
const agentwallet_sdk_1 = require("agentwallet-sdk");
|
|
16
|
+
// ─── Supported chains ──────────────────────────────────────────────────────
|
|
17
|
+
const CHAIN_MAP = {
|
|
18
|
+
8453: chains_1.base,
|
|
19
|
+
84532: chains_1.baseSepolia,
|
|
20
|
+
};
|
|
21
|
+
const CHAIN_NAME_MAP = {
|
|
22
|
+
8453: 'base',
|
|
23
|
+
84532: 'base-sepolia',
|
|
24
|
+
};
|
|
25
|
+
const DEFAULT_RPC = {
|
|
26
|
+
8453: 'https://mainnet.base.org',
|
|
27
|
+
84532: 'https://sepolia.base.org',
|
|
28
|
+
};
|
|
29
|
+
// ─── Config loader ─────────────────────────────────────────────────────────
|
|
30
|
+
/**
|
|
31
|
+
* Load configuration from environment variables.
|
|
32
|
+
* Only AGENT_PRIVATE_KEY and AGENT_WALLET_ADDRESS are required to get started.
|
|
33
|
+
*/
|
|
34
|
+
function loadConfig() {
|
|
35
|
+
const agentPrivateKey = process.env['AGENT_PRIVATE_KEY'];
|
|
36
|
+
const walletAddress = process.env['AGENT_WALLET_ADDRESS'];
|
|
37
|
+
if (!agentPrivateKey) {
|
|
38
|
+
throw new Error('AGENT_PRIVATE_KEY environment variable is required. ' +
|
|
39
|
+
'Set it to the agent hot wallet private key (0x-prefixed hex).');
|
|
40
|
+
}
|
|
41
|
+
if (!walletAddress) {
|
|
42
|
+
throw new Error('AGENT_WALLET_ADDRESS environment variable is required. ' +
|
|
43
|
+
'Set it to the deployed AgentAccountV2 contract address.');
|
|
44
|
+
}
|
|
45
|
+
if (!agentPrivateKey.startsWith('0x') || agentPrivateKey.length !== 66) {
|
|
46
|
+
throw new Error('AGENT_PRIVATE_KEY must be a 0x-prefixed 32-byte hex string (66 chars total).');
|
|
47
|
+
}
|
|
48
|
+
if (!walletAddress.startsWith('0x') || walletAddress.length !== 42) {
|
|
49
|
+
throw new Error('AGENT_WALLET_ADDRESS must be a 0x-prefixed 20-byte hex string (42 chars total).');
|
|
50
|
+
}
|
|
51
|
+
const chainId = parseInt(process.env['CHAIN_ID'] ?? '8453', 10);
|
|
52
|
+
if (!CHAIN_MAP[chainId]) {
|
|
53
|
+
throw new Error(`Unsupported CHAIN_ID: ${chainId}. Supported values: 8453 (Base Mainnet), 84532 (Base Sepolia).`);
|
|
54
|
+
}
|
|
55
|
+
const rpcUrl = process.env['RPC_URL'] ?? DEFAULT_RPC[chainId] ?? 'https://mainnet.base.org';
|
|
56
|
+
const factoryAddress = process.env['FACTORY_ADDRESS'];
|
|
57
|
+
const nftContractAddress = process.env['NFT_CONTRACT_ADDRESS'];
|
|
58
|
+
return {
|
|
59
|
+
agentPrivateKey: agentPrivateKey,
|
|
60
|
+
walletAddress: walletAddress,
|
|
61
|
+
chainId,
|
|
62
|
+
rpcUrl,
|
|
63
|
+
factoryAddress,
|
|
64
|
+
nftContractAddress,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Create an AgentWallet instance from config.
|
|
69
|
+
* Returns the wallet bound to the configured chain + RPC.
|
|
70
|
+
*/
|
|
71
|
+
function createAgentWallet(config) {
|
|
72
|
+
const chain = CHAIN_MAP[config.chainId];
|
|
73
|
+
if (!chain) {
|
|
74
|
+
throw new Error(`Unsupported chain ID: ${config.chainId}`);
|
|
75
|
+
}
|
|
76
|
+
const chainName = CHAIN_NAME_MAP[config.chainId];
|
|
77
|
+
if (!chainName) {
|
|
78
|
+
throw new Error(`No chain name mapping for chain ID: ${config.chainId}`);
|
|
79
|
+
}
|
|
80
|
+
const account = (0, accounts_1.privateKeyToAccount)(config.agentPrivateKey);
|
|
81
|
+
const walletClient = (0, viem_1.createWalletClient)({
|
|
82
|
+
account,
|
|
83
|
+
chain,
|
|
84
|
+
transport: (0, viem_1.http)(config.rpcUrl),
|
|
85
|
+
});
|
|
86
|
+
return (0, agentwallet_sdk_1.createWallet)({
|
|
87
|
+
accountAddress: config.walletAddress,
|
|
88
|
+
chain: chainName,
|
|
89
|
+
rpcUrl: config.rpcUrl,
|
|
90
|
+
walletClient,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
// ─── Singleton accessor ────────────────────────────────────────────────────
|
|
94
|
+
let _config = null;
|
|
95
|
+
let _wallet = null;
|
|
96
|
+
/**
|
|
97
|
+
* Get the singleton AgentPay config (loaded once from env).
|
|
98
|
+
* Throws a descriptive error if env vars are missing.
|
|
99
|
+
*/
|
|
100
|
+
function getConfig() {
|
|
101
|
+
if (!_config) {
|
|
102
|
+
_config = loadConfig();
|
|
103
|
+
}
|
|
104
|
+
return _config;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Get the singleton AgentWallet instance.
|
|
108
|
+
* Lazily initialized on first call.
|
|
109
|
+
*/
|
|
110
|
+
function getWallet() {
|
|
111
|
+
if (!_wallet) {
|
|
112
|
+
_wallet = createAgentWallet(getConfig());
|
|
113
|
+
}
|
|
114
|
+
return _wallet;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Reset singletons (for testing only).
|
|
118
|
+
*/
|
|
119
|
+
function _resetSingletons() {
|
|
120
|
+
_config = null;
|
|
121
|
+
_wallet = null;
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/utils/client.ts"],"names":[],"mappings":";;AAiDA,gCAiDC;AAUD,8CAyBC;AAWD,8BAKC;AAMD,8BAKC;AAKD,4CAGC;AAxKD;;;GAGG;AACH,+BAA0E;AAC1E,4CAAoD;AACpD,wCAAgD;AAChD,qDAA+C;AAE/C,8EAA8E;AAE9E,MAAM,SAAS,GAA0B;IACvC,IAAI,EAAE,aAAI;IACV,KAAK,EAAE,oBAAW;CACnB,CAAC;AAEF,MAAM,cAAc,GAA4C;IAC9D,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,c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U,EAAE,CAAC;IACzB,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;GAGG;AACH,SAAgB,SAAS;IACvB,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,GAAG,iBAAiB,CAAC,SAAS,EAAE,CAAC,CAAC;IAC3C,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,SAAgB,gBAAgB;IAC9B,OAAO,GAAG,IAAI,CAAC;IACf,OAAO,GAAG,IAAI,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Response formatters for AgentPay MCP tools.
|
|
3
|
+
* Converts on-chain bigint/hex values to human-readable MCP content.
|
|
4
|
+
*/
|
|
5
|
+
import type { Address, Hash } from 'viem';
|
|
6
|
+
/**
|
|
7
|
+
* Format a bigint wei amount as a readable ETH string.
|
|
8
|
+
* e.g., 1000000000000000000n → "1.000000 ETH"
|
|
9
|
+
*/
|
|
10
|
+
export declare function formatEth(wei: bigint): string;
|
|
11
|
+
/**
|
|
12
|
+
* Format a bigint token amount with the given decimals.
|
|
13
|
+
* e.g., 1000000n with decimals=6 → "1.000000 USDC"
|
|
14
|
+
*/
|
|
15
|
+
export declare function formatToken(amount: bigint, decimals: number, symbol: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Format a bigint as a readable ETH or "N/A" if zero/unlimited.
|
|
18
|
+
* Used for spend limits where 0 means "no autonomous spending allowed".
|
|
19
|
+
*/
|
|
20
|
+
export declare function formatSpendLimit(wei: bigint): string;
|
|
21
|
+
/**
|
|
22
|
+
* Format an address with a label. Truncates middle for readability.
|
|
23
|
+
*/
|
|
24
|
+
export declare function formatAddress(address: Address): string;
|
|
25
|
+
/**
|
|
26
|
+
* Format a full address (for display in detailed outputs).
|
|
27
|
+
*/
|
|
28
|
+
export declare function formatAddressFull(address: Address): string;
|
|
29
|
+
/**
|
|
30
|
+
* Format seconds as human-readable duration.
|
|
31
|
+
*/
|
|
32
|
+
export declare function formatDuration(seconds: number): string;
|
|
33
|
+
/**
|
|
34
|
+
* Format a Unix timestamp as ISO string.
|
|
35
|
+
*/
|
|
36
|
+
export declare function formatTimestamp(ts: number): string;
|
|
37
|
+
/**
|
|
38
|
+
* Get a utilization badge based on percentage used.
|
|
39
|
+
*/
|
|
40
|
+
export declare function utilizationBadge(pct: number): string;
|
|
41
|
+
export declare function chainName(chainId: number): string;
|
|
42
|
+
export declare function explorerTxUrl(txHash: Hash, chainId: number): string;
|
|
43
|
+
export declare function explorerAddressUrl(address: Address, chainId: number): string;
|
|
44
|
+
/**
|
|
45
|
+
* Create a standard MCP text content block.
|
|
46
|
+
*/
|
|
47
|
+
export declare function textContent(text: string): {
|
|
48
|
+
type: 'text';
|
|
49
|
+
text: string;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Format an error into a human-readable MCP error response text.
|
|
53
|
+
*/
|
|
54
|
+
export declare function formatError(error: unknown, context: string): string;
|
|
55
|
+
/**
|
|
56
|
+
* Format a success message with optional details.
|
|
57
|
+
*/
|
|
58
|
+
export declare function formatSuccess(message: string, details?: Record<string, string>): string;
|
|
59
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/utils/format.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAK1C;;;GAGG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAEpF;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAKpD;AAID;;GAEG;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