@mixrpay/agent-sdk 0.10.0 → 0.11.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/README.md CHANGED
@@ -1,11 +1,15 @@
1
1
  # @mixrpay/agent-sdk
2
2
 
3
- AI agent payments and wallet management.
3
+ Non-custodial wallet, DeFi, and payments SDK for AI agents. Includes MCP server, Anthropic tool definitions, and 20+ gateway tools.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
8
  npm install @mixrpay/agent-sdk
9
+ # or
10
+ yarn add @mixrpay/agent-sdk
11
+ # or
12
+ pnpm add @mixrpay/agent-sdk
9
13
  ```
10
14
 
11
15
  ## Quick Start
@@ -13,70 +17,175 @@ npm install @mixrpay/agent-sdk
13
17
  ```typescript
14
18
  import { AgentWallet } from '@mixrpay/agent-sdk';
15
19
 
16
- // Connect (auto-detects credentials from env)
17
20
  const wallet = await AgentWallet.connect();
18
21
 
19
- // Or with explicit credentials
22
+ const balances = await wallet.getBalances();
23
+ console.log(balances);
24
+
25
+ await wallet.transfer('0x...', '10.00');
26
+ ```
27
+
28
+ ## Authentication
29
+
30
+ ### Device Flow (Browser)
31
+
32
+ On first run, `connect()` opens your browser for login. After approval, credentials are cached locally.
33
+
34
+ ```typescript
35
+ const wallet = await AgentWallet.connect();
36
+ ```
37
+
38
+ ### API Key
39
+
40
+ ```typescript
41
+ const wallet = await AgentWallet.connect({
42
+ apiKey: 'agt_live_...',
43
+ });
44
+ ```
45
+
46
+ Or via environment variable:
47
+
48
+ ```bash
49
+ MIXRPAY_API_KEY=agt_live_xxx node my-agent.js
50
+ ```
51
+
52
+ ### Access Code
53
+
54
+ For agents connecting to an existing human-managed wallet with budget limits:
55
+
56
+ ```typescript
20
57
  const wallet = await AgentWallet.connect({
21
58
  accessCode: 'mixr-abc123',
22
59
  });
23
60
  ```
24
61
 
25
- ## Usage
62
+ ## Wallet & DeFi
26
63
 
27
64
  ```typescript
28
- // Check balances
65
+ // Check balances (tokens + delegation budget)
29
66
  const balances = await wallet.getBalances();
30
67
 
31
68
  // Transfer USDC
32
- const tx = await wallet.transfer('0x...', '10.00');
69
+ await wallet.transfer('0x...', '10.00');
33
70
 
34
- // Swap tokens
35
- const swap = await wallet.swap('ETH', 'USDC', '0.1');
71
+ // Swap tokens via 0x
72
+ await wallet.swap('ETH', 'USDC', '0.1');
36
73
 
37
- // Bridge cross-chain
74
+ // Bridge cross-chain via deBridge
38
75
  const bridge = await wallet.bridge('USDC', '100', 'ethereum');
76
+ await wallet.waitForBridgeCompletion(bridge.order_id);
77
+
78
+ // Execute arbitrary on-chain transactions
79
+ await wallet.executeTransaction({
80
+ to: '0x...contractAddress',
81
+ data: '0x...calldata',
82
+ estimatedCostUsd: 5.0,
83
+ });
84
+ ```
85
+
86
+ ## Paid APIs (x402)
87
+
88
+ ```typescript
89
+ const response = await wallet.fetchPaid('https://api.example.com/endpoint');
90
+ ```
91
+
92
+ ## Gateway Tools
39
93
 
40
- // Call paid APIs (x402)
41
- const response = await wallet.fetch('https://api.example.com/endpoint');
94
+ ```typescript
95
+ const tools = await wallet.listTools();
42
96
 
43
- // Call gateway tools
44
97
  const result = await wallet.callTool('firecrawl', {
45
98
  action: 'scrape',
46
99
  url: 'https://example.com',
47
100
  });
101
+ ```
48
102
 
49
- // Execute arbitrary on-chain transactions
50
- const result = await wallet.executeTransaction({
51
- to: '0x...contractAddress',
52
- data: '0x...calldata',
53
- estimatedCostUsd: 5.0,
103
+ ## Transaction History
104
+
105
+ ```typescript
106
+ const history = await wallet.getTransactions({ limit: 50 });
107
+
108
+ for (const tx of history.transactions) {
109
+ console.log(`${tx.chargeType}: $${tx.amount} - ${tx.status}`);
110
+ }
111
+ ```
112
+
113
+ ## Multi-Step Plans
114
+
115
+ Submit, approve, and execute multi-step plans with idempotent resumption:
116
+
117
+ ```typescript
118
+ const plan = await wallet.submitPlan({
119
+ title: 'Rebalance portfolio',
120
+ steps: [
121
+ { action: 'swap', params: { sellToken: 'ETH', buyToken: 'USDC', sellAmount: '0.5' }, description: 'Sell ETH' },
122
+ { action: 'bridge', params: { token: 'USDC', amount: '500', destChain: 'ethereum' }, description: 'Bridge to Ethereum' },
123
+ ],
124
+ totalEstimatedCostUsd: 510,
54
125
  });
126
+
127
+ if (plan.status === 'auto_approved') {
128
+ const result = await wallet.executePlan(plan.planId);
129
+ console.log(result.status);
130
+ }
55
131
  ```
56
132
 
57
- ## MCP Server
133
+ ## Claude Agent SDK
58
134
 
59
- Use as an MCP server for Claude, Cline, or other MCP-compatible agents:
135
+ Use as an MCP server with the Claude Agent SDK:
60
136
 
61
- ```bash
62
- MIXRPAY_SESSION_KEY=sk_live_... npx mixrpay-mcp
137
+ ```typescript
138
+ import { query } from '@anthropic-ai/claude-agent-sdk';
139
+ import { AgentWallet } from '@mixrpay/agent-sdk';
140
+
141
+ const wallet = await AgentWallet.connect();
142
+
143
+ for await (const msg of query({
144
+ prompt: 'Check my balance and swap 0.1 ETH for USDC',
145
+ options: {
146
+ mcpServers: {
147
+ wallet: wallet.mcp(),
148
+ },
149
+ },
150
+ })) {
151
+ console.log(msg);
152
+ }
63
153
  ```
64
154
 
65
- Or programmatically:
155
+ Or use `wallet.tools()` for direct Anthropic SDK integration:
66
156
 
67
157
  ```typescript
68
- const mcpConfig = wallet.mcp();
158
+ import Anthropic from '@anthropic-ai/sdk';
159
+
160
+ const toolkit = wallet.tools();
161
+
162
+ const response = await anthropic.messages.create({
163
+ model: 'claude-sonnet-4-20250514',
164
+ tools: toolkit.definitions,
165
+ messages: [{ role: 'user', content: 'Transfer 5 USDC to 0x...' }],
166
+ });
167
+
168
+ // Execute tool calls returned by Claude
169
+ for (const block of response.content) {
170
+ if (block.type === 'tool_use') {
171
+ const result = await toolkit.execute(block.name, block.input);
172
+ }
173
+ }
69
174
  ```
70
175
 
71
- ## CLI
176
+ ## MCP Server (Standalone)
72
177
 
73
178
  ```bash
74
- npm install -g @mixrpay/agent-sdk
179
+ MIXRPAY_API_KEY=agt_live_... npx mixrpay-mcp
180
+ ```
75
181
 
76
- mixrpay login
77
- mixrpay status
78
- mixrpay whoami
79
- mixrpay logout
182
+ ## CLI
183
+
184
+ ```bash
185
+ npx mixrpay login
186
+ npx mixrpay whoami
187
+ npx mixrpay status
188
+ npx mixrpay logout
80
189
  ```
81
190
 
82
191
  ## Error Handling
@@ -91,11 +200,32 @@ try {
91
200
  console.log(`Need $${error.required}, have $${error.available}`);
92
201
  }
93
202
  if (error instanceof MixrPayError && error.isRetryable()) {
94
- await sleep(error.retryAfterMs || 1000);
203
+ await new Promise((r) => setTimeout(r, error.retryAfterMs || 1000));
95
204
  }
96
205
  }
97
206
  ```
98
207
 
208
+ ## Environment Variables
209
+
210
+ | Variable | Description |
211
+ | --- | --- |
212
+ | `MIXRPAY_API_KEY` | Agent API key (`agt_live_...`), skips device flow |
213
+ | `MIXRPAY_SESSION_KEY` | Session key for delegation signing |
214
+ | `MIXRPAY_BASE_URL` | Custom API URL (default: `https://www.mixrpay.com`) |
215
+
216
+ ## Features
217
+
218
+ - Non-custodial agent wallets (keys stay local)
219
+ - DeFi primitives: swap (0x), bridge (deBridge), transfer
220
+ - 20+ gateway tools (Firecrawl, Exa, Tavily, and more)
221
+ - x402 auto-pay proxy for paid APIs
222
+ - MCP server for Claude Agent SDK
223
+ - Anthropic tool definitions for `messages.create()`
224
+ - Multi-step plan submission with human approval
225
+ - Idempotent execution with resume support
226
+ - Transaction history and spending stats
227
+ - Budget governance (per-tx limits, daily/total caps)
228
+
99
229
  ## Documentation
100
230
 
101
231
  [mixrpay.com/docs](https://www.mixrpay.com/docs)
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- export{g as AgentWallet,c as DEFAULT_BASE_URL,d as DEFAULT_FACILITATOR_URL,e as DEFAULT_TIMEOUT,f as NETWORKS,b as SDK_VERSION}from'./chunk-RAJSYN5T.js';
2
+ export{g as AgentWallet,c as DEFAULT_BASE_URL,d as DEFAULT_FACILITATOR_URL,e as DEFAULT_TIMEOUT,f as NETWORKS,b as SDK_VERSION}from'./chunk-UED36HQN.js';