@aifinpay/mcp 1.5.3 → 2.0.0-rc.13

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.
Files changed (47) hide show
  1. package/README.md +116 -69
  2. package/bin/aifinpay-mcp.js +119 -49
  3. package/dist/api.d.ts +2 -0
  4. package/dist/api.d.ts.map +1 -0
  5. package/dist/api.js +6 -0
  6. package/dist/api.js.map +1 -0
  7. package/dist/config.d.ts +35 -2
  8. package/dist/config.d.ts.map +1 -1
  9. package/dist/config.js +63 -0
  10. package/dist/config.js.map +1 -1
  11. package/dist/identity.d.ts +9 -0
  12. package/dist/identity.d.ts.map +1 -0
  13. package/dist/identity.js +75 -0
  14. package/dist/identity.js.map +1 -0
  15. package/dist/index.d.ts +3 -6
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +3 -6
  18. package/dist/index.js.map +1 -1
  19. package/dist/safe-fetch.d.ts +2 -0
  20. package/dist/safe-fetch.d.ts.map +1 -1
  21. package/dist/safe-fetch.js +76 -17
  22. package/dist/safe-fetch.js.map +1 -1
  23. package/dist/server.d.ts +11 -8
  24. package/dist/server.d.ts.map +1 -1
  25. package/dist/server.js +106 -102
  26. package/dist/server.js.map +1 -1
  27. package/dist/tools/agent-address.d.ts.map +1 -1
  28. package/dist/tools/agent-address.js +6 -27
  29. package/dist/tools/agent-address.js.map +1 -1
  30. package/dist/tools/agent-history.d.ts +58 -0
  31. package/dist/tools/agent-history.d.ts.map +1 -0
  32. package/dist/tools/agent-history.js +73 -0
  33. package/dist/tools/agent-history.js.map +1 -0
  34. package/dist/tools/agent-quota.d.ts +40 -0
  35. package/dist/tools/agent-quota.d.ts.map +1 -0
  36. package/dist/tools/agent-quota.js +95 -0
  37. package/dist/tools/agent-quota.js.map +1 -0
  38. package/dist/tools/dev-payment-quote.d.ts +39 -0
  39. package/dist/tools/dev-payment-quote.d.ts.map +1 -0
  40. package/dist/tools/dev-payment-quote.js +52 -0
  41. package/dist/tools/dev-payment-quote.js.map +1 -0
  42. package/dist/tools/production-control.d.ts +108 -0
  43. package/dist/tools/production-control.d.ts.map +1 -0
  44. package/dist/tools/production-control.js +132 -0
  45. package/dist/tools/production-control.js.map +1 -0
  46. package/package.json +8 -22
  47. package/skills/SKILL.md +143 -0
