DEV Community

Cover image for Claude Waits for Cheap Gas: MCP Tools for Gas-Conditional DeFi Execution
Wallet Guy
Wallet Guy

Posted on

Claude Waits for Cheap Gas: MCP Tools for Gas-Conditional DeFi Execution

Claude Waits for Cheap Gas: MCP Tools for Gas-Conditional DeFi Execution

MCP tools for DeFi execution are about to change how your Claude agent interacts with onchain protocols — instead of hardcoding wallet logic into every script, you add one entry to claude_desktop_config.json and Claude gains a fully-featured wallet with 45 tools covering swaps, staking, lending, bridging, and yes, gas-conditional execution. This post shows you exactly how to set that up and why gas conditions matter for autonomous agents running DeFi strategies.

The Problem: Autonomous Agents and Gas Timing

Anyone who has run an automated DeFi strategy knows the pain. Your agent executes a swap at exactly the wrong moment — gas spikes, the transaction costs three times what it should, and the trade is no longer profitable. If a human were watching, they'd wait. But autonomous agents don't wait. They fire and forget.

This is a real problem when you're giving an AI agent control over onchain actions. The agent might be smart enough to find the right trade, but without infrastructure that enforces execution conditions, it'll burn gas whenever it decides to move. For long-running strategies — think recurring rebalancing, yield harvesting, or position management — bad gas timing compounds into serious losses over time.

The answer isn't to make the agent smarter about gas in every prompt. The answer is to build the gas condition into the infrastructure layer, so the agent can't execute until conditions are met. That's exactly what WAIaaS's gas conditional execution feature does, and it's exposed directly through MCP tools that Claude can call.

What WAIaaS Brings to Claude Desktop

WAIaaS is an open-source, self-hosted Wallet-as-a-Service designed for AI agents. It runs as a local daemon (default port 3100) and exposes its capabilities through multiple integration surfaces — REST API, TypeScript SDK, Python SDK, and an MCP server.

The MCP server is the interesting part for Claude users. It packages 45 tools into a single stdio-based server that Claude Desktop can call directly. Those tools cover:

  • Wallet operations (balance, address, assets, transaction history)
  • Token transfers and batch transactions
  • DeFi actions across 15 integrated protocols
  • NFT queries and transfers
  • ERC-4337 UserOp building and signing
  • x402 HTTP payment protocol
  • Simulation and dry-run before execution
  • WalletConnect integration for human approval flows

The gas conditional execution feature (FEAT-GAS) lives in the transaction pipeline. When your agent submits a transaction, the pipeline checks whether the current gas price meets a configured threshold before proceeding to execution. The agent doesn't need to poll gas prices, implement retry logic, or manage any of this — it submits, and the infrastructure handles the waiting.

One Line to Give Claude a Wallet

Here's the configuration. Open ~/Library/Application Support/Claude/claude_desktop_config.json and add:

