Claude Integration
Sponge provides first-class integration with Anthropic's Claude through two methods: MCP (Model Context Protocol) and direct tool calling.
Overview
| Method | Best For | Requires |
|---|---|---|
| MCP | Claude Desktop, MCP clients | MCP-compatible client |
| Direct Tools | Custom apps, Anthropic API | Anthropic SDK |
MCP Integration
MCP (Model Context Protocol) is Anthropic's open protocol for connecting AI models to external systems. Sponge implements a full MCP server.
Quick Setup
import Anthropic from "@anthropic-ai/sdk";
import { SpongeWallet } from "@spongewallet/sdk";
const wallet = await SpongeWallet.connect();
const anthropic = new Anthropic();
const response = await anthropic.messages.create({
model: "claude-sonnet-4-20250514",
max_tokens: 1024,
messages: [
{ role: "user", content: "What's my wallet balance?" }
],
mcp_servers: {
wallet: wallet.mcp()
}
});MCP Server Configuration
The wallet.mcp() method returns MCP server configuration:
const mcpConfig = wallet.mcp();
// {
// transport: "stdio",
// command: "sponge-mcp",
// args: ["--api-key", "sponge_test_..."],
// env: {}
// }Claude Desktop Setup
For Claude Desktop, add Sponge to your MCP configuration:
{
"mcpServers": {
"sponge-wallet": {
"command": "npx",
"args": ["@spongewallet/mcp", "--api-key", "YOUR_API_KEY"]
}
}
}Or use environment variables:
{
"mcpServers": {
"sponge-wallet": {
"command": "npx",
"args": ["@spongewallet/mcp"],
"env": {
"SPONGE_API_KEY": "sponge_test_..."
}
}
}
}Available MCP Tools
When connected via MCP, Claude has access to these tools:
Wallet Tools
| Tool | Description |
|---|---|
get_balance | Check balance on one or all chains |
evm_transfer | Transfer ETH/USDC on Ethereum or Base |
solana_transfer | Transfer SOL/USDC on Solana |
tempo_transfer | Transfer pathUSD on Tempo (testnet) |
solana_swap | Swap tokens on Solana via Jupiter |
get_solana_tokens | List all SPL tokens in wallet |
search_solana_tokens | Search Jupiter token database |
Transaction Tools
| Tool | Description |
|---|---|
get_transaction_status | Check transaction status |
get_transaction_history | View past transactions |
Fund Management
| Tool | Description |
|---|---|
request_funding | Request funds from owner |
withdraw_to_main_wallet | Withdraw to owner's wallet |
request_tempo_faucet | Get testnet tokens (test keys) |
Direct Tools Integration
For custom applications using the Anthropic API directly, use the tools interface.
Setup
import Anthropic from "@anthropic-ai/sdk";
import { SpongeWallet } from "@spongewallet/sdk";
const wallet = await SpongeWallet.connect();
const anthropic = new Anthropic();
const tools = wallet.tools();Tool Definitions
Get tool definitions for the Anthropic API:
const tools = wallet.tools();
console.log(tools.definitions);
// [
// {
// name: "get_balance",
// description: "Get wallet balance on one or all chains",
// input_schema: {
// type: "object",
// properties: {
// chain: { type: "string", enum: ["ethereum", "base", "solana"] }
// }
// }
// },
// {
// name: "transfer",
// description: "Transfer crypto to an address",
// input_schema: {
// type: "object",
// properties: {
// chain: { type: "string" },
// to: { type: "string" },
// amount: { type: "string" },
// currency: { type: "string" }
// },
// required: ["chain", "to", "amount", "currency"]
// }
// },
// // ... more tools
// ]Executing Tool Calls
const response = await anthropic.messages.create({
model: "claude-sonnet-4-20250514",
max_tokens: 1024,
messages: [
{ role: "user", content: "Send 10 USDC to 0x1234..." }
],
tools: tools.definitions
});
// Process the response
const messages = [{ role: "user", content: "Send 10 USDC to 0x1234..." }];
for (const block of response.content) {
if (block.type === "tool_use") {
// Execute the tool
const result = await tools.execute(block.name, block.input);
// Add to conversation
messages.push({
role: "assistant",
content: response.content
});
messages.push({
role: "user",
content: [{
type: "tool_result",
tool_use_id: block.id,
content: JSON.stringify(result)
}]
});
}
}
// Continue conversation if needed
if (response.stop_reason === "tool_use") {
const followUp = await anthropic.messages.create({
model: "claude-sonnet-4-20250514",
max_tokens: 1024,
messages,
tools: tools.definitions
});
}Complete Example
import Anthropic from "@anthropic-ai/sdk";
import { SpongeWallet } from "@spongewallet/sdk";
async function chat(userMessage: string) {
const wallet = await SpongeWallet.connect();
const anthropic = new Anthropic();
const tools = wallet.tools();
const messages: Anthropic.MessageParam[] = [
{ role: "user", content: userMessage }
];
let response = await anthropic.messages.create({
model: "claude-sonnet-4-20250514",
max_tokens: 1024,
system: "You are a helpful assistant with access to a crypto wallet. " +
"You can check balances, send crypto, and swap tokens.",
messages,
tools: tools.definitions
});
// Handle tool calls in a loop
while (response.stop_reason === "tool_use") {
const toolResults: Anthropic.ToolResultBlockParam[] = [];
for (const block of response.content) {
if (block.type === "tool_use") {
const result = await tools.execute(block.name, block.input);
toolResults.push({
type: "tool_result",
tool_use_id: block.id,
content: JSON.stringify(result)
});
}
}
messages.push({ role: "assistant", content: response.content });
messages.push({ role: "user", content: toolResults });
response = await anthropic.messages.create({
model: "claude-sonnet-4-20250514",
max_tokens: 1024,
messages,
tools: tools.definitions
});
}
// Extract text response
const textBlocks = response.content.filter(b => b.type === "text");
return textBlocks.map(b => b.text).join("\n");
}
// Usage
const answer = await chat("What's my balance on Base?");
console.log(answer);Tool Filtering
You can filter which tools are exposed to Claude:
// Only balance and transfer tools
const tools = wallet.tools({
include: ["get_balance", "transfer"]
});
// Everything except swap
const tools = wallet.tools({
exclude: ["solana_swap"]
});Error Handling
Tool execution can fail. Handle errors gracefully:
try {
const result = await tools.execute(block.name, block.input);
return { success: true, data: result };
} catch (error) {
return {
success: false,
error: error.message
};
}Claude will see the error and can explain it to the user or try a different approach.
Security Considerations
Transaction Approval
By default, Claude can execute transfers without confirmation. Consider implementing approval flows for production use.
Implementing Approval
const tools = wallet.tools({
beforeExecute: async (toolName, input) => {
if (toolName === "transfer") {
const approved = await promptUser(
`Approve transfer of ${input.amount} ${input.currency} to ${input.to}?`
);
if (!approved) {
throw new Error("User declined the transfer");
}
}
}
});Using Spending Limits
Set spending limits on your agent to cap maximum transfers:
// Via master key admin
await admin.setSpendingLimit("agent_id", {
type: "per_transaction",
amount: "100.0",
currency: "USD"
});Allowlist Restrictions
Restrict transfers to approved addresses only:
await admin.addToAllowlist("agent_id", {
chain: "base",
address: "0xTrustedAddress",
label: "Treasury"
});MCP Resources & Prompts
The MCP server also provides resources and prompts:
Resources
// Available via MCP resource reading
const resources = await mcpClient.listResources();
// ["x402-services"] - Catalog of x402 payment servicesPrompts
const prompts = await mcpClient.listPrompts();
// [
// "sponge-guide" - Decision matrix for Sponge tool usage
// "x402-guide" - x402 payment protocol guide
// "how-to-search" - Web search instructions
// ]Debugging
Enable debug logging:
const tools = wallet.tools({
debug: true
});
// Or via environment variable
// SPONGE_DEBUG=true