@mixrpay/agent-sdk
v0.11.0
Published
Non-custodial wallet and payments SDK for AI agents with MCP and Claude integration
Readme
@mixrpay/agent-sdk
Non-custodial wallet, DeFi, and payments SDK for AI agents. Includes MCP server, Anthropic tool definitions, and 20+ gateway tools.
Installation
npm install @mixrpay/agent-sdk
# or
yarn add @mixrpay/agent-sdk
# or
pnpm add @mixrpay/agent-sdkQuick Start
import { AgentWallet } from '@mixrpay/agent-sdk';
const wallet = await AgentWallet.connect();
const balances = await wallet.getBalances();
console.log(balances);
await wallet.transfer('0x...', '10.00');Authentication
Device Flow (Browser)
On first run, connect() opens your browser for login. After approval, credentials are cached locally.
const wallet = await AgentWallet.connect();API Key
const wallet = await AgentWallet.connect({
apiKey: 'agt_live_...',
});Or via environment variable:
MIXRPAY_API_KEY=agt_live_xxx node my-agent.jsAccess Code
For agents connecting to an existing human-managed wallet with budget limits:
const wallet = await AgentWallet.connect({
accessCode: 'mixr-abc123',
});Wallet & DeFi
// Check balances (tokens + delegation budget)
const balances = await wallet.getBalances();
// Transfer USDC
await wallet.transfer('0x...', '10.00');
// Swap tokens via 0x
await wallet.swap('ETH', 'USDC', '0.1');
// Bridge cross-chain via deBridge
const bridge = await wallet.bridge('USDC', '100', 'ethereum');
await wallet.waitForBridgeCompletion(bridge.order_id);
// Execute arbitrary on-chain transactions
await wallet.executeTransaction({
to: '0x...contractAddress',
data: '0x...calldata',
estimatedCostUsd: 5.0,
});Paid APIs (x402)
const response = await wallet.fetchPaid('https://api.example.com/endpoint');Gateway Tools
const tools = await wallet.listTools();
const result = await wallet.callTool('firecrawl', {
action: 'scrape',
url: 'https://example.com',
});Transaction History
const history = await wallet.getTransactions({ limit: 50 });
for (const tx of history.transactions) {
console.log(`${tx.chargeType}: $${tx.amount} - ${tx.status}`);
}Multi-Step Plans
Submit, approve, and execute multi-step plans with idempotent resumption:
const plan = await wallet.submitPlan({
title: 'Rebalance portfolio',
steps: [
{ action: 'swap', params: { sellToken: 'ETH', buyToken: 'USDC', sellAmount: '0.5' }, description: 'Sell ETH' },
{ action: 'bridge', params: { token: 'USDC', amount: '500', destChain: 'ethereum' }, description: 'Bridge to Ethereum' },
],
totalEstimatedCostUsd: 510,
});
if (plan.status === 'auto_approved') {
const result = await wallet.executePlan(plan.planId);
console.log(result.status);
}Claude Agent SDK
Use as an MCP server with the Claude Agent SDK:
import { query } from '@anthropic-ai/claude-agent-sdk';
import { AgentWallet } from '@mixrpay/agent-sdk';
const wallet = await AgentWallet.connect();
for await (const msg of query({
prompt: 'Check my balance and swap 0.1 ETH for USDC',
options: {
mcpServers: {
wallet: wallet.mcp(),
},
},
})) {
console.log(msg);
}Or use wallet.tools() for direct Anthropic SDK integration:
import Anthropic from '@anthropic-ai/sdk';
const toolkit = wallet.tools();
const response = await anthropic.messages.create({
model: 'claude-sonnet-4-20250514',
tools: toolkit.definitions,
messages: [{ role: 'user', content: 'Transfer 5 USDC to 0x...' }],
});
// Execute tool calls returned by Claude
for (const block of response.content) {
if (block.type === 'tool_use') {
const result = await toolkit.execute(block.name, block.input);
}
}MCP Server (Standalone)
MIXRPAY_API_KEY=agt_live_... npx mixrpay-mcpCLI
npx mixrpay login
npx mixrpay whoami
npx mixrpay status
npx mixrpay logoutError Handling
import { AgentWallet, InsufficientBalanceError, MixrPayError } from '@mixrpay/agent-sdk';
try {
await wallet.transfer('0x...', '100.00');
} catch (error) {
if (error instanceof InsufficientBalanceError) {
console.log(`Need $${error.required}, have $${error.available}`);
}
if (error instanceof MixrPayError && error.isRetryable()) {
await new Promise((r) => setTimeout(r, error.retryAfterMs || 1000));
}
}Environment Variables
| Variable | Description |
| --- | --- |
| MIXRPAY_API_KEY | Agent API key (agt_live_...), skips device flow |
| MIXRPAY_SESSION_KEY | Session key for delegation signing |
| MIXRPAY_BASE_URL | Custom API URL (default: https://www.mixrpay.com) |
Features
- Non-custodial agent wallets (keys stay local)
- DeFi primitives: swap (0x), bridge (deBridge), transfer
- 20+ gateway tools (Firecrawl, Exa, Tavily, and more)
- x402 auto-pay proxy for paid APIs
- MCP server for Claude Agent SDK
- Anthropic tool definitions for
messages.create() - Multi-step plan submission with human approval
- Idempotent execution with resume support
- Transaction history and spending stats
- Budget governance (per-tx limits, daily/total caps)
Documentation
License
MIT