{
  "mcpServers": {
    "waiaas": {
      "command": "npx",
      "args": ["-y", "@waiaas/mcp"],
      "env": {
        "WAIAAS_BASE_URL": "http://127.0.0.1:3100",
        "WAIAAS_SESSION_TOKEN": "wai_sess_<your-token>",
        "WAIAAS_DATA_DIR": "~/.waiaas"
      }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

That's it. Restart Claude Desktop, and Claude can now call any of the 45 MCP tools. It can check balances, send tokens, execute swaps on Jupiter, manage Aave positions, stake with Lido or Jito, bridge via LI.FI or Across, and more — all from natural language instructions in the chat window.

The transport is stdio, which means no network ports are opened for the MCP connection itself. The MCP process talks to your local WAIaaS daemon over HTTP on 127.0.0.1:3100, which is bound to localhost only by default (fact DOCKER-02).

Getting the Daemon Running First

Before Claude can use the tools, you need the daemon running. The fastest path:

Step 1 — Install the CLI and initialize:

npm install -g @waiaas/cli
waiaas init --auto-provision
waiaas start
Enter fullscreen mode Exit fullscreen mode

The --auto-provision flag generates a random master password and writes it to recovery.key. No password prompt on startup — useful for getting started quickly. You can harden it later with waiaas set-master.

Step 2 — Create wallets and sessions in one command:

waiaas quickset --mode mainnet
Enter fullscreen mode Exit fullscreen mode

This creates wallets and MCP-ready session tokens in a single step. The CLI prints the MCP config JSON — paste it into your Claude Desktop config, or use:

waiaas mcp setup --all
Enter fullscreen mode Exit fullscreen mode

...to auto-register all wallets with Claude Desktop automatically.

Step 3 — Add the MCP config and restart Claude Desktop.

That's the whole setup. Three commands, one config edit.

Alternatively, if you prefer Docker:

git clone https://github.com/waiaas/WAIaaS.git
cd WAIaaS
docker compose up -d
Enter fullscreen mode Exit fullscreen mode

The Docker image (waiaas/daemon:latest) includes auto-provision support, Docker Secrets integration for production deployments, a healthcheck, and runs as a non-root user (UID 1001). The compose file binds to 127.0.0.1:3100:3100 by default, keeping the daemon local.

How Gas-Conditional Execution Works in Practice

The gas conditional execution feature (FEAT-GAS) sits inside WAIaaS's 7-stage transaction pipeline: validate → auth → policy → wait → execute → confirm. The gas condition check happens in the wait stage. If the current gas price exceeds your configured threshold, the transaction queues and waits. Once gas drops to an acceptable level, execution proceeds automatically.

From Claude's perspective, the interaction is simple. Claude calls the send or DeFi action tool, the transaction enters the pipeline, and Claude can query the transaction status later. The waiting happens server-side. Claude doesn't need to implement any retry logic or gas-checking loops.

Here's what that looks like from the REST API side (which the MCP tools wrap):

curl -X POST http://127.0.0.1:3100/v1/transactions/send \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer wai_sess_<token>" \
  -d '{
    "type": "TRANSFER",
    "to": "recipient-address",
    "amount": "0.1"
  }'
Enter fullscreen mode Exit fullscreen mode

Before you execute anything for real, you can simulate it:

curl -X POST http://127.0.0.1:3100/v1/transactions/send \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer wai_sess_<token>" \
  -d '{
    "type": "TRANSFER",
    "to": "recipient-address",
    "amount": "0.1",
    "dryRun": true
  }'
Enter fullscreen mode Exit fullscreen mode

The dry-run API (FEAT-DRYRUN) lets Claude (or you) validate a transaction's expected outcome before committing gas. For a DeFi agent running strategies autonomously, this is a useful safety check before any significant action.

The Policy Layer: What Claude Is and Isn't Allowed to Do

Giving Claude a wallet without guardrails is a bad idea. WAIaaS has a policy engine with 21 policy types and 4 security tiers — INSTANT, NOTIFY, DELAY, and APPROVAL — enforced on every transaction the agent attempts.

The default-deny behavior is important: transactions are blocked unless explicitly allowed. An agent without a CONTRACT_WHITELIST policy can't call arbitrary contracts. Without ALLOWED_TOKENS, it can't transfer arbitrary tokens. You define exactly what Claude can touch.

For a gas-conditional DeFi setup, a sensible starting policy set looks like this:

curl -X POST http://127.0.0.1:3100/v1/policies \
  -H "Content-Type: application/json" \
  -H "X-Master-Password: my-secret-password" \
  -d '{
    "walletId": "<wallet-uuid>",
    "type": "SPENDING_LIMIT",
    "rules": {
      "instant_max_usd": 100,
      "notify_max_usd": 500,
      "delay_max_usd": 2000,
      "delay_seconds": 900,
      "daily_limit_usd": 5000
    }
  }'
Enter fullscreen mode Exit fullscreen mode

With this configuration:

  • Transactions under $100 execute immediately (INSTANT)
  • $100–$500 execute but you get notified (NOTIFY)
  • $500–$2,000 queue for 15 minutes before executing, giving you time to cancel (DELAY)
  • Over $2,000 requires your explicit approval via WalletConnect or Telegram (APPROVAL)

The WalletConnect integration (FEAT-WC) is how you approve transactions from your phone when Claude requests something above your DELAY threshold. Claude submits the transaction, it lands in a pending state, and you get a WalletConnect prompt to approve or reject it.

