agentpay-mcp 4.1.0 → 4.1.4

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 (34) hide show
  1. package/README.md +299 -2
  2. package/dist/index.js +19 -0
  3. package/dist/index.js.map +1 -1
  4. package/dist/tools/otel-budget.d.ts +265 -0
  5. package/dist/tools/otel-budget.d.ts.map +1 -0
  6. package/dist/tools/otel-budget.js +399 -0
  7. package/dist/tools/otel-budget.js.map +1 -0
  8. package/dist/tools/session.d.ts.map +1 -1
  9. package/dist/tools/session.js +2 -0
  10. package/dist/tools/session.js.map +1 -1
  11. package/dist/tools/x402.d.ts.map +1 -1
  12. package/dist/tools/x402.js +58 -0
  13. package/dist/tools/x402.js.map +1 -1
  14. package/dist/utils/client.d.ts.map +1 -1
  15. package/dist/utils/client.js +8 -1
  16. package/dist/utils/client.js.map +1 -1
  17. package/dist/utils/x402-networks.d.ts +12 -0
  18. package/dist/utils/x402-networks.d.ts.map +1 -0
  19. package/dist/utils/x402-networks.js +30 -0
  20. package/dist/utils/x402-networks.js.map +1 -0
  21. package/docs/channel-agent-affiliate-controls.md +142 -0
  22. package/docs/hitl-reference-architecture.md +140 -0
  23. package/docs/security-posture.md +74 -0
  24. package/docs/trust-architecture.md +127 -0
  25. package/docs/vercel-deployment-hardening.md +115 -0
  26. package/docs/whatsapp-smb-agent-controls.md +130 -0
  27. package/docs/x402-batch-settlement-channels.md +199 -0
  28. package/docs/x402-bazaar-observability.md +209 -0
  29. package/docs/x402-chain-drift-compatibility.md +63 -0
  30. package/docs/x402-mcp-funding-ux-benchmark.md +36 -0
  31. package/docs/x402-multi-sdk-batch-settlement-parity.md +167 -0
  32. package/docs/x402-scanner-readiness.md +110 -0
  33. package/docs/x402-tvm-readiness.md +53 -0
  34. package/package.json +6 -5