@@ -0,0 +1,132 @@
1
+ import { apiUrl } from "../api.js";
2
+ const DEFAULT_BASE = "https://aifinpay.io";
3
+ const ROUTES = new Set(["AIFP-1", "AIFP-2"]);
4
+ const CHAINS = new Set([
5
+ "polygon", "avalanche", "arbitrum", "bnb", "base",
6
+ "unichain", "optimism", "botchain", "xrplevm",
7
+ ]);
8
+ function result(value) {
9
+ return { content: [{ type: "text", text: JSON.stringify(value, null, 2) }] };
10
+ }
11
+ function errorResult(message) {
12
+ return { isError: true, content: [{ type: "text", text: message }] };
13
+ }
14
+ function base(ctx) {
15
+ return String(ctx.config.baseUrl || DEFAULT_BASE).replace(/\/$/, "");
16
+ }
17
+ async function api(ctx, path, init) {
18
+ const response = await ctx.agent.inner.fetchImpl(apiUrl(base(ctx), path), init);
19
+ const body = await response.json().catch(() => null);
20
+ if (!response.ok) {
21
+ const detail = body && typeof body === "object"
22
+ ? JSON.stringify(body)
23
+ : `HTTP ${response.status}`;
24
+ throw new Error(detail);
25
+ }
26
+ return body;
27
+ }
28
+ export function agentPassportResolveTool() {
29
+ return {
30
+ name: "agent_passport_resolve",
31
+ description: "Resolve an AiFinPay Agent Passport by @username, permanent AIFP number, or immutable agent id. " +
32
+ "Returns verified public wallet bindings only. Resolution never authorizes a payment.",
33
+ inputSchema: {
34
+ type: "object",
35
+ properties: {
36
+ identifier: { type: "string", description: "@username, AIFP-#########, or aifp_agent_* id" },
37
+ },
38
+ required: ["identifier"],
39
+ },
40
+ annotations: { readOnlyHint: true, openWorldHint: false, destructiveHint: false },
41
+ outputSchema: { type: "object" },
42
+ };
43
+ }
44
+ export async function runAgentPassportResolve(ctx, args) {
45
+ const identifier = String(args.identifier || "").trim();
46
+ if (!identifier)
47
+ return errorResult("missing required arg: identifier");
48
+ try {
49
+ const body = await api(ctx, `/api/agent/resolve/${encodeURIComponent(identifier)}`);
50
+ return result(body);
51
+ }
52
+ catch (e) {
53
+ return errorResult(`Agent Passport resolve failed: ${e.message}`);
54
+ }
55
+ }
56
+ export function settlementRoutesTool() {
57
+ return {
58
+ name: "settlement_routes",
59
+ description: "Read AiFinPay's currently runtime-verified v1.3 settlement routes. " +
60
+ "AIFP-1 is merchant monetisation (99% merchant / 1% AiFinPay / 0% creator). " +
61
+ "AIFP-2/x402 is 100% provider / 0% AiFinPay / 0% creator.",
62
+ inputSchema: {
63
+ type: "object",
64
+ properties: {
65
+ route_class: { type: "string", enum: ["AIFP-1", "AIFP-2"] },
66
+ },
67
+ },
68
+ annotations: { readOnlyHint: true, openWorldHint: false, destructiveHint: false },
69
+ outputSchema: { type: "object" },
70
+ };
71
+ }
72
+ export async function runSettlementRoutes(ctx, args) {
73
+ const route = args.route_class == null ? "" : String(args.route_class).toUpperCase();
74
+ if (route && !ROUTES.has(route))
75
+ return errorResult("route_class must be AIFP-1 or AIFP-2");
76
+ try {
77
+ return result(await api(ctx, `/v1/settlement/routes${route ? `?route_class=${encodeURIComponent(route)}` : ""}`));
78
+ }
79
+ catch (e) {
80
+ return errorResult(`Settlement route lookup failed: ${e.message}`);
81
+ }
82
+ }
83
+ export function settlementInvoiceTool() {
84
+ return {
85
+ name: "settlement_invoice",
86
+ description: "Build and validate a NON-SIGNING v1.3 settlement invoice. This tool never moves funds. " +
87
+ "Use the published @aifinpay/agent v2 settlement executor to verify bytecode/profile and sign it.",
88
+ inputSchema: {
89
+ type: "object",
90
+ properties: {
91
+ route_class: { type: "string", enum: ["AIFP-1", "AIFP-2"] },
92
+ chain: { type: "string", enum: [...CHAINS] },
93
+ asset: { type: "string", description: "Native symbol, USDC, or USDT if the route advertises it." },
94
+ gross_amount: { type: "string", description: "Gross payer amount in base units." },
95
+ merchant_wallet: { type: "string", description: "Merchant/provider EVM wallet." },
96
+ order_id: { type: "string" },
97
+ valid_until: { type: "integer", description: "Optional Unix seconds, max 20 minutes ahead." },
98
+ },
99
+ required: ["route_class", "chain", "asset", "gross_amount", "merchant_wallet", "order_id"],
100
+ },
101
+ annotations: { readOnlyHint: true, openWorldHint: false, destructiveHint: false },
102
+ outputSchema: { type: "object" },
103
+ };
104
+ }
105
+ export async function runSettlementInvoice(ctx, args) {
106
+ const route = String(args.route_class || "").toUpperCase();
107
+ const chain = String(args.chain || "").toLowerCase();
108
+ if (!ROUTES.has(route))
109
+ return errorResult("route_class must be AIFP-1 or AIFP-2");
110
+ if (!CHAINS.has(chain))
111
+ return errorResult("unsupported EVM settlement chain");
112
+ try {
113
+ const payload = {
114
+ route_class: route,
115
+ chain,
116
+ asset: String(args.asset || "").toUpperCase(),
117
+ gross_amount: String(args.gross_amount || ""),
118
+ merchant_wallet: String(args.merchant_wallet || ""),
119
+ order_id: String(args.order_id || ""),
120
+ ...(args.valid_until != null ? { valid_until: Number(args.valid_until) } : {}),
121
+ };
122
+ return result(await api(ctx, "/v1/settlement/invoice", {
123
+ method: "POST",
124
+ headers: { "content-type": "application/json" },
125
+ body: JSON.stringify(payload),
126
+ }));
127
+ }
128
+ catch (e) {
129
+ return errorResult(`Settlement invoice failed: ${e.message}`);
130
+ }
131
+ }
132
+ //# sourceMappingURL=production-control.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"production-control.js","sourceRoot":"","sources":["../../src/tools/production-control.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,MAAM,YAAY,GAAG,qBAAqB,CAAC;AAC3C,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;AAC7C,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC;IACrB,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM;IACjD,UAAU,EAAE,UAAU,EAAE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AC,WAAW,EAAE;YAC7C,YAAY,EAAE,MAAM,CAAC,IAAI,CAAC,YAAY,IAAI,EAAE,CAAC;YAC7C,eAAe,EAAE,MAAM,CAAC,IAAI,CAAC,eAAe,IAAI,EAAE,CAAC;YACnD,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAC;YACrC,GAAG,CAAC,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC/E,CAAC;QACF,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,GAAG,EAAE,wBAAwB,EAAE;YACrD,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;SAC9B,CAAC,CAAC,CAAC;IACN,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,WAAW,CAAC,8BAA+B,CAAW,CAAC,OAAO,EAAE,CAAC,CAAC;IAC3E,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@aifinpay/mcp",
3
- "version": "1.5.3",
4
- "description": "Pay-per-call MCP server for autonomous AI agents \u2014 installs in Claude Desktop / Cursor / Continue with one config block; on-chain settlement on Polygon and Solana via x402.",
3
+ "version": "2.0.0-rc.13",
4
+ "description": "AiFinPay MCP production-RC control surface for Agent Passport resolution and runtime-verified AIFP-1/AIFP-2 settlement invoices. Signing tools remain gated until @aifinpay/agent v2 release.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -18,7 +18,8 @@
18
18
  "dist",
19
19
  "bin",
20
20
  "README.md",
21
- "LICENSE"
21
+ "LICENSE",
22
+ "skills"
22
23
  ],
23
24
  "scripts": {
24
25
  "build": "tsc -p tsconfig.json",
@@ -32,10 +33,9 @@
32
33
  "mcp-server",
33
34
  "mcp-payments",
34
35
  "mcp-monetization",
35
- "paid-mcp-tools",
36
+ "agent-passport",
37
+ "settlement",
36
38
  "x402-mcp",
37
- "pay-per-call",
38
- "paid-ai-tools",
39
39
  "claude-desktop",
40
40
  "claude-mcp",
41
41
  "cursor",
@@ -46,29 +46,15 @@
46
46
  "ai-agent-payments",
47
47
  "agentic-ai",
48
48
  "autonomous-agents",
49
- "autonomous-payments",
50
49
  "agent-payments",
51
50
  "agent-commerce",
52
51
  "agentic-commerce",
53
52
  "agent-economy",
54
53
  "ai-commerce",
55
- "ai-payment-infrastructure",
56
- "ai-financial-infrastructure",
57
54
  "x402",
58
55
  "x402-payments",
59
56
  "http-402",
60
- "payments",
61
- "api-payments",
62
- "api-monetization",
63
- "machine-payments",
64
- "m2m-payments",
65
- "programmable-payments",
66
- "crypto-payments",
67
- "stablecoin-payments",
68
- "polygon",
69
- "solana",
70
- "non-custodial",
71
- "stripe-for-ai-agents"
57
+ "non-custodial"
72
58
  ],
73
59
  "author": "CoinSecurities (SECCO) <contact@aifinpay.io>",
74
60
  "license": "MIT",
@@ -80,7 +66,7 @@
80
66
  },
81
67
  "bugs": "https://github.com/AiFinPay/sdk/issues",
82
68
  "dependencies": {
83
- "@aifinpay/agent": "^1.8.1",
69
+ "@aifinpay/agent": "2.0.0-rc.13",
84
70
  "@modelcontextprotocol/sdk": "^1.0.0",
85
71
  "bs58": "^6.0.0",
86
72
  "tweetnacl": "^1.0.3"
@@ -0,0 +1,143 @@
1
+ ---
2
+ name: aifinpay
3
+ description: Discover an agent wallet, retrieve payment history and prepaid quotas, resolve public Agent Passport identities, and inspect dev payment quotes through AiFinPay MCP/SDK.
4
+ license: MIT
5
+ ---
6
+
7
+ The current source and compatible package line is **2.0.0-rc.12**. Until that
8
+ RC is published, use the checked-out source build or an explicitly pinned
9
+ compatible package; never install `latest` for a payment test. The production
10
+ RC tool inventory below is read-only; do not claim MCP signing or AIFP-2
11
+ settlement is active.
12
+
13
+ # AiFinPay agent workflow
14
+
15
+ Use the tools actually returned by MCP tools/list. This RC exposes
16
+ agent_address, agent_reload, agent_history, agent_quota,
17
+ agent_passport_resolve, settlement_routes and settlement_invoice.
18
+ With AIFINPAY_MODE=dev it also exposes dev_payment_quote.
19
+ It does not register payable_fetch, agent_call or other payment-signing tools.
20
+ Never tell a user a payment was sent because a quote or invoice was created.
21
+
22
+ ## Wallet source priority
23
+
24
+ The local server selects one identity in this order:
25
+
26
+ 1. SEED_HASH environment variable: 32-byte hex seed, 64 hex characters,
27
+ optionally prefixed with 0x. Passed directly to AiFinPayAgent.fromSeed;
28
+ no second hash, no mnemonic conversion.
29
+ 2. ./aifinpay/agents.json relative to the MCP process working directory.
30
+ AIFINPAY_AGENTS_FILE may name an explicit absolute path.
31
+ 3. Legacy AIFINPAY_AGENT_SECRET base58 secret.
32
+ 4. Legacy ~/.aifinpay/agent.json (or AIFINPAY_HOME/agent.json).
33
+
34
+ The project-file schema is:
35
+
36
+ ```json
37
+ {"agents":[{"id":"research-agent","seed_hash":"REDACTED"}]}
38
+ ```
39
+
40
+ REDACTED is a placeholder, not a usable seed. With more than one record,
41
+ AIFINPAY_AGENT_ID must select exactly one id. Invalid configured sources stop
42
+ loading; they never silently generate a new wallet or fall back to another.
43
+ Keep secret files private (mode 600), outside Git and outside chat. Never ask
44
+ for a real seed, print it, or send it to the backend. Use agent_address to
45
+ confirm the public wallet selected. With no configured identity the server
46
+ uses an ephemeral wallet: do not fund it.
47
+
48
+ ## Init and reconnect
49
+
50
+ For a funded crawler or balance check, load the existing persistent identity
51
+ first through the configured MCP identity sources or
52
+ `AiFinPayAgent.fromEnvironment()`. If none exists, stop and ask the operator
53
+ to configure one; never call `Agent.new()` to create a wallet that will be
54
+ funded. `npx @aifinpay/mcp@2.0.0-rc.12 init` creates the legacy keystore only when no
55
+ configured wallet exists. It preserves existing wallets. After init or a local
56
+ wallet-file update, call agent_reload in the existing MCP connection, then agent_address.
57
+ The reload returns only public addresses and preserves the old identity if
58
+ loading fails. This server does not require a new conversation.
59
+
60
+ On an interactive TTY, init may print a one-time private-key recovery line for
61
+ the operator to back up offline. Automated agents must never request, capture,
62
+ log or repeat that line; non-interactive runs suppress it.
63
+
64
+ Installing a new package or changing launch environment variables requires the
65
+ MCP host to launch/reconnect the server process. Shell exports cannot change an
66
+ already running process. Whether the host can reconnect in the same UI session
67
+ is client-specific; do not universally prescribe restarting the whole chat.
68
+
69
+ ## Payment history is required before reporting spend
70
+
71
+ Use agent_history. Do not guess /v1/history, /v1/payments or /v1/wallet/tx.
72
+
73
+ ```json
74
+ {"address":"0x…","source":"transactions","limit":25,"offset":0}
75
+ ```
76
+
77
+ ```json
78
+ {"passport":"AIFP-000000042","source":"receipts","network":"polygon"}
79
+ ```
80
+
81
+ An omitted address/passport uses the current wallet. With both inputs, the
82
+ address must match the passport's verified wallet on the requested network.
83
+ Passport accepts a public @username, AIFP number or aifp_agent_* id; a secret
84
+ API key or holder private key is not a passport identifier. The backend
85
+ resolver must be deployed. A 404/403/503 is unavailable history, not proof
86
+ that the agent made no payments.
87
+
88
+ Routes:
89
+
90
+ - GET /v1/agents/:address/transactions?chain=polygon&limit=25&offset=0:
91
+ public facts from indexed AiFinPay Polygon settlements in the durable
92
+ ledger. Excludes arbitrary wallet transfers and may lag the chain.
93
+ - GET /v1/agents/:address/receipts?limit=25&offset=0: retained prepaid-batch
94
+ metadata, including test payments. Never includes the spendable receipt JWT.
95
+ - GET /v1/agents/:address/statement?days=7: retained billing statement.
96
+ - GET /api/agent/resolve/:identifier: public verified passport wallet bindings,
97
+ only on backends with the Agent Passport service installed.
98
+
99
+ On https://api.aifinpay.io the resolver path is /agent/resolve/:identifier
100
+ because ingress adds /api. Keep /v1 paths unchanged. On the main host or a
101
+ normal dev backend, the resolver includes /api.
102
+
103
+ Amounts from the ledger are integer strings in token base units. Do not turn
104
+ uint256 amounts into JavaScript numbers. Use next_offset for the next page.
105
+ Receipt history is retained metadata, not a full blockchain explorer. External
106
+ merchants may meter quotas locally; AiFinPay's remaining count can lag.
107
+
108
+ Node SDK: getAgentHistory({address, passport, source, network, limit, offset,
109
+ baseUrl}) uses the same route flow. Retrieve a paid bearer receipt separately
110
+ with the signed recovery API; never put it in a public history report.
111
+
112
+ After a settlement error, retain the original quote, transaction reference and
113
+ idempotency context and use the recovery path before another attempt. A new
114
+ quote or a new `fetchPaid` call may charge again; this RC has no payment
115
+ executor. `dev.ratersapp.com` is only a hostname, not proof of testnet or dev
116
+ settlement. Validate the 402 challenge and quote's `network_mode`, chain and
117
+ deployed contract before any approved executor could settle.
118
+
119
+ ## Dev paid-content inspection
120
+
121
+ Configure AIFINPAY_MODE=dev and a separate AIFINPAY_BASE_URL. The backend must
122
+ have AIFP_DEV_MODE=true and AIFP_DEV_MERCHANT_ID pointing to an existing test
123
+ merchant. GET /v1/dev/paid/data then uses the real receipt gate. Live merchants
124
+ are rejected; a missing config cannot enable free access.
125
+
126
+ Call dev_payment_quote({contract_version:"1.2" or "1.4", units:1000}). It reads
127
+ the 402 and requests a batch quote. The quote must name only Amoy, test mode,
128
+ the same merchant/resource and the requested deployed contract version.
129
+ Changing a requested version does not redeploy a contract or relabel its ABI;
130
+ a mismatch stops the flow. The operator must configure the corresponding
131
+ verified SPLITTER_ADDRESS_AMOY deployment first. Minimum-unit and cap errors
132
+ stop the request; do not lower units below the server minimum, edit quote
133
+ responses, or invent manual nonces, receipts or transactions.
134
+
135
+ This tool never broadcasts. Current MCP has no settlement executor; SDK
136
+ fetchPaid remains gated and is not a general Amoy 1.2/1.4 executor. Finish
137
+ that executor's deployment verification and paid testnet E2E before claiming
138
+ the full dev payment loop works. A prepaid batch means one settlement funding
139
+ multiple API calls, not an arbitrary batch of on-chain transfers.
140
+
141
+ After any actual settlement, retain its quote and transaction reference.
142
+ Retry receipt issuance on temporary errors without paying again. Inspect
143
+ agent_history(source:"receipts") and agent_quota to report the result.