There are also DeFi-specific policy types worth knowing about for this use case:

  • PERP_MAX_LEVERAGE — caps the leverage Claude can use on Hyperliquid perpetuals
  • PERP_MAX_POSITION_USD — caps absolute position size
  • LENDING_LTV_LIMIT — prevents Claude from borrowing against collateral at dangerous ratios on Aave
  • VENUE_WHITELIST — restricts which protocols Claude can interact with
  • ACTION_CATEGORY_LIMIT — limits DeFi action categories (e.g., allow swaps but not perpetuals)

These aren't just nice-to-haves. For a gas-conditional agent that executes while you're asleep, they're the guardrails that keep a strategy from going sideways.

The 15 DeFi Protocols Claude Can Access

Once your MCP session is configured and policies are set, Claude has access to 15 integrated DeFi protocol providers:

Swaps: Jupiter (Solana), 0x, D'CENT swap, LI.FI

Lending: Aave v3, Kamino, Pendle

Staking: Lido (EVM liquid staking), Jito (Solana)

Perpetuals: Hyperliquid (perps, spot, sub-accounts), Drift

Bridging: LI.FI, Across

Prediction markets: Polymarket

DEX: XRPL DEX

Onchain agent reputation: ERC-8004

For example, to execute a Jupiter swap (Solana), Claude calls the action-provider tool which maps to:

curl -X POST http://127.0.0.1:3100/v1/actions/jupiter-swap/swap \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer wai_sess_<token>" \
  -d '{
    "inputMint": "So11111111111111111111111111111111111111112",
    "outputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    "amount": "1000000000"
  }'
Enter fullscreen mode Exit fullscreen mode

Claude can also query DeFi positions across protocols using the get-defi-positions tool — useful for portfolio-aware agents that need to understand their current exposure before taking action.

Multi-Wallet Setup for Strategy Isolation

If you're running multiple strategies, you probably want them isolated in separate wallets with separate policies. WAIaaS supports this with per-wallet sessions and per-wallet policy sets.

The MCP config supports multiple named servers pointing to different wallets on the same daemon:

{
  "mcpServers": {
    "waiaas-trading": {
      "command": "npx",
      "args": ["-y", "@waiaas/mcp"],
      "env": {
        "WAIAAS_BASE_URL": "http://127.0.0.1:3100",
        "WAIAAS_AGENT_ID": "019c47d6-51ef-7f43-a76b-d50e875d95f4",
        "WAIAAS_AGENT_NAME": "trading-agent",
        "WAIAAS_DATA_DIR": "~/.waiaas"
      }
    },
    "waiaas-solana": {
      "command": "npx",
      "args": ["-y", "@waiaas/mcp"],
      "env": {
        "WAIAAS_BASE_URL": "http://127.0.0.1:3100",
        "WAIAAS_AGENT_ID": "019c4cd2-86e8-758f-a61e-9c560307c788",
        "WAIAAS_AGENT_NAME": "solana-wallet",
        "WAIAAS_DATA_DIR": "~/.waiaas"
      }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Two MCP servers, two wallets, two independent policy sets. Claude Desktop sees both as separate tool namespaces. Each wallet's session has its own TTL, renewal limits, and policy configuration — defined at session creation time (fact SEC-04).

What the Full Setup Looks Like

To recap the end-to-end picture:

  1. WAIaaS daemon runs locally (Docker or CLI), manages wallets, enforces policies, executes the 7-stage transaction pipeline including gas condition checks
  2. MCP server (@waiaas/mcp) connects Claude Desktop to the daemon via stdio, exposing 45 tools
  3. Claude receives natural language instructions, selects the appropriate MCP tool, and submits the action
  4. Policy engine validates the action against your 21 configured policy types before anything hits the chain
  5. Gas condition holds the transaction in the wait stage until gas price meets your threshold
  6. Signing channels notify you (Push, Telegram, WalletConnect) when human approval is needed

The agent does the reasoning. The infrastructure does the enforcement. You stay in control of what the agent is allowed to do and when transactions actually execute.

What's Next

The WAIaaS codebase is open source and actively developed — the monorepo has 15 packages, 684+ test files, and covers EVM and Solana across 18 networks. If you want to dig into the policy engine in detail, the OpenAPI spec and interactive reference UI are available at http://127.0.0.1:3100/doc and /reference once your daemon is running.

Star the repo, try the quickstart, and open an issue if you hit anything unexpected.

Top comments (0)