pypi defi-mcpstdioMITupdated 2mo ago
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.
What can you do with defi mcp?
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. 5 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:
- Polygon:
USDC,USDC.e,USDT,WETH,WMATIC,WBTC,DAI,AAVE - Arbitrum:
USDC,USDC.e(bridged),USDT,WETH,WBTC,ARB
// 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 feeds:
- Polygon:
ETH/WETH,MATIC/WMATIC,WBTC,USDC,USDT - Arbitrum:
ETH/WETH,WBTC,ARB,USDC,USDT
// get_token_price(token_symbol="WBTC", chain="polygon")
{
"token": "WBTC",
"chain": "polygon",
"price_usd": 63835.77,
"decimals": 8,
"updated_at": 1782032816
}
simulate_swap
Simulates a Uniswap v3 swap on-chain via the QuoterV2 contract ā no transaction submitted, no wallet needed. Tries all four fee tiers (0.01%, 0.05%, 0.3%, 1%) and returns the best available output amount.
Supported tokens:
- Polygon:
USDC,USDC.e,USDT,WETH,WMATIC,WBTC,DAI,AAVE - Arbitrum:
USDC,USDC.e(bridged),USDT,WETH,WBTC,ARB
// simulate_swap(token_in="WMATIC", token_out="USDC", amount_in=100.0, chain="polygon")
{
"chain": "polygon",
"token_in": "WMATIC",
"token_out": "USDC",
"amount_in": 100.0,
"amount_out": 7.990547,
"fee_tier_used_pct": 0.05,
"fee_tier_used_bps": 500,
"gas_estimate": 122770
}
If no pool exists for the pair at any fee tier, returns {"error": "No liquidity found for this pair on any fee tier"}.
hello
Simple connectivity check ā confirms the MCP server is reachable and responding.
Supported chains
| Chain | get_token_balance |
get_aave_position |
get_token_price |
simulate_swap |
|---|---|---|---|---|
| Polygon | ā | ā | ā | ā |
| Arbitrum | ā | ā | ā | ā |
Installation
Requires Python 3.10+ and an RPC provider API key (e.g. Alchemy, free tier works).
pip install defi-mcp
Create a .env file in your working directory (see .env.example):
POLYGON_RPC_URL=https://polygon-mainnet.g.alchemy.com/v2/YOUR_API_KEY
ARBITRUM_RPC_URL=https://arb-mainnet.g.alchemy.com/v2/YOUR_API_KEY
Each chain only needs its RPC URL configured. Tools called with chain="arbitrum" will fail gracefully if ARBITRUM_RPC_URL is not set.
Usage with Claude Desktop
Add this to your Claude Desktop MCP config (claude_desktop_config.json):
{
"mcpServers": {
"defi-mcp": {
"command": "uvx",
"args": ["defi-mcp"],
"env": {
"POLYGON_RPC_URL": "https://polygon-mainnet.g.alchemy.com/v2/YOUR_API_KEY",
"ARBITRUM_RPC_URL": "https://arb-mainnet.g.alchemy.com/v2/YOUR_API_KEY"
}
}
}
}
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 uvx defi-mcp
Roadmap
- Track Uniswap v3 LP positions and impermanent loss
- Monitor protocol TVLs
- Additional chains (Ethereum, 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.
Resources
- defi-storage-cheatsheet ā verified EVM storage slot layouts for Aave v3 and Uniswap v3, with
web3.pysnippets. Useful if you want to read on-chain state directly viaeth_getStorageAtinstead of callingviewfunctions ā the lower-level approach behind some of what this server does under the hood.
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
Install
Add defi mcp to your client. Pick the one you use.
claude mcp add defi-mcp -- uvx defi-mcpcodex mcp add defi-mcp -- uvx defi-mcpamp mcp add defi-mcp -- uvx defi-mcp{
"mcpServers": {
"defi-mcp": {
"command": "uvx",
"args": [
"defi-mcp"
]
}
}
}Add to `claude_desktop_config.json`, then restart Claude Desktop.
{
"mcpServers": {
"defi-mcp": {
"command": "uvx",
"args": [
"defi-mcp"
]
}
}
}Add to `~/.cursor/mcp.json`, or `.cursor/mcp.json` for a single project.
code --add-mcp '{"name":"defi-mcp","command":"uvx","args":["defi-mcp"]}'Or add the block manually to `.vscode/mcp.json` under `servers`.
{
"mcpServers": {
"defi-mcp": {
"command": "uvx",
"args": [
"defi-mcp"
]
}
}
}Add to `~/.codeium/windsurf/mcp_config.json`.
{
"mcpServers": {
"defi-mcp": {
"command": "uvx",
"args": [
"defi-mcp"
]
}
}
}Add to `cline_mcp_settings.json` via the MCP Servers panel.
{
"mcpServers": {
"defi-mcp": {
"command": "uvx",
"args": [
"defi-mcp"
]
}
}
}Add to `~/.gemini/settings.json`.
{
"mcpServers": {
"defi-mcp": {
"type": "local",
"command": "uvx",
"args": [
"defi-mcp"
],
"tools": [
"*"
]
}
}
}Add to `~/.copilot/mcp-config.json`, or run `/mcp add` inside the CLI.
{
"context_servers": {
"defi-mcp": {
"command": {
"path": "uvx",
"args": [
"defi-mcp"
]
}
}
}
}Add to your Zed `settings.json`.
uvx defi-mcpRun `goose configure`, choose **Add Extension ā Command-line Extension**, and paste this command.
Score
75 / 100
Good
- Documentation25/25
- Maintenance22/25
- Trust13/20
- Capability3/15
- Install experience12/15
- Documents what it does and how to connect
- Has a resolvable package or endpoint
- Exposes at least one tool, prompt or resource
- README has substantive content
- Includes a code example
- Documents its configuration
- Mentions credentials or security posture
- Last commit 69 days ago
- Has a release history
- Repository is not archived
- Licensed MIT
- Namespace verified in the official MCP registry
- Claimed by its owner
- Published under an organisation
- 0 tool(s) documented
- Provides prompt templates
- Provides resources
- 12 documented install method(s)
- Published to a package registry
- Offers a hosted endpoint ā no local install
Version history
| Versions | Published |
|---|---|
| 0.1.6Latest | Jun 23, 2026 |
| 0.1.5 | Jun 23, 2026 |
| 0.1.3 | Jun 22, 2026 |
| 0.1.1 | Jun 21, 2026 |