@paywithtender/mcp 0.1.1 → 0.1.3

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tender (paywithtender)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # @paywithtender/mcp
2
2
 
3
+ [![Tender MCP server](https://glama.ai/mcp/servers/paywithtender/tender/badges/score.svg)](https://glama.ai/mcp/servers/paywithtender/tender) [![Tender MCP on mcprush](https://mcprush.com/badge/paywithtender-tender-mcp/compact.svg)](https://mcprush.com/to/paywithtender-tender-mcp?ref=badge)
4
+
3
5
  An MCP server that lets any AI agent pay x402 APIs on Robinhood Chain with whatever token it holds. Tender swaps the token to USDG on Uniswap inside the payment, so the API always receives the exact price, in one transaction.
4
6
 
5
7
  Works with Claude Desktop, Claude Code, Cursor, and any other MCP client.
@@ -56,7 +58,9 @@ It costs $0.01 plus gas, in whatever token you set as `TENDER_PAY_WITH`.
56
58
  | `TENDER_PAY_WITH` | USDG | Token to pay with. Any token with a Uniswap route to USDG works. |
57
59
  | `TENDER_MAX_PER_CALL_USD` | `1` | Refuse any API priced above this. |
58
60
  | `TENDER_MAX_FEE_USD` | `0.10` | Refuse if Tender's fee plus gas is above this. |
59
- | `TENDER_DAILY_LIMIT_USD` | `10` | Total the agent may spend per UTC day (resets when the server restarts). |
61
+ | `TENDER_DAILY_LIMIT_USD` | `10` | Total the agent may spend per UTC day. The running total is saved to disk, so restarting the server or the AI app doesn't reset it. |
62
+ | `TENDER_APPROVAL_DAYS` | `7` | The agent approves only enough of its token for this many days at the daily limit, and renews the approval when it runs low. It never grants an unlimited allowance unless you set this to `unlimited`. A wallet without ETH gets its first approval sponsored; renewals need a little ETH for gas. |
63
+ | `TENDER_STATE_FILE` | `~/.tender/spend.json` | Where today's spending is kept, per wallet. Set to `none` to keep it in memory only (resets on restart). |
60
64
  | `TENDER_RPC_URL` | Robinhood Chain public RPC | |
61
65
  | `TENDER_FACILITATOR` | `https://facilitator.paywithtender.com` | |
62
66
 
@@ -66,7 +70,7 @@ It costs $0.01 plus gas, in whatever token you set as `TENDER_PAY_WITH`.
66
70
  - Paying in any other token: 0.5% + gas
67
71
  - Paying in $TENDER: gas only
68
72
 
69
- The first payment with a new token needs a one-time Permit2 approval. If the agent wallet has no ETH, Tender covers the gas for it.
73
+ The first payment with a new token approves Permit2 for a capped amount: enough for `TENDER_APPROVAL_DAYS` days at your daily limit, never unlimited. If the agent wallet has no ETH, Tender covers the gas for that first approval. When the approval runs low the agent renews it, which needs a little ETH.
70
74
 
71
75
  ## Links
72
76
 
package/dist/server.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { type Address, type Hex } from "viem";
3
- export declare const VERSION = "0.1.1";
3
+ export declare const VERSION = "0.1.3";
4
4
  export interface TenderMcpConfig {
5
5
  /** Agent wallet key. Without it, only the read-only tools work. */
6
6
  privateKey?: Hex;
@@ -15,9 +15,16 @@ export interface TenderMcpConfig {
15
15
  maxPerCall: bigint;
16
16
  maxFeePerCall: bigint;
17
17
  dailyLimit: bigint;
18
+ /** File that keeps today's spending per wallet, so restarts don't reset the daily limit. Unset = memory only. */
19
+ stateFile?: string;
18
20
  /** Allow paying plain-http URLs (local testing only). */
19
21
  allowHttp: boolean;
20
22
  explorer?: string;
23
+ /**
24
+ * Token approval to Permit2, in days of `dailyLimit`. The agent approves only enough of its
25
+ * token for this many days of maximum spending, and renews when it runs low. 0 = unlimited.
26
+ */
27
+ approvalDays?: number;
21
28
  }
22
29
  export declare function configFromEnv(env?: NodeJS.ProcessEnv): TenderMcpConfig;
23
30
  export declare function createTenderMcp(cfg: TenderMcpConfig): {
package/dist/server.js CHANGED
@@ -1,9 +1,12 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
1
4
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
5
  import { z } from "zod";
3
6
  import { createPublicClient, createWalletClient, defineChain, erc20Abi, formatUnits, getAddress, http, isAddress, } from "viem";
4
7
  import { privateKeyToAccount } from "viem/accounts";
5
8
  import { HEADER_PAYMENT, HEADER_REQUIRED, HEADER_RESPONSE, ROBINHOOD, SCHEME_SWAP, buildPayment, decodeHeader, encodeHeader, ensurePermit2Approval, } from "@paywithtender/sdk";
6
- export const VERSION = "0.1.1";
9
+ export const VERSION = "0.1.3";
7
10
  const USD = 1000000n;
8
11
  function usdUnits(v, fallback) {
9
12
  const s = (v ?? fallback).replace("$", "").trim();
@@ -12,6 +15,14 @@ function usdUnits(v, fallback) {
12
15
  const [w, f = ""] = s.split(".");
13
16
  return BigInt(w) * USD + BigInt((f + "000000").slice(0, 6));
14
17
  }
18
+ function approvalDaysFromEnv(v) {
19
+ const s = (v ?? "7").trim().toLowerCase();
20
+ if (s === "unlimited" || s === "0")
21
+ return 0;
22
+ if (!/^\d+$/.test(s) || Number(s) > 365)
23
+ throw new Error("TENDER_APPROVAL_DAYS must be a whole number of days (1-365), or 'unlimited'");
24
+ return Number(s);
25
+ }
15
26
  export function configFromEnv(env = process.env) {
16
27
  const key = env.TENDER_PRIVATE_KEY?.trim();
17
28
  if (key && !/^0x[0-9a-fA-F]{64}$/.test(key))
@@ -31,7 +42,9 @@ export function configFromEnv(env = process.env) {
31
42
  maxPerCall: usdUnits(env.TENDER_MAX_PER_CALL_USD, "1"),
32
43
  maxFeePerCall: usdUnits(env.TENDER_MAX_FEE_USD, "0.10"),
33
44
  dailyLimit: usdUnits(env.TENDER_DAILY_LIMIT_USD, "10"),
45
+ approvalDays: approvalDaysFromEnv(env.TENDER_APPROVAL_DAYS),
34
46
  allowHttp: env.TENDER_ALLOW_HTTP === "true",
47
+ stateFile: env.TENDER_STATE_FILE === "none" ? undefined : env.TENDER_STATE_FILE || path.join(os.homedir(), ".tender", "spend.json"),
35
48
  explorer: chainId === ROBINHOOD.chainId ? "https://robinhoodchain.blockscout.com" : undefined,
36
49
  };
37
50
  }
@@ -65,15 +78,49 @@ export function createTenderMcp(cfg) {
65
78
  const pc = createPublicClient({ chain, transport: http(cfg.rpcUrl) });
66
79
  const account = cfg.privateKey ? privateKeyToAccount(cfg.privateKey) : undefined;
67
80
  const wallet = account ? createWalletClient({ chain, transport: http(cfg.rpcUrl), account }) : undefined;
68
- // Spending this process has done in the current UTC day.
69
- let day = new Date().toISOString().slice(0, 10);
70
- let spentToday = 0n;
81
+ // Today's spending, per wallet and UTC day. Kept in cfg.stateFile so restarting the server (or the AI app)
82
+ // can't hand the agent a fresh day's budget, and several server processes share one running total.
83
+ const today = () => new Date().toISOString().slice(0, 10);
84
+ const ledgerKey = account ? `${cfg.chainId}:${account.address.toLowerCase()}` : "";
85
+ let memDay = today();
86
+ let memSpent = 0n;
87
+ function readLedger() {
88
+ try {
89
+ return JSON.parse(fs.readFileSync(cfg.stateFile, "utf8"));
90
+ }
91
+ catch (e) {
92
+ if (e.code === "ENOENT")
93
+ return {};
94
+ throw new Error(`can't read the spending record at ${cfg.stateFile}: ${e.message}`);
95
+ }
96
+ }
71
97
  const spent = () => {
72
- const d = new Date().toISOString().slice(0, 10);
73
- if (d !== day)
74
- [day, spentToday] = [d, 0n];
75
- return spentToday;
98
+ const d = today();
99
+ if (!cfg.stateFile) {
100
+ if (d !== memDay)
101
+ [memDay, memSpent] = [d, 0n];
102
+ return memSpent;
103
+ }
104
+ const e = readLedger()[ledgerKey];
105
+ return e && e.day === d ? BigInt(e.spent) : 0n;
76
106
  };
107
+ function addSpent(delta) {
108
+ const d = today();
109
+ if (!cfg.stateFile) {
110
+ if (d !== memDay)
111
+ [memDay, memSpent] = [d, 0n];
112
+ memSpent = memSpent + delta < 0n ? 0n : memSpent + delta;
113
+ return;
114
+ }
115
+ const all = readLedger();
116
+ const cur = all[ledgerKey]?.day === d ? BigInt(all[ledgerKey].spent) : 0n;
117
+ const next = cur + delta < 0n ? 0n : cur + delta;
118
+ all[ledgerKey] = { day: d, spent: next.toString() };
119
+ fs.mkdirSync(path.dirname(cfg.stateFile), { recursive: true, mode: 0o700 });
120
+ const tmp = `${cfg.stateFile}.${process.pid}.tmp`;
121
+ fs.writeFileSync(tmp, JSON.stringify(all, null, 2), { mode: 0o600 });
122
+ fs.renameSync(tmp, cfg.stateFile);
123
+ }
77
124
  const tokenCache = new Map();
78
125
  async function token(addr) {
79
126
  const k = addr.toLowerCase();
@@ -213,7 +260,7 @@ export function createTenderMcp(cfg) {
213
260
  pc.readContract({ address: cfg.payWith, abi: erc20Abi, functionName: "balanceOf", args: [account.address] }),
214
261
  pc.readContract({ address: cfg.payWith, abi: erc20Abi, functionName: "allowance", args: [account.address, cfg.permit2] }),
215
262
  ]);
216
- lines.push(`Pays with ${info.symbol}: ${amt(bal, info.decimals)} (${allowance > 0n ? "ready" : "one-time approval happens on first payment"})`);
263
+ lines.push(`Pays with ${info.symbol}: ${amt(bal, info.decimals)} (${allowance > 0n ? "approved" : "approval happens on first payment"}${(cfg.approvalDays ?? 7) === 0 ? ", unlimited" : `, capped at ${cfg.approvalDays ?? 7} days of the daily limit`})`);
217
264
  Object.assign(structured, { payWith: info.symbol, payWithBalance: formatUnits(bal, info.decimals) });
218
265
  }
219
266
  else {
@@ -282,23 +329,19 @@ export function createTenderMcp(cfg) {
282
329
  const price = BigInt(opt.amount);
283
330
  if (price > cap)
284
331
  return fail(`The API wants ${money(price)}, above this agent's limit of ${money(cap)} per call. Nothing was paid.`);
285
- if (spent() + price > cfg.dailyLimit) {
286
- return fail(`Paying ${money(price)} would pass today's limit (${money(spent())} of ${money(cfg.dailyLimit)} used). Nothing was paid.`);
287
- }
288
- const tokenIn = payWith ?? cfg.usdg;
289
- const extra = (opt.extra ?? {});
332
+ let used;
290
333
  try {
291
- await ensurePermit2Approval({
292
- wallet,
293
- publicClient: pc,
294
- token: tokenIn,
295
- permit2: extra.permit2 ?? cfg.permit2,
296
- facilitator: extra.facilitator ?? cfg.facilitator,
297
- });
334
+ used = spent();
298
335
  }
299
336
  catch (e) {
300
- return fail(`One-time token approval failed: ${e.shortMessage ?? e.message}. Nothing was paid.`);
337
+ return fail(`Couldn't check today's spending: ${e.message}. Nothing was paid.`);
338
+ }
339
+ if (used + price > cfg.dailyLimit) {
340
+ return fail(`Paying ${money(price)} would pass today's limit (${money(used)} of ${money(cfg.dailyLimit)} used). Nothing was paid.`);
301
341
  }
342
+ const tokenIn = payWith ?? cfg.usdg;
343
+ const extra = (opt.extra ?? {});
344
+ // Sign first (no allowance needed to sign), so the approval can be sized from the real quote.
302
345
  let payload;
303
346
  try {
304
347
  payload = await buildPayment(pc, { account, chain, rpcUrl: cfg.rpcUrl, payWith: payWith ?? undefined, maxUsdgPerCall: cap, maxFeePerCall: cfg.maxFeePerCall }, required, cap);
@@ -306,13 +349,48 @@ export function createTenderMcp(cfg) {
306
349
  catch (e) {
307
350
  return fail(`Couldn't prepare the payment: ${e.message}. Nothing was paid.`);
308
351
  }
352
+ // Permit2 payments need an approval. Capped by default: enough of this token for
353
+ // TENDER_APPROVAL_DAYS days at the daily limit, never an unlimited allowance.
354
+ const permit = payload.payload.permit;
355
+ if (permit) {
356
+ const needed = BigInt(permit.permitted.amount);
357
+ const days = cfg.approvalDays ?? 7;
358
+ const amount = days === 0 ? undefined : (needed * cfg.dailyLimit * BigInt(days)) / (price > 0n ? price : 1n);
359
+ try {
360
+ await ensurePermit2Approval({
361
+ wallet,
362
+ publicClient: pc,
363
+ token: tokenIn,
364
+ permit2: extra.permit2 ?? cfg.permit2,
365
+ facilitator: extra.facilitator ?? cfg.facilitator,
366
+ amount,
367
+ needed,
368
+ });
369
+ }
370
+ catch (e) {
371
+ return fail(`Token approval failed: ${e.shortMessage ?? e.message}. Nothing was paid.`);
372
+ }
373
+ }
309
374
  const h = new Headers(init.headers);
310
375
  h.set(HEADER_PAYMENT, encodeHeader(payload));
311
- const paid = await fetch(target, { ...init, headers: h });
376
+ // count the payment before sending it, so parallel calls and crashes can't overspend; give it back only if it clearly failed
377
+ try {
378
+ addSpent(price);
379
+ }
380
+ catch (e) {
381
+ return fail(`Couldn't record today's spending: ${e.message}. Nothing was paid.`);
382
+ }
383
+ let paid;
384
+ try {
385
+ paid = await fetch(target, { ...init, headers: h });
386
+ }
387
+ catch (e) {
388
+ return fail(`The API couldn't be reached after signing (${e.message}). The payment may or may not have settled, so ${money(price)} stays counted toward today's limit.`);
389
+ }
312
390
  const settleHeader = paid.headers.get(HEADER_RESPONSE);
313
391
  const settle = settleHeader ? decodeHeader(settleHeader) : null;
314
- if (settle?.success)
315
- spentToday = spent() + price;
392
+ if ((settle && !settle.success) || (!settle && paid.status === 402))
393
+ addSpent(-price);
316
394
  return respond(paid, settle ? { ...settle, price, tokenIn } : null);
317
395
  });
318
396
  async function respond(res, payment) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paywithtender/mcp",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "mcpName": "io.github.paywithtender/tender",
5
5
  "description": "MCP server that lets any AI agent pay x402 APIs with any token on Robinhood Chain, through Tender.",
6
6
  "license": "MIT",
@@ -24,7 +24,7 @@
24
24
  "main": "./dist/server.js",
25
25
  "types": "./dist/server.d.ts",
26
26
  "bin": {
27
- "tender-mcp": "./dist/cli.js"
27
+ "tender-mcp": "dist/cli.js"
28
28
  },
29
29
  "exports": {
30
30
  ".": {
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "@modelcontextprotocol/sdk": "^1.32.2",
48
- "@paywithtender/sdk": "^0.1.2",
48
+ "@paywithtender/sdk": "^0.1.3",
49
49
  "viem": "^2.21.0",
50
50
  "zod": "^4.1.0"
51
51
  },