Skip to main content

An MCP server giving AI agents access to DeFi data on EVM chains.

Project description

defi-mcp

An MCP (Model Context Protocol) server that gives AI agents direct, on-chain access to DeFi data on EVM chains — wallet balances, Aave v3 lending positions, and live token prices, with no centralized API in the middle.

Status: Live and functional. 4 tools available today, more on the roadmap.

Why

Most "DeFi + AI" integrations route through a centralized API that can rate-limit, paywall, or simply disappear. defi-mcp talks directly to the chain (via your own RPC provider) and to first-party oracles (Chainlink), so the data your AI agent gets is exactly what's on-chain — verifiable, and not dependent on a third-party API staying online.

Tools

get_token_balance

Reads the ERC-20 balance of any wallet address for a supported token.

Supported tokens on Polygon: USDC, USDC.e, USDT, WETH, WMATIC, WBTC, DAI, AAVE.

// get_token_balance(address="0x...", token_symbol="USDC", chain="polygon")
{
  "address": "0x...",
  "token": "USDC",
  "chain": "polygon",
  "balance": 268.21,
  "raw_balance": "268210000",
  "decimals": 6
}

get_aave_position

Reads a user's full Aave v3 lending/borrowing position: collateral, debt, available borrowing power, and health factor — straight from the Aave v3 Pool contract.

// get_aave_position(address="0x...", chain="polygon")
{
  "address": "0x...",
  "chain": "polygon",
  "total_collateral_usd": 969.78,
  "total_debt_usd": 288.16,
  "available_borrows_usd": 484.86,
  "liquidation_threshold_pct": 82.79,
  "ltv_pct": 79.71,
  "health_factor": 2.79,
  "has_active_position": true
}

A health_factor below 1.0 means the position is at risk of liquidation. A null health factor means the user has no outstanding debt.

get_token_price

Reads the current USD price of a token directly from a Chainlink price feed — the same oracle DeFi protocols use internally, so the price is consistent with what get_aave_position reports.

Supported on Polygon: ETH/WETH, MATIC/WMATIC, WBTC, USDC, USDT.

// get_token_price(token_symbol="WBTC", chain="polygon")
{
  "token": "WBTC",
  "chain": "polygon",
  "price_usd": 63835.77,
  "decimals": 8,
  "updated_at": 1782032816
}

hello

Simple connectivity check — confirms the MCP server is reachable and responding.

Supported chains

  • Polygon

More EVM chains are on the roadmap (see below).

Installation

Requires Python 3.10+ and an RPC provider API key (e.g. Alchemy, free tier works).

git clone https://github.com/matiosera3-ops/defi-mcp.git
cd defi-mcp
python -m venv venv

# Windows
.\venv\Scripts\Activate.ps1
# macOS/Linux
source venv/bin/activate

pip install -e .

Create a .env file in the project root:

POLYGON_RPC_URL=https://polygon-mainnet.g.alchemy.com/v2/YOUR_API_KEY

Usage with Claude Desktop

Add this to your Claude Desktop MCP config (claude_desktop_config.json):

{
  "mcpServers": {
    "defi-mcp": {
      "command": "python",
      "args": ["/absolute/path/to/defi-mcp/server.py"]
    }
  }
}

Restart Claude Desktop, and the tools above will be available to the model.

Testing locally

You can test the server directly with the official MCP Inspector:

npx @modelcontextprotocol/inspector python server.py

Roadmap

  • Track Uniswap v3 LP positions and impermanent loss
  • Simulate swaps with realistic slippage estimates
  • Monitor protocol TVLs
  • Additional chains (Ethereum, Arbitrum, Base)
  • defi-mcp-cloud — hosted tier with MEV-specific tools, caching, and higher rate limits

Architecture

Open-core model: this repository (MIT licensed) covers standard on-chain read tools. A separate defi-mcp-cloud will offer a hosted version with MEV-related tools, request caching, and managed RPC access for users who don't want to run their own infrastructure.

Contributing

Issues and PRs welcome. This is an early-stage project — feedback on what tools would actually be useful to you is especially valuable.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

defi_mcp-0.1.1.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

defi_mcp-0.1.1-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file defi_mcp-0.1.1.tar.gz.

File metadata

  • Download URL: defi_mcp-0.1.1.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for defi_mcp-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ab543f06d847efde7b7df1a39c9a12f8403944a42cfc33d6cc9759c797a24030
MD5 bd4cb80bba48f384444270c7a2657155
BLAKE2b-256 21f0cc7e5099e3b513dbc783c6dde70811963657e3de715ace00d94f3e6968d2

See more details on using hashes here.

File details

Details for the file defi_mcp-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: defi_mcp-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for defi_mcp-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 243e84a33c75bba4cc67521e502840479d23f02cdf3a6036b9be801ed4c7e460
MD5 218be9fbe8ff1fe485b4cb5b6631e677
BLAKE2b-256 ab1866b14b213355d74a55a50fe33d336ca5a136e10460cd63c413c07bb01c00

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page