@@ -0,0 +1,140 @@
1
+ # AgentPay MCP: HITL Reference Architecture for Payment Authorization
2
+
3
+ > The reference implementation for human-in-the-loop payment workflows in MCP-compatible agents.
4
+
5
+ ## Why HITL Matters
6
+
7
+ McKinsey's 2026 AI Trust Maturity Survey found that only **14.4% of enterprises formally approve AI agents before deployment**, while **88% report at least one agent security incident**. For payment operations specifically, just **18% of enterprises are confident in their agent IAM**.
8
+
9
+ The implication is clear: autonomous agent payments without human oversight are a non-starter for enterprise adoption. The question isn't whether HITL is needed — it's how to implement it without destroying the autonomy that makes agents valuable.
10
+
11
+ ## The Pattern: Suggest → Approve → Execute
12
+
13
+ AgentPay MCP implements a three-phase payment authorization pattern:
14
+
15
+ ```
16
+ Phase 1: SUGGEST
17
+ Agent encounters a paid API (HTTP 402)
18
+ AgentPay MCP evaluates spending policy
19
+ If amount > human_approval_threshold:
20
+ → Payment is BLOCKED (not executed)
21
+ → Human receives approval request
22
+
23
+ Phase 2: APPROVE
24
+ Human reviews: merchant, amount, context
25
+ Human decides: approve or reject
26
+ Decision is logged with timestamp
27
+
28
+ Phase 3: EXECUTE
29
+ If approved → payment executes on-chain
30
+ If rejected → agent receives rejection, adapts
31
+ Full audit trail recorded regardless
32
+ ```
33
+
34
+ ### Code Example: Human-Approval Payment Flow
35
+
36
+ ```python
37
+ from smolagents import CodeAgent, InferenceClientModel
38
+ from smolagents.x402_payment_tool import X402PaymentTool, SpendingPolicy, PaymentMode
39
+
40
+ # Configure HITL: auto-approve under $1, require human approval above
41
+ payment_tool = X402PaymentTool(
42
+ spending_policy=SpendingPolicy(
43
+ mode=PaymentMode.LIVE,
44
+ max_per_transaction=10.00,
45
+ rolling_cap=100.00,
46
+ require_human_approval=True,
47
+ human_approval_threshold=1.00,
48
+ merchant_allowlist=["api.example.com", "data.provider.io"],
49
+ )
50
+ )
51
+
52
+ agent = CodeAgent(
53
+ tools=[payment_tool],
54
+ model=InferenceClientModel(),
55
+ )
56
+
57
+ # Agent workflow:
58
+ # 1. Agent calls api.example.com → gets HTTP 402 for $0.50
59
+ # → Auto-approved (under $1 threshold) → paid → data returned
60
+ #
61
+ # 2. Agent calls data.provider.io → gets HTTP 402 for $3.50
62
+ # → BLOCKED → human sees:
63
+ # "Agent wants to pay $3.50 to data.provider.io — approve? [y/n]"
64
+ # → Human approves → paid → data returned
65
+ # → OR human rejects → agent receives error, tries alternative
66
+ ```
67
+
68
+ ### MCP Server Configuration
69
+
70
+ ```json
71
+ {
72
+ "mcpServers": {
73
+ "agentpay": {
74
+ "command": "npx",
75
+ "args": ["agentpay-mcp"],
76
+ "env": {
77
+ "AGENT_PRIVATE_KEY": "0x...",
78
+ "AGENT_WALLET_ADDRESS": "0x..."
79
+ }
80
+ }
81
+ }
82
+ }
83
+ ```
84
+
85
+ The HITL behavior is configured via `set_spend_policy` tool:
86
+
87
+ ```json
88
+ {
89
+ "tool": "set_spend_policy",
90
+ "arguments": {
91
+ "perTxCapEth": "0.004",
92
+ "dailyLimitEth": "0.04",
93
+ "requireHumanApproval": true,
94
+ "humanApprovalThreshold": "0.0004",
95
+ "allowedRecipients": ["0x..."]
96
+ }
97
+ }
98
+ ```
99
+
100
+ ## Why This Architecture Works
101
+
102
+ ### 1. Graduated Autonomy
103
+
104
+ Not every payment needs human review. The threshold model lets agents handle routine micropayments autonomously while escalating significant transactions. This preserves agent utility without sacrificing oversight.
105
+
106
+ ### 2. On-Chain Enforcement
107
+
108
+ The spending caps aren't in application code — they're in the AgentAccountV2 smart contract. Even if the agent, the MCP server, or the host application is compromised, the on-chain limits hold. The human-approval gate is the last line of defense, not the only one.
109
+
110
+ ### 3. Audit Trail for Compliance
111
+
112
+ Every payment attempt (approved, rejected, or auto-approved) is logged with:
113
+ - Merchant/recipient address
114
+ - Amount requested
115
+ - Policy evaluation result
116
+ - Human decision (if applicable)
117
+ - On-chain transaction hash (if executed)
118
+
119
+ This gives compliance teams the artifact trail they need for SOC 2, financial audits, and regulatory reporting.
120
+
121
+ ## MCP 2026 Roadmap Alignment
122
+
123
+ The MCP specification is evolving toward mandatory security controls for financial operations:
124
+
125
+ - **CoSAI T9 (Financial Fraud):** AgentPay MCP's HITL pattern directly addresses this threat category
126
+ - **OAuth 2.1 + PKCE:** Enterprise authentication for MCP server access (see [security-posture.md](security-posture.md))
127
+ - **Standardized approval UX:** The `queue_approval` tool provides a consistent interface that MCP clients (Claude Desktop, Cursor, etc.) can render as native approval dialogs
128
+
129
+ ## Production Reference
130
+
131
+ This HITL payment architecture is already in production:
132
+
133
+ - **[NVIDIA NeMo Agent Toolkit Examples PR #17](https://github.com/NVIDIA/NeMo-Agent-Toolkit-Examples/pull/17)** — x402 payment tool merged into NVIDIA's official agent toolkit catalog
134
+ - **[smolagents PR #2123](https://github.com/huggingface/smolagents/pull/2123)** — Native x402 payment tool with HITL support, addressing community request [#2112](https://github.com/huggingface/smolagents/issues/2112) for human-in-the-loop payment authorization
135
+
136
+ ## Related Documentation
137
+
138
+ - [Security Posture](security-posture.md) — CoSAI alignment and OAuth 2.1 compliance
139
+ - [README](../README.md) — Full AgentPay MCP documentation
140
+ - [SECURITY.md](../SECURITY.md) — Responsible disclosure process
@@ -0,0 +1,74 @@
1
+ # AgentPay MCP — Security Posture
2
+
3
+ > Last updated: 2026-03-26
4
+
5
+ This document maps AgentPay MCP's security controls to the CoSAI (Coalition for Secure AI) threat taxonomy and MCP 2026 authentication requirements. It is intended for enterprise security teams evaluating MCP servers for production deployment.
6
+
7
+ ## CoSAI Threat Alignment
8
+
9
+ ### T9 — Financial Fraud
10
+
11
+ **Threat:** An AI agent is manipulated (via prompt injection, tool poisoning, or logic error) into making unauthorized payments.
12
+
13
+ **Mitigations in AgentPay MCP:**
14
+
15
+ | Control | Implementation | Bypass Resistance |
16
+ |---------|---------------|-------------------|
17
+ | Per-transaction spending cap | `set_spend_policy` enforced by AgentAccountV2 smart contract | On-chain — cannot be overridden by application code or the agent |
18
+ | Rolling period limits | Daily/weekly caps enforced on-chain | Same — smart contract enforcement |
19
+ | Merchant allowlist | Only pre-approved recipient addresses can receive funds | On-chain enforcement |
20
+ | Human-approval gate | Transactions above configurable threshold queue for human review | Cannot be bypassed — `queue_approval` requires explicit human action |
21
+ | Fail-closed policy engine | Any error in policy evaluation → transaction rejected | Default-deny; no silent pass-through |
22
+ | Full audit trail | Every payment attempt logged: merchant, amount, timestamp, approval status, tx hash | Immutable on-chain record |
23
+
24
+ ### T10 — Identity Spoofing
25
+
26
+ **Threat:** A malicious agent impersonates a legitimate agent to gain access to payment infrastructure or services.
27
+
28
+ **Mitigations in AgentPay MCP:**
29
+
30
+ | Control | Implementation |
31
+ |---------|---------------|
32
+ | ERC-8004 identity verification | `verify_agent_identity` tool validates on-chain agent identity NFTs |
33
+ | Non-custodial key management | Agent private key stored locally; never transmitted to any server |
34
+ | On-chain reputation | `get_reputation` provides verifiable transaction history and trust score |
35
+ | Session token verification | x402 session tokens are ECDSA-signed; any verifier can independently validate |
36
+
37
+ ## OAuth 2.1 + PKCE Compliance
38
+
39
+ MCP 2026 roadmap requires OAuth 2.1 with PKCE for server authentication in enterprise environments.
40
+
41
+ **Current status:**
42
+
43
+ - AgentPay MCP supports configuration via environment variables (`AGENT_PRIVATE_KEY`, `AGENT_WALLET_ADDRESS`) for direct deployment
44
+ - For enterprise SSO: Azure AD and Okta can broker OAuth 2.1 tokens that gate access to the MCP server process
45
+ - PKCE flow: supported when deployed behind an OAuth 2.1-compliant reverse proxy (e.g., Azure API Management, Auth0)
46
+ - The MCP server itself authenticates agents via their on-chain identity (ERC-8004) and wallet signature, which provides cryptographic authentication independent of OAuth
47
+
48
+ **Roadmap:**
49
+
50
+ - Native OAuth 2.1 token validation in the MCP server transport layer (aligned with MCP spec evolution)
51
+ - Mutual TLS option for server-to-server deployments
52
+
53
+ ## MCP Audit Logging
54
+
55
+ Every tool invocation is logged with:
56
+
57
+ - Timestamp (ISO 8601)
58
+ - Tool name and parameters
59
+ - Outcome (success/failure/queued)
60
+ - Transaction hash (for on-chain operations)
61
+ - Policy evaluation result (approved/rejected/queued with reason)
62
+
63
+ Logs are available via `get_transaction_history` tool and can be exported to enterprise SIEM systems.
64
+
65
+ ## Dependency Security
66
+
67
+ - **Zero LiteLLM dependency** — no exposure to the March 2026 PyPI supply chain compromise
68
+ - **Minimal npm dependency tree** — `viem`, `@modelcontextprotocol/sdk`, and auditable packages only
69
+ - **No Python runtime required** — eliminates PyPI supply chain attack surface entirely
70
+ - **NVIDIA-validated** — security posture reviewed as part of [NVIDIA NeMo Agent Toolkit Examples PR #17](https://github.com/NVIDIA/NeMo-Agent-Toolkit-Examples/pull/17) merge process
71
+
72
+ ## Contact
73
+
74
+ Security issues: see [SECURITY.md](../SECURITY.md) for responsible disclosure process.
@@ -0,0 +1,127 @@
1
+ # AgentPay MCP Trust Architecture
2
+
3
+ **Simulation Mode · Spend Caps · Human-in-the-Loop · Transaction Explainability**
4
+
5
+ ---
6
+
7
+ ## The Problem: Agent Autonomy Without Trust Infrastructure
8
+
9
+ Autonomous agents that handle money need more than API keys and wallet addresses. They need a trust architecture — a layered system of controls that lets operators grant autonomy incrementally, verify behavior continuously, and intervene instantly when something goes wrong.
10
+
11
+ Enterprise solutions like Visa's Visa Intelligent Commerce (VIC) platform address this for traditional payment flows: pre-authorization, fraud scoring, velocity checks, chargeback handling. But VIC is built for card networks and merchant acquirers. It doesn't speak MCP. It doesn't run locally. It doesn't give developers control over the trust model.
12
+
13
+ AgentPay MCP provides the same trust primitives — simulation, spend controls, human approval, and explainability — in an open-source, developer-native package that runs wherever your agent runs.
14
+
15
+ ---
16
+
17
+ ## Trust Layers
18
+
19
+ ### Layer 1: Simulation Mode
20
+
21
+ Before any real funds move, agents can dry-run a transaction to preview:
22
+
23
+ - **Recipient address** and whether it's on the allowlist
24
+ - **Estimated cost** in the payment token (USDC, ETH)
25
+ - **Gas estimate** for the target chain
26
+ - **Policy evaluation result** — would this transaction be auto-approved, queued, or rejected?
27
+
28
+ Simulation mode gives operators confidence before enabling auto-approve. It's also the right tool for testing new integrations: point your agent at a paid API, see what it would cost, and decide whether to add it to the allowlist — all without spending a cent.
29
+
30
+ **Comparison:** Visa VIC performs pre-authorization checks server-side through the card network. AgentPay performs simulation locally, with results visible to the agent and operator before any network call.
31
+
32
+ ### Layer 2: Per-Call Spend Caps
33
+
34
+ Every transaction is evaluated against on-chain spending policy before execution:
35
+
36
+ - **Per-transaction maximum** — no single call can exceed this amount, regardless of what the agent requests
37
+ - **Enforced by smart contract** — the AgentAccountV2 contract rejects over-cap transactions at the EVM level. Application-layer bugs or agent prompt injection cannot bypass this.
38
+
39
+ This is the most critical trust boundary. Even if an agent is compromised, jailbroken, or simply wrong about what it's buying, the per-call cap limits blast radius to a known, acceptable amount.
40
+
41
+ **Comparison:** Visa VIC enforces transaction limits through issuer-configured velocity rules in the card network. AgentPay enforces them on-chain — no intermediary required, publicly auditable, and immutable once set.
42
+
43
+ ### Layer 3: Daily Aggregate Caps
44
+
45
+ Per-call caps prevent single large losses. Daily caps prevent death by a thousand cuts:
46
+
47
+ - **Rolling daily limit** — total spend across all transactions resets on a configurable period
48
+ - **On-chain enforcement** — same smart contract, same immutability guarantees
49
+ - **Budget visibility** — agents can call `check_budget` to see remaining allowance before starting expensive workflows
50
+
51
+ An agent running a 50-item enrichment loop at $0.10 each hits $5.00 total. If the daily cap is $10, the agent knows it has $5 left. If the loop was supposed to be 500 items due to a bug, the cap stops it at 100.
52
+
53
+ **Comparison:** VIC uses velocity checks (transaction count and amount per time window) configured at the issuer level. AgentPay's daily caps serve the same function, configured by the wallet owner.
54
+
55
+ ### Layer 4: Human-in-the-Loop Approval
56
+
57
+ Not every transaction should be automatic. AgentPay's HITL system queues transactions that exceed the auto-approve threshold:
58
+
59
+ - **Threshold-based routing** — under threshold: auto-approved and executed. Over threshold: queued for human review.
60
+ - **Queue inspection** — operators see pending transactions with full context (merchant, amount, tool that triggered it, agent reasoning)
61
+ - **Approve or reject** — explicit human decision. Rejection returns a structured error to the agent, which can adapt (use cached data, try a cheaper source, ask the user).
62
+ - **Fail-closed** — if the approval system errors, the default is rejection. Never approval.
63
+
64
+ HITL is the default mode. Operators opt *into* automation by raising thresholds, not opt *out* of oversight by lowering them. Trust is earned incrementally.
65
+
66
+ **Comparison:** Visa VIC routes high-risk transactions to manual review queues via issuer fraud teams. AgentPay routes them to the operator directly — no intermediary, no SLA dependency on a third-party fraud team.
67
+
68
+ ### Layer 5: Transaction Explainability
69
+
70
+ Every transaction — approved, rejected, queued, or simulated — produces a structured audit record:
71
+
72
+ - **Timestamp** (block time + local time)
73
+ - **Merchant/recipient** address and resolved name (if available)
74
+ - **Amount** in payment token and USD equivalent
75
+ - **Policy evaluation** — which rule triggered (auto-approve, cap exceeded, allowlist miss)
76
+ - **Approval path** — auto-approved, human-approved, or rejected (with reason)
77
+ - **On-chain transaction hash** — independently verifiable on any block explorer
78
+
79
+ This isn't just logging. It's the artifact that security teams, compliance officers, and auditors need to answer: "What did this agent spend money on, why, and who approved it?"
80
+
81
+ **Comparison:** Visa VIC generates transaction records through the card network's settlement process. AgentPay generates them on-chain — immutable, publicly verifiable, and available in real-time (not T+1 or T+2 settlement).
82
+
83
+ ---
84
+
85
+ ## Trust Model Comparison
86
+
87
+ | Trust Primitive | Visa VIC (Enterprise) | AgentPay MCP (Open Source) |
88
+ |---|---|---|
89
+ | Pre-transaction simulation | Pre-authorization via card network | Local simulation mode, no network call |
90
+ | Per-transaction limits | Issuer-configured velocity rules | On-chain smart contract enforcement |
91
+ | Aggregate spend caps | Velocity checks per time window | On-chain daily caps, agent-queryable |
92
+ | Human review routing | Issuer fraud team queues | Direct operator HITL, fail-closed |
93
+ | Transaction audit trail | Card network settlement records (T+1/T+2) | On-chain, real-time, publicly verifiable |
94
+ | Integration model | Enterprise API + card network onboarding | `npm install` + MCP config |
95
+ | Source availability | Proprietary | MIT open source |
96
+ | Protocol native | Card networks (ISO 8583) | MCP + x402 (HTTP 402) |
97
+ | Agent-native controls | No (designed for human cardholders) | Yes (agents query budget, adapt to rejections) |
98
+
99
+ ---
100
+
101
+ ## Deployment Progression
102
+
103
+ Trust should be granted incrementally. Here's the recommended progression:
104
+
105
+ 1. **Simulation only** — Agent runs, simulates all payments, logs what it would spend. Zero risk.
106
+ 2. **HITL with low threshold** — Auto-approve micro-payments ($0.10), queue everything else. Operator reviews daily.
107
+ 3. **HITL with raised threshold** — After reviewing transaction patterns, raise auto-approve to $1-$5. Queue large transactions.
108
+ 4. **Full auto with daily cap** — High-confidence workflows get full auto-approve with a daily ceiling. Operator reviews weekly.
109
+ 5. **Multi-agent with per-agent caps** — Each agent gets its own wallet with independent caps. Blast radius is isolated per agent.
110
+
111
+ At no point does the operator lose the ability to intervene. Every stage is reversible by lowering thresholds or enabling simulation mode.
112
+
113
+ ---
114
+
115
+ ## For Enterprise Security Teams
116
+
117
+ If you're evaluating agent payment infrastructure:
118
+
119
+ - **Smart contract source** is verified and auditable on-chain
120
+ - **Dependency tree** is minimal — zero LiteLLM, zero Python runtime, auditable with `npm ls`
121
+ - **NVIDIA validation** — integrated into [NVIDIA NeMo Agent Toolkit Examples](https://github.com/NVIDIA/NeMo-Agent-Toolkit-Examples/pull/17) (PR #17, merged)
122
+ - **CoSAI alignment** — addresses T9 (Financial Fraud) and T10 (Identity Spoofing) threat categories
123
+ - **Security posture doc** — see [`security-posture.md`](security-posture.md) for the full compliance matrix
124
+
125
+ ---
126
+
127
+ *AgentPay MCP is MIT licensed. Built by [AI Agent Economy](https://ai-agent-economy.com).*
@@ -0,0 +1,115 @@
1
+ # Vercel deployment hardening for AgentPay MCP
2
+
3
+ Vercel's April 2026 security bulletin changed the threat model for agent teams. The incident started through a compromised third-party AI tool OAuth grant, then moved into Google Workspace and Vercel systems. Vercel reported that a limited set of non-sensitive environment variables were enumerated and decrypted, and it told affected customers to rotate readable env vars, review activity and deployments, and move secrets into sensitive environment variables.
4
+
5
+ AgentPay MCP should be deployed as if the host can leak readable configuration. Keep payment authority isolated, make every paid tool fail closed, and treat OAuth app grants as production access.
6
+
7
+ ## 10-minute incident response checklist
8
+
9
+ Use this first if you deployed AgentPay MCP or any x402-capable agent on Vercel before April 24, 2026.
10
+
11
+ 1. Rotate every readable Vercel environment variable that can reach money, data, or infrastructure. Include `AGENT_PRIVATE_KEY`, `AGENT_WALLET_ADDRESS`, `RPC_URL`, model provider keys, database URLs, OAuth client secrets, webhook secrets, and any internal API tokens.
12
+ 2. Move secrets into Vercel sensitive environment variables. Anything that signs, pays, authenticates, deploys, or reads private data should not be readable from the dashboard or API after creation.
13
+ 3. Audit Google Workspace OAuth grants for AI tools. Remove any app you don't recognize or can't tie to an owner. Vercel published the OAuth app ID `110671459871-30f1spbu0hptbs60cb4vsmv79i7bbvqj.apps.googleusercontent.com` as an indicator of compromise.
14
+ 4. Review Vercel activity logs for environment variable reads, token changes, project setting changes, team membership changes, and unusual API access.
15
+ 5. Review recent deployments. Delete deployments you didn't initiate, don't recognize, or can't explain from a linked commit and CI run.
16
+ 6. Rotate Deployment Protection bypass tokens if they exist. Treat them like exposed credentials.
17
+ 7. Verify Deployment Protection is at least Standard for every production project.
18
+ 8. Re-deploy from a known clean commit after rotation. Don't trust a deployment that was built with stale credentials.
19
+ 9. Re-run AgentPay MCP approval validation before reconnecting agents to paid tools.
20
+ 10. Keep the old credentials disabled. Don't keep them as fallback values in preview or development projects.
21
+
22
+ ## Vercel environment variable policy
23
+
24
+ Classify AgentPay MCP configuration by blast radius:
25
+
26
+ | Variable | Classification | Vercel setting | Rotation trigger |
27
+ | --- | --- | --- | --- |
28
+ | `AGENT_PRIVATE_KEY` | x402 signing key | Sensitive env var only | Any host, OAuth, CI, or dashboard compromise |
29
+ | `AGENT_WALLET_ADDRESS` | Public identifier | Readable allowed | Wallet migration or key rotation |
30
+ | `RPC_URL` with provider key | Paid infrastructure credential | Sensitive env var only | Any provider, Vercel, or CI exposure |
31
+ | `AGENTPAY_MCP_TOKEN` | MCP transport auth | Sensitive env var only | Any agent, app, or host compromise |
32
+ | Model provider API keys | Paid tool and data access | Sensitive env var only | Any env var read or OAuth compromise |
33
+ | Database URLs | Production data access | Sensitive env var only | Any env var read, deployment anomaly, or DB alert |
34
+
35
+ Rules:
36
+
37
+ - Don't store owner keys in Vercel. AgentPay MCP should use an agent hot wallet with on-chain spend limits, not the owner's treasury key.
38
+ - Don't put signing keys in client-side env vars. In Vercel, avoid any `NEXT_PUBLIC_` prefix for payment, API, OAuth, or database secrets.
39
+ - Don't copy production secrets into preview projects unless the preview deployment is protected and tied to the same incident response process.
40
+ - Use separate keys for development, preview, and production. A preview leak shouldn't become a production payment incident.
41
+
42
+ ## x402 signing key isolation
43
+
44
+ AgentPay MCP is safest when the Vercel app does not hold unrestricted signing authority.
45
+
46
+ Recommended pattern:
47
+
48
+ 1. Deploy AgentPay MCP as a separate service behind HTTPS with an auth token or mTLS-equivalent gateway.
49
+ 2. Give the Vercel AI app only an `AGENTPAY_MCP_TOKEN` and MCP endpoint URL.
50
+ 3. Keep `AGENT_PRIVATE_KEY` in the AgentPay MCP service, a KMS, or an HSM-backed signer. If it must run on Vercel, mark it as a sensitive environment variable and bind it to the smallest possible project scope.
51
+ 4. Use an agent hot wallet with on-chain spend caps, recipient allowlists, and daily limits.
52
+ 5. Keep owner or treasury keys outside the Vercel runtime entirely.
53
+ 6. Log every signing attempt with `agent_id`, `task_id`, `tool_call_id`, amount, recipient, policy version, approval ID, and x402 receipt ID.
54
+
55
+ The invariant is simple: a leaked model key can burn credits; a leaked signing key can move funds. Treat them differently.
56
+
57
+ ## Fail-closed paid tools with Vercel AI SDK approvals
58
+
59
+ The Vercel AI SDK approval flow is the correct place to stop paid tools before x402 signing. Use `needsApproval: true` or a dynamic `needsApproval` function for any tool that can spend money, change billing state, or call a paid API.
60
+
61
+ AgentPay MCP v4.1.3 already documents the native AI SDK approval bridge. Preserve this signing rule in production:
62
+
63
+ - `tool-approval-response` with `approved: true`: allow policy checks, then signing
64
+ - denied response: block signing
65
+ - missing response: block signing
66
+ - approval engine error: block signing
67
+ - policy engine error: block signing
68
+ - amount, recipient, chain, or payment header mismatch: block signing
69
+
70
+ Never let a model retry a denied paid tool until a human creates a new approval. Add a system instruction such as: `When a tool execution is not approved, do not retry the same paid call.`
71
+
72
+ Run the existing approval-validation test before deploy:
73
+
74
+ ```bash
75
+ npm install
76
+ npm test -- tests/payments.test.ts
77
+ ```
78
+
79
+ This test suite covers approval queue behavior and must remain fail-closed: decline, cancel, missing approval, and incomplete approval paths must not reach signing.
80
+
81
+ ## Activity and deployment review
82
+
83
+ After a Vercel security event, review these records before turning agents back on:
84
+
85
+ - Vercel account activity log for env var reads, project changes, team changes, token changes, and unusual API access
86
+ - deployment list for unexpected deploys, build sources, commit SHAs, domains, and aliases
87
+ - GitHub repository audit log for OAuth app grants, webhooks, deploy keys, and branch protection edits
88
+ - Google Workspace connected apps and OAuth grants for AI tools
89
+ - npm publish history if the deployment consumes internal packages
90
+ - AgentPay MCP transaction history for unexpected x402 attempts, blocked approvals, and policy denials
91
+
92
+ If the app paid anything during the exposure window, reconcile the x402 receipt IDs against approval IDs and policy versions. Any payment without an approval record should be treated as an incident until disproven.
93
+
94
+ ## Pre-deploy gate
95
+
96
+ Do not ship a Vercel-hosted agent with paid tools until all of these pass:
97
+
98
+ - every secret value is sensitive, scoped by environment, and rotated after any exposure
99
+ - owner keys are absent from Vercel
100
+ - agent signing key is isolated to AgentPay MCP or a dedicated signer
101
+ - Vercel Deployment Protection is enabled for production
102
+ - Google Workspace OAuth grants have an owner and a business reason
103
+ - activity logs and deployment logs were reviewed after the last rotation
104
+ - AI SDK paid tools require approval before execution
105
+ - AgentPay MCP validation proves x402 signing is blocked until approval
106
+ - spend caps, recipient allowlists, daily limits, and kill switches are active
107
+ - audit records join approval ID, tool call ID, policy version, and x402 receipt ID
108
+
109
+ ## References
110
+
111
+ - Vercel April 2026 security incident bulletin: https://vercel.com/kb/bulletin/vercel-april-2026-security-incident
112
+ - Vercel sensitive environment variables: https://vercel.com/docs/environment-variables/sensitive-environment-variables
113
+ - Vercel activity logs: https://vercel.com/docs/cli/activity
114
+ - Vercel AI SDK tool execution approval: https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling#tool-execution-approval
115
+ - AgentPay MCP approval validation tests: ../tests/payments.test.ts
@@ -0,0 +1,130 @@
1
+ # WhatsApp and SMB paid-agent controls with AgentPay MCP
2
+
3
+ WhatsApp agent management changes the buyer question. The problem is no longer only "can this gateway call a paid API?" It is "can a shop owner approve spend from the same channel where the agent works?"
4
+
5
+ AgentPay MCP should sit between the channel agent and the x402 or USDC endpoint.
6
+
7
+ ## Reference flow
8
+
9
+ ```text
10
+ Customer or operator in WhatsApp
11
+ -> WhatsApp agent runtime
12
+ -> paid action requested
13
+ -> AgentPay MCP policy check
14
+ -> approval card or decline path
15
+ -> x402 or USDC payment only after approval
16
+ -> audit row returned to the operator
17
+ ```
18
+
19
+ ## Control points
20
+
21
+ 1. The WhatsApp agent asks to call a paid API, book a service, buy data, or trigger a USDC payment.
22
+ 2. AgentPay MCP computes the spend decision before any wallet signature exists.
23
+ 3. If the request needs approval, the channel shows a concise card:
24
+ - merchant or endpoint,
25
+ - amount,
26
+ - token and chain,
27
+ - reason the agent gave,
28
+ - daily cap remaining,
29
+ - approve, deny, or lower cap.
30
+ 4. AgentPay MCP signs only after an approved decision.
31
+ 5. The operator gets a receipt with transaction hash, URL, amount, policy version, and agent task ID.
32
+
33
+ ## Policy shape
34
+
35
+ ```json
36
+ {
37
+ "agent_id": "whatsapp-agent-42",
38
+ "channel": "whatsapp",
39
+ "daily_cap_usdc": "25.00",
40
+ "per_call_cap_usdc": "2.00",
41
+ "approval_required_above_usdc": "0.50",
42
+ "allowed_recipients": ["api.vendor.example"],
43
+ "allowed_chains": ["base", "base-sepolia"],
44
+ "audit_tags": ["smb", "whatsapp", "x402"]
45
+ }
46
+ ```
47
+
48
+ ## Example approval card text
49
+
50
+ ```text
51
+ Approve paid agent action?
52
+
53
+ Agent: Inventory assistant
54
+ Endpoint: api.supplier.example/restock-check
55
+ Cost: 0.18 USDC on Base
56
+ Daily cap left: 14.72 USDC
57
+ Reason: Check supplier stock before replying to customer
58
+
59
+ [Approve once] [Deny] [Lower cap]
60
+ ```
61
+
62
+ ## Failure behavior
63
+
64
+ - If the user denies, return a normal agent message and do not sign.
65
+ - If the cap is exceeded, fail closed and ask for a cap update.
66
+ - If the payment metadata is missing or malformed, do not guess.
67
+ - If the chain is unknown, route to the chain-drift watchlist before enabling payment.
68
+ - If the WhatsApp session expires, require a fresh approval.
69
+
70
+ ## Audit row
71
+
72
+ ```json
73
+ {
74
+ "timestamp": "2026-04-28T05:20:00Z",
75
+ "agent_id": "whatsapp-agent-42",
76
+ "task_id": "restock-check-1902",
77
+ "channel": "whatsapp",
78
+ "resource": "https://api.supplier.example/restock-check",
79
+ "amount_usdc": "0.18",
80
+ "chain": "base",
81
+ "approval_decision": "approved_once",
82
+ "policy_version": "2026-04-28.whatsapp-smb.v1",
83
+ "settlement_reference": "0x..."
84
+ }
85
+ ```
86
+
87
+ ## Acceptance criteria
88
+
89
+ - No channel agent can produce a wallet signature before AgentPay MCP returns an approved decision.
90
+ - Operators can set daily and per-call caps per WhatsApp agent.
91
+ - Every paid call joins channel context, payment metadata, policy version, and settlement reference.
92
+ - Deny, cancel, expired session, cap exceeded, and unknown chain paths all fail closed.
93
+
94
+ ## Persona creation approval gate
95
+
96
+ Axon-style vertical personas make the first spend decision happen before the first paid API call. When a shop owner creates an inventory assistant, booking assistant, legal intake assistant, or support persona, AgentPay MCP should attach payment authority at creation time instead of waiting for the first x402 challenge.
97
+
98
+ Recommended creation flow:
99
+
100
+ 1. Operator creates or edits a persona in the channel agent dashboard.
101
+ 2. The dashboard asks AgentPay MCP for a spend profile before enabling paid tools.
102
+ 3. AgentPay MCP returns default caps, chain allowlist, recipient allowlist, and approval threshold.
103
+ 4. The operator approves the persona's payment authority in WhatsApp or the admin UI.
104
+ 5. The runtime stores the persona ID, policy version, cap, approver, and allowed tool set.
105
+ 6. Every later x402 or USDC call must reference the persona policy before signing.
106
+
107
+ Minimal policy attachment:
108
+
109
+ ```json
110
+ {
111
+ "persona_id": "inventory-assistant-ptbr",
112
+ "persona_vertical": "retail_inventory",
113
+ "created_by": "operator:shop-owner-17",
114
+ "approval_surface": "whatsapp",
115
+ "policy_version": "2026-04-29.persona-controls.v1",
116
+ "daily_cap_usdc": "10.00",
117
+ "per_call_cap_usdc": "0.25",
118
+ "approval_required_above_usdc": "0.05",
119
+ "allowed_tools": ["supplier_stock_lookup", "delivery_quote"],
120
+ "allowed_recipients": ["api.supplier.example", "api.delivery.example"],
121
+ "allowed_chains": ["base", "base-sepolia"]
122
+ }
123
+ ```
124
+
125
+ Acceptance additions:
126
+
127
+ - Persona creation cannot enable paid tools without an attached AgentPay MCP policy.
128
+ - Persona edits that raise spend caps, add recipients, add chains, or add paid tools require fresh approval.
129
+ - WhatsApp receipts include both `agent_id` and `persona_id` so the owner can see which persona spent money.
130
+ - Revoking a persona immediately disables its payment authority, even if the agent runtime still has an active session.