@newblock/iautopay-mcp 0.0.3 → 0.0.5

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,6 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import('../dist/iautopay-mcp.js').catch((err) => {
4
- console.error('Failed to load iautopay-mcp:', err);
5
4
  process.exit(1);
6
5
  });
@@ -31,8 +31,7 @@ if (!CONFIG.BUYER_PRIVATE_KEY) {
31
31
  }
32
32
  // Validate private key format
33
33
  try {
34
- const account = privateKeyToAccount(CONFIG.BUYER_PRIVATE_KEY);
35
- console.log(`[CONFIG] Private key validated, account: ${account.address}`);
34
+ privateKeyToAccount(CONFIG.BUYER_PRIVATE_KEY);
36
35
  }
37
36
  catch (error) {
38
37
  throw new Error(`Invalid BUYER_PRIVATE_KEY format: ${error}`);
@@ -81,20 +80,16 @@ async function fetchPricingFromFactAPI() {
81
80
  "7days": `${data.prices?.["7daysUsdc"] || 0.49} USDC`,
82
81
  "30days": `${data.prices?.["30daysUsdc"] || 0.99} USDC`
83
82
  };
84
- console.log(`[PRICING] Loaded from fact-api:`, CACHED_PRICING);
85
83
  return CACHED_PRICING;
86
84
  }
87
85
  }
88
86
  catch (error) {
89
- console.warn(`[PRICING] Failed to fetch from fact-api, using defaults. Error:`, error);
90
87
  }
91
- // Default pricing as fallback
92
88
  CACHED_PRICING = {
93
89
  "1day": "0.09 USDC",
94
90
  "7days": "0.49 USDC",
95
91
  "30days": "0.99 USDC"
96
92
  };
97
- console.log(`[PRICING] Using default pricing:`, CACHED_PRICING);
98
93
  return CACHED_PRICING;
99
94
  }
100
95
  const buyerAccount = privateKeyToAccount(CONFIG.BUYER_PRIVATE_KEY);
@@ -119,14 +114,11 @@ async function fetchWithRetry(url, options, context = 'API Request') {
119
114
  if (response.ok || response.status < 500) {
120
115
  return response;
121
116
  }
122
- console.log(`[RETRY] ${context} - Attempt ${i + 1}/${RETRY_CONFIG.MAX_RETRIES} failed, status: ${response.status}`);
123
117
  }
124
118
  catch (error) {
125
- console.log(`[RETRY] ${context} - Attempt ${i + 1}/${RETRY_CONFIG.MAX_RETRIES} error:`, error);
126
119
  }
127
120
  if (i < RETRY_CONFIG.MAX_RETRIES - 1) {
128
121
  const delay = RETRY_CONFIG.BASE_DELAY * Math.pow(2, i);
129
- console.log(`[RETRY] ${context} - Waiting ${delay}ms before retry...`);
130
122
  await new Promise(resolve => setTimeout(resolve, delay));
131
123
  }
132
124
  }
@@ -258,11 +250,6 @@ async function buildPaymentSignature(requirements) {
258
250
  };
259
251
  }
260
252
  async function payStablecoin(params) {
261
- console.log(`[PAY_STABLECOIN] Starting payment...`);
262
- console.log(`[PAY_STABLECOIN] Network: ${params.isTestnet ? "eip155:84532 (Testnet)" : `eip155:${BUYER_CHAIN_ID}`}`);
263
- console.log(`[PAY_STABLECOIN] Asset: ${params.asset}`);
264
- console.log(`[PAY_STABLECOIN] Amount: ${params.amount}`);
265
- console.log(`[PAY_STABLECOIN] To: ${params.to}`);
266
253
  const [balance, decimals] = await Promise.all([
267
254
  publicClient.readContract({
268
255
  address: params.asset,
@@ -278,10 +265,7 @@ async function payStablecoin(params) {
278
265
  ]);
279
266
  const balanceNumber = Number(balance) / (10 ** Number(decimals));
280
267
  const amountNumber = Number(params.amount) / 1e6;
281
- console.log(`[PAY_STABLECOIN] Current balance: ${balanceNumber.toFixed(6)} USDC`);
282
- console.log(`[PAY_STABLECOIN] Required: ${amountNumber.toFixed(6)} USDC`);
283
268
  if (balanceNumber < amountNumber) {
284
- console.log(`[PAY_STABLECOIN] Insufficient balance!`);
285
269
  throw new Error(`Insufficient balance: required ${amountNumber.toFixed(6)} USDC, available ${balanceNumber.toFixed(6)} USDC`);
286
270
  }
287
271
  const requirements = {
@@ -291,10 +275,7 @@ async function payStablecoin(params) {
291
275
  price: params.amount,
292
276
  payee: params.to,
293
277
  };
294
- console.log(`[PAY_STABLECOIN] Building payment signature...`);
295
278
  const signaturePayload = await buildPaymentSignature(requirements);
296
- console.log(`[PAY_STABLECOIN] Signature built, calling fact-api...`);
297
- console.log(`[PAY_STABLECOIN] Fact API URL: ${FACT_API_URL}/v1/transfer`);
298
279
  const transferRes = await fetchWithRetry(`${FACT_API_URL}/v1/transfer`, {
299
280
  method: "POST",
300
281
  headers: {
@@ -307,15 +288,12 @@ async function payStablecoin(params) {
307
288
  asset: params.asset,
308
289
  }),
309
290
  }, 'PAY_STABLECOIN Transfer');
310
- console.log(`[PAY_STABLECOIN] Fact API response status: ${transferRes.status}`);
311
291
  if (!transferRes.ok) {
312
292
  const error = await transferRes.text();
313
- console.log(`[PAY_STABLECOIN] Transfer failed: ${error}`);
314
293
  const networkInfo = params.isTestnet ? "Testnet (Base Sepolia 84532)" : `Mainnet (Base ${BUYER_CHAIN_ID === '8453' ? 'Mainnet' : BUYER_CHAIN_ID})`;
315
294
  throw new Error(`Transfer failed (${networkInfo}): ${error}`);
316
295
  }
317
296
  const result = await transferRes.json();
318
- console.log(`[PAY_STABLECOIN] Transfer successful:`, result);
319
297
  const deductedAmount = amountNumber.toFixed(6);
320
298
  const currentBalance = (balanceNumber - amountNumber).toFixed(6);
321
299
  return {
@@ -408,8 +386,6 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
408
386
  const priceString = priceMap[duration];
409
387
  const priceNumber = parseFloat(priceString);
410
388
  const priceWei = (priceNumber * 1e6).toString();
411
- console.log(`[BUY_APIKEY] Checking balance...`);
412
- console.log(`[BUY_APIKEY] Required: ${priceNumber.toFixed(6)} USDC, Available: ${balanceNumber.toFixed(6)} USDC`);
413
389
  if (balanceNumber < priceNumber) {
414
390
  throw new Error(`Insufficient balance: required ${priceNumber.toFixed(6)} USDC, available ${balanceNumber.toFixed(6)} USDC`);
415
391
  }
@@ -420,11 +396,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
420
396
  price: priceWei,
421
397
  payee: "0x1a85156c2943b63febeee7883bd84a7d1cf0da0c",
422
398
  };
423
- console.log(`[BUY_APIKEY] Building payment signature...`);
424
399
  const signaturePayload = await buildPaymentSignature(requirements);
425
- console.log(`[BUY_APIKEY] Signature built, calling fact-api...`);
426
- console.log(`[BUY_APIKEY] Fact API URL: ${FACT_API_URL}/v1/buy-apikey`);
427
- console.log(`[BUY_APIKEY] Sending request to fact-api (no retry, generate new nonce on failure)...`);
428
400
  const buyRes = await fetch(`${FACT_API_URL}/v1/buy-apikey`, {
429
401
  method: "POST",
430
402
  headers: {
@@ -433,15 +405,12 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
433
405
  },
434
406
  body: JSON.stringify({ duration })
435
407
  });
436
- console.log(`[BUY_APIKEY] Fact API response status: ${buyRes.status}`);
437
408
  if (!buyRes.ok) {
438
409
  const error = await buyRes.text();
439
- console.log(`[BUY_APIKEY] Buy API key failed ${error}`);
440
410
  const networkInfo = CUR_ENV === 'dev' ? "Testnet (Base Sepolia 84532)" : `Mainnet (Base ${BUYER_CHAIN_ID})`;
441
411
  throw new Error(`Buy API key failed (${networkInfo}): ${error}`);
442
412
  }
443
413
  const result = await buyRes.json();
444
- console.log(`[BUY_APIKEY] Buy API key successful:`, result);
445
414
  return {
446
415
  content: [{
447
416
  type: "text",
@@ -597,21 +566,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
597
566
  throw new Error(`Unknown tool: ${name}`);
598
567
  });
599
568
  const transport = new StdioServerTransport();
600
- console.log(`========================================`);
601
- console.log(`[CONFIG] Environment: ${CUR_ENV}`);
602
- console.log(`[CONFIG] RPC URL: ${BUYER_RPC_URL}`);
603
- console.log(`[CONFIG] Chain ID: ${BUYER_CHAIN_ID}`);
604
- console.log(`[CONFIG] Fact API: ${FACT_API_URL}`);
605
- console.log(`[CONFIG] USDC Address: ${CURRENT_USDC}`);
606
- console.log(`[CONFIG] Buyer Address: ${buyerAccount.address}`);
607
- console.log(`========================================`);
608
- // Fetch pricing from Fact API on startup
609
569
  await fetchPricingFromFactAPI();
610
- console.log(`========================================`);
611
- console.log(`[PRICING] 1 Day: ${CACHED_PRICING?.["1day"]}`);
612
- console.log(`[PRICING] 7 Days: ${CACHED_PRICING?.["7days"]}`);
613
- console.log(`[PRICING] 30 Days: ${CACHED_PRICING?.["30days"]}`);
614
- // Check USDC balance on startup
615
570
  try {
616
571
  const usdcBalance = await publicClient.readContract({
617
572
  address: CURRENT_USDC,
@@ -624,27 +579,7 @@ try {
624
579
  abi: tokenAbi,
625
580
  functionName: 'decimals'
626
581
  });
627
- const balanceNumber = Number(usdcBalance) / (10 ** Number(decimals));
628
- console.log(`[BALANCE] USDC Balance: ${balanceNumber.toFixed(6)} USDC`);
629
582
  }
630
583
  catch (error) {
631
- console.warn(`[BALANCE] Failed to check USDC balance:`, error);
632
584
  }
633
- console.log(`========================================`);
634
585
  await server.connect(transport);
635
- // Display startup message for users
636
- setTimeout(() => {
637
- console.log(`
638
- ╔════════════════════════════════════════════════════════════╗
639
- ║ iAutoPay MCP Server 已启动 ║
640
- ╠════════════════════════════════════════════════════════════╣
641
- ║ 快速开始: ║
642
- ║ 1. 输入 "guide" 查看完整使用指南 ║
643
- ║ 2. 输入 "info" 查看服务器信息和价格 ║
644
- ║ 3. 输入 "buy_apikey" 购买 API Key (可选1/7/30天) ║
645
- ╠════════════════════════════════════════════════════════════╣
646
- ║ 提示:请确保 opencode.json 已配置 autopay_ 命令 ║
647
- ║ 运行 "sync_opencode_config" 自动添加缺失的命令 ║
648
- ╚════════════════════════════════════════════════════════════╝
649
- `);
650
- }, 1000);
package/dist/server.js CHANGED
@@ -31,8 +31,7 @@ if (!CONFIG.BUYER_PRIVATE_KEY) {
31
31
  }
32
32
  // Validate private key format
33
33
  try {
34
- const account = privateKeyToAccount(CONFIG.BUYER_PRIVATE_KEY);
35
- console.log(`[CONFIG] Private key validated, account: ${account.address}`);
34
+ privateKeyToAccount(CONFIG.BUYER_PRIVATE_KEY);
36
35
  }
37
36
  catch (error) {
38
37
  throw new Error(`Invalid BUYER_PRIVATE_KEY format: ${error}`);
@@ -81,20 +80,16 @@ async function fetchPricingFromFactAPI() {
81
80
  "7days": `${data.prices?.["7daysUsdc"] || 0.49} USDC`,
82
81
  "30days": `${data.prices?.["30daysUsdc"] || 0.99} USDC`
83
82
  };
84
- console.log(`[PRICING] Loaded from fact-api:`, CACHED_PRICING);
85
83
  return CACHED_PRICING;
86
84
  }
87
85
  }
88
86
  catch (error) {
89
- console.warn(`[PRICING] Failed to fetch from fact-api, using defaults. Error:`, error);
90
87
  }
91
- // Default pricing as fallback
92
88
  CACHED_PRICING = {
93
89
  "1day": "0.09 USDC",
94
90
  "7days": "0.49 USDC",
95
91
  "30days": "0.99 USDC"
96
92
  };
97
- console.log(`[PRICING] Using default pricing:`, CACHED_PRICING);
98
93
  return CACHED_PRICING;
99
94
  }
100
95
  const buyerAccount = privateKeyToAccount(CONFIG.BUYER_PRIVATE_KEY);
@@ -119,14 +114,11 @@ async function fetchWithRetry(url, options, context = 'API Request') {
119
114
  if (response.ok || response.status < 500) {
120
115
  return response;
121
116
  }
122
- console.log(`[RETRY] ${context} - Attempt ${i + 1}/${RETRY_CONFIG.MAX_RETRIES} failed, status: ${response.status}`);
123
117
  }
124
118
  catch (error) {
125
- console.log(`[RETRY] ${context} - Attempt ${i + 1}/${RETRY_CONFIG.MAX_RETRIES} error:`, error);
126
119
  }
127
120
  if (i < RETRY_CONFIG.MAX_RETRIES - 1) {
128
121
  const delay = RETRY_CONFIG.BASE_DELAY * Math.pow(2, i);
129
- console.log(`[RETRY] ${context} - Waiting ${delay}ms before retry...`);
130
122
  await new Promise(resolve => setTimeout(resolve, delay));
131
123
  }
132
124
  }
@@ -258,11 +250,6 @@ async function buildPaymentSignature(requirements) {
258
250
  };
259
251
  }
260
252
  async function payStablecoin(params) {
261
- console.log(`[PAY_STABLECOIN] Starting payment...`);
262
- console.log(`[PAY_STABLECOIN] Network: ${params.isTestnet ? "eip155:84532 (Testnet)" : `eip155:${BUYER_CHAIN_ID}`}`);
263
- console.log(`[PAY_STABLECOIN] Asset: ${params.asset}`);
264
- console.log(`[PAY_STABLECOIN] Amount: ${params.amount}`);
265
- console.log(`[PAY_STABLECOIN] To: ${params.to}`);
266
253
  const [balance, decimals] = await Promise.all([
267
254
  publicClient.readContract({
268
255
  address: params.asset,
@@ -278,10 +265,7 @@ async function payStablecoin(params) {
278
265
  ]);
279
266
  const balanceNumber = Number(balance) / (10 ** Number(decimals));
280
267
  const amountNumber = Number(params.amount) / 1e6;
281
- console.log(`[PAY_STABLECOIN] Current balance: ${balanceNumber.toFixed(6)} USDC`);
282
- console.log(`[PAY_STABLECOIN] Required: ${amountNumber.toFixed(6)} USDC`);
283
268
  if (balanceNumber < amountNumber) {
284
- console.log(`[PAY_STABLECOIN] Insufficient balance!`);
285
269
  throw new Error(`Insufficient balance: required ${amountNumber.toFixed(6)} USDC, available ${balanceNumber.toFixed(6)} USDC`);
286
270
  }
287
271
  const requirements = {
@@ -291,10 +275,7 @@ async function payStablecoin(params) {
291
275
  price: params.amount,
292
276
  payee: params.to,
293
277
  };
294
- console.log(`[PAY_STABLECOIN] Building payment signature...`);
295
278
  const signaturePayload = await buildPaymentSignature(requirements);
296
- console.log(`[PAY_STABLECOIN] Signature built, calling fact-api...`);
297
- console.log(`[PAY_STABLECOIN] Fact API URL: ${FACT_API_URL}/v1/transfer`);
298
279
  const transferRes = await fetchWithRetry(`${FACT_API_URL}/v1/transfer`, {
299
280
  method: "POST",
300
281
  headers: {
@@ -307,15 +288,12 @@ async function payStablecoin(params) {
307
288
  asset: params.asset,
308
289
  }),
309
290
  }, 'PAY_STABLECOIN Transfer');
310
- console.log(`[PAY_STABLECOIN] Fact API response status: ${transferRes.status}`);
311
291
  if (!transferRes.ok) {
312
292
  const error = await transferRes.text();
313
- console.log(`[PAY_STABLECOIN] Transfer failed: ${error}`);
314
293
  const networkInfo = params.isTestnet ? "Testnet (Base Sepolia 84532)" : `Mainnet (Base ${BUYER_CHAIN_ID === '8453' ? 'Mainnet' : BUYER_CHAIN_ID})`;
315
294
  throw new Error(`Transfer failed (${networkInfo}): ${error}`);
316
295
  }
317
296
  const result = await transferRes.json();
318
- console.log(`[PAY_STABLECOIN] Transfer successful:`, result);
319
297
  const deductedAmount = amountNumber.toFixed(6);
320
298
  const currentBalance = (balanceNumber - amountNumber).toFixed(6);
321
299
  return {
@@ -408,8 +386,6 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
408
386
  const priceString = priceMap[duration];
409
387
  const priceNumber = parseFloat(priceString);
410
388
  const priceWei = (priceNumber * 1e6).toString();
411
- console.log(`[BUY_APIKEY] Checking balance...`);
412
- console.log(`[BUY_APIKEY] Required: ${priceNumber.toFixed(6)} USDC, Available: ${balanceNumber.toFixed(6)} USDC`);
413
389
  if (balanceNumber < priceNumber) {
414
390
  throw new Error(`Insufficient balance: required ${priceNumber.toFixed(6)} USDC, available ${balanceNumber.toFixed(6)} USDC`);
415
391
  }
@@ -420,11 +396,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
420
396
  price: priceWei,
421
397
  payee: "0x1a85156c2943b63febeee7883bd84a7d1cf0da0c",
422
398
  };
423
- console.log(`[BUY_APIKEY] Building payment signature...`);
424
399
  const signaturePayload = await buildPaymentSignature(requirements);
425
- console.log(`[BUY_APIKEY] Signature built, calling fact-api...`);
426
- console.log(`[BUY_APIKEY] Fact API URL: ${FACT_API_URL}/v1/buy-apikey`);
427
- console.log(`[BUY_APIKEY] Sending request to fact-api (no retry, generate new nonce on failure)...`);
428
400
  const buyRes = await fetch(`${FACT_API_URL}/v1/buy-apikey`, {
429
401
  method: "POST",
430
402
  headers: {
@@ -433,15 +405,12 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
433
405
  },
434
406
  body: JSON.stringify({ duration })
435
407
  });
436
- console.log(`[BUY_APIKEY] Fact API response status: ${buyRes.status}`);
437
408
  if (!buyRes.ok) {
438
409
  const error = await buyRes.text();
439
- console.log(`[BUY_APIKEY] Buy API key failed ${error}`);
440
410
  const networkInfo = CUR_ENV === 'dev' ? "Testnet (Base Sepolia 84532)" : `Mainnet (Base ${BUYER_CHAIN_ID})`;
441
411
  throw new Error(`Buy API key failed (${networkInfo}): ${error}`);
442
412
  }
443
413
  const result = await buyRes.json();
444
- console.log(`[BUY_APIKEY] Buy API key successful:`, result);
445
414
  return {
446
415
  content: [{
447
416
  type: "text",
@@ -597,21 +566,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
597
566
  throw new Error(`Unknown tool: ${name}`);
598
567
  });
599
568
  const transport = new StdioServerTransport();
600
- console.log(`========================================`);
601
- console.log(`[CONFIG] Environment: ${CUR_ENV}`);
602
- console.log(`[CONFIG] RPC URL: ${BUYER_RPC_URL}`);
603
- console.log(`[CONFIG] Chain ID: ${BUYER_CHAIN_ID}`);
604
- console.log(`[CONFIG] Fact API: ${FACT_API_URL}`);
605
- console.log(`[CONFIG] USDC Address: ${CURRENT_USDC}`);
606
- console.log(`[CONFIG] Buyer Address: ${buyerAccount.address}`);
607
- console.log(`========================================`);
608
- // Fetch pricing from Fact API on startup
609
569
  await fetchPricingFromFactAPI();
610
- console.log(`========================================`);
611
- console.log(`[PRICING] 1 Day: ${CACHED_PRICING?.["1day"]}`);
612
- console.log(`[PRICING] 7 Days: ${CACHED_PRICING?.["7days"]}`);
613
- console.log(`[PRICING] 30 Days: ${CACHED_PRICING?.["30days"]}`);
614
- // Check USDC balance on startup
615
570
  try {
616
571
  const usdcBalance = await publicClient.readContract({
617
572
  address: CURRENT_USDC,
@@ -624,27 +579,7 @@ try {
624
579
  abi: tokenAbi,
625
580
  functionName: 'decimals'
626
581
  });
627
- const balanceNumber = Number(usdcBalance) / (10 ** Number(decimals));
628
- console.log(`[BALANCE] USDC Balance: ${balanceNumber.toFixed(6)} USDC`);
629
582
  }
630
583
  catch (error) {
631
- console.warn(`[BALANCE] Failed to check USDC balance:`, error);
632
584
  }
633
- console.log(`========================================`);
634
585
  await server.connect(transport);
635
- // Display startup message for users
636
- setTimeout(() => {
637
- console.log(`
638
- ╔════════════════════════════════════════════════════════════╗
639
- ║ iAutoPay MCP Server 已启动 ║
640
- ╠════════════════════════════════════════════════════════════╣
641
- ║ 快速开始: ║
642
- ║ 1. 输入 "guide" 查看完整使用指南 ║
643
- ║ 2. 输入 "info" 查看服务器信息和价格 ║
644
- ║ 3. 输入 "buy_apikey" 购买 API Key (可选1/7/30天) ║
645
- ╠════════════════════════════════════════════════════════════╣
646
- ║ 提示:请确保 opencode.json 已配置 autopay_ 命令 ║
647
- ║ 运行 "sync_opencode_config" 自动添加缺失的命令 ║
648
- ╚════════════════════════════════════════════════════════════╝
649
- `);
650
- }, 1000);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newblock/iautopay-mcp",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "iAutoPay is an MCP service that enables AI agents to automatically pay for purchases. It currently runs on Base chain (operated by Coinbase) and supports USDC payments.",
5
5
  "type": "module",
6
6
  "main": "dist/iautopay-mcp.js",
@@ -17,7 +17,7 @@
17
17
  ],
18
18
  "scripts": {
19
19
  "build": "tsc",
20
- "dev": "tsx src/server.ts",
20
+ "dev": "tsx src/iautopay-mcp.ts",
21
21
  "test": "vitest",
22
22
  "install:opencode-config": "node scripts/generate-opencode-config.js",
23
23
  "prepublishOnly": "npm run build"