Skip to main content
Glama

🏦 defi-mcp

Give your AI agent eyes on DeFi. An MCP server that lets Claude, Cursor or any MCP client read Aave V3 positions, compare markets and simulate the health-factor impact of an action — before anyone signs a transaction.

TypeScript MCP viem Read-only License


Why

LLMs are good at explaining risk but blind to on-chain state. defi-mcp gives an agent a small set of typed, read-only tools so it can answer questions like:

"How close am I to liquidation on Base?" "If I borrow 2,000 USDC more, what happens to my health factor?" "Where's the best stablecoin supply rate right now — Arbitrum or Optimism?"

No private keys, no signing, no transactions. The agent can look and simulate, the human decides.

Related MCP server: chain-data

Tools

Tool

What it does

aave_markets

All Aave V3 reserves on a chain: price, supply / borrow APY, LTV, liquidation threshold, utilization. Filter and sort.

aave_account

A wallet's position: collateral, debt, health factor, risk label, net APY, per-asset breakdown, and how far each collateral price can drop before liquidation.

aave_simulate

What-if for up to 10 chained actions (supply / withdraw / borrow / repay) → health factor after every step. Rejects impossible actions.

wallet_balances

Native + ERC-20 balances (Aave reserve tokens) with USD values.

Chains: Ethereum · Base · Arbitrum · Optimism · Polygon

Architecture

flowchart LR
    A[Claude / Cursor / any MCP client] -- stdio --> S[defi-mcp]
    S --> T[tools.ts<br/>zod-validated inputs]
    T --> C[aave/client.ts<br/>viem multicall + 60s cache]
    T --> M[math.ts<br/>HF, APY, liquidation drop<br/>pure + unit-tested]
    C --> P[PoolAddressesProvider]
    P --> Pool & Oracle & DataProvider
  • One address per chain. Only Aave's PoolAddressesProvider is hard-coded; Pool, Oracle and DataProvider are resolved at runtime, so protocol upgrades don't break the server.

  • Multicall everywhere. A full account read is ~3 RPC round-trips regardless of how many reserves a chain has.

  • Pure risk math. Health factor, APY compounding and liquidation-price math live in math.ts with no network access and are covered by tests.

Quick start

git clone https://github.com/StanislavV01/defi-mcp && cd defi-mcp
npm install && npm run build

Claude Desktop

Add to claude_desktop_config.json:

{
  "mcpServers": {
    "defi": {
      "command": "node",
      "args": ["/absolute/path/to/defi-mcp/dist/index.js"],
      "env": { "RPC_URL_BASE": "https://your-base-rpc" }
    }
  }
}

Claude Code

claude mcp add defi -- node /absolute/path/to/defi-mcp/dist/index.js

Try it in the MCP Inspector

npm run inspect

Use as a library

The same reads and risk math are exported for direct use, e.g. as tools in an AI SDK agent:

import { getAccount, toSimPositions, applyAction, computeHealth } from "defi-mcp";

const account = await getAccount("base", "0x…");
const after = applyAction(toSimPositions(account), "borrow", "USDC", 500);
console.log(computeHealth(after).healthFactor);
npm install github:StanislavV01/defi-mcp

Configuration

Public RPCs work out of the box but are rate-limited. For real use set your own:

Variable

Chain

RPC_URL_ETHEREUM

Ethereum

RPC_URL_BASE

Base

RPC_URL_ARBITRUM

Arbitrum

RPC_URL_OPTIMISM

Optimism

RPC_URL_POLYGON

Polygon

Example

You: Check 0x… on Base. If I borrow 1,500 USDC, am I still safe?

The agent calls aave_account, then aave_simulate:

{
  "before": { "healthFactor": 2.49, "debtUsd": 1000 },
  "after":  { "healthFactor": 0.996, "debtUsd": 2500 },
  "risk": "LIQUIDATABLE",
  "warning": "This sequence would make the position liquidatable — Aave would reject the borrow/withdraw."
}

…and explains why, instead of guessing.

Development

npm run dev        # run from source
npm test           # unit tests (node:test)
npm run typecheck

Limitations

  • Simulation does not model eMode, isolation mode or interest accrual — results are estimates, clearly labelled as such.

  • Read-only by design. Transaction building lives in the companion project DeFi Agent (coming next).

Roadmap

  • eMode-aware simulation

  • More protocols (Morpho, Compound V3)

  • prepare_transaction tool returning unsigned calldata for human signing

  • Publish to npm (npx defi-mcp)

License

MIT © Stanislav Verbytskyi

Available Tools

4 tools
aave_accountAave V3 accountB

Get a wallet's Aave V3 position: collateral, debt, health factor, risk level, net APY and per-asset breakdown. Health factor < 1 means the position can be liquidated.

Inputs: address (required), chain.

aave_marketsAave V3 marketsA

List Aave V3 reserves on a chain with price, supply/borrow APY, LTV, liquidation threshold and utilization. Use to compare where to supply or borrow. APYs are fractions (0.05 = 5%).

Inputs: chain, sortBy, symbols.

aave_simulateSimulate Aave actionA

What-if: estimate the health factor after a sequence of supply / withdraw / borrow / repay actions, without sending any transaction. Use before recommending an action to the user. Estimate ignores eMode and interest accrual; treat values close to 1 as unsafe.

Inputs: actions (required), address (required), chain.

wallet_balancesWallet balancesB

Native and ERC-20 balances of a wallet (tokens that are Aave reserves on the chain), with USD values.

Inputs: address (required), chain.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.6/5.0

    Scored across 4 tools

    Disambiguation4/5

    Each tool targets a distinct facet: market data (aave_markets), a user's position (aave_account), hypothetical outcomes (aave_simulate), and raw wallet holdings (wallet_balances). The only mild overlap is aave_account vs wallet_balances, both returning per-asset holdings, but the descriptions make the Aave-position vs raw-balance boundary clear.

    Naming Consistency4/5

    All four names are snake_case and follow a resource-prefix pattern (aave_*, wallet_*), which reads predictably. The verbs are implicit rather than an explicit verb_noun convention (e.g. 'aave_account' and 'aave_markets' are noun-only), a minor deviation from a strict pattern.

    Tool Count4/5

    Four tools is on the lean side but each covers a genuinely different question (where to supply, what my position is, what would happen, what I hold). Nothing feels redundant or padded, though the set sits just below the typical 3-15 comfort range.

    Completeness3/5

    The read-only analytics lifecycle is coherent, but there is no path to actually execute or prepare supply/borrow/repay transactions, and no liquidation or historical-rate data. Despite the broad 'defi-mcp' name, coverage is limited to Aave V3, so agents hit a dead end when asked to act or to use another protocol.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      D
      maintenance
      Enables AI assistants to analyze Aave V3 positions on Ethereum, monitor health factors, identify liquidation opportunities, and query protocol data including collateral positions, debt composition, and real-time asset prices.
      8
      1
      MIT
    • A
      license
      A
      quality
      C
      maintenance
      Enables AI agents to fetch live multi-chain portfolio, token info, gas prices, and token prices across Ethereum, Base, Polygon, Arbitrum, and Optimism with a single call. No API key required.
      4
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI agents to check DeFi liquidation risk levels for lending protocols like Aave, Compound, and Morpho, including at-risk positions, liquidation prices, current prices, and aggregate exposure. Access is pay-per-call via x402 micropayments with USDC on Base, requiring no API key or signup.
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI agents to monitor stablecoin yields, balances, and rewards across Aave, Morpho, and Euler on multiple EVM chains, and to deposit, withdraw, or rebalance positions via user-signed transactions.
      MIT