DE

DeFi Rates MCP Server: Cross-Chain Lending Comparison

Compare real-time DeFi lending rates across 13+ protocols and chains with the MCP server to find best opportunities and calculate looping strategies.

Quick Install
npx -y @qingfeng/defi-rates-mcp

Overview

The DeFi Rates MCP Server is a lightweight backend that collects, normalizes, and serves real-time lending and borrowing rates from multiple DeFi protocols and blockchains. It implements the Model Context Protocol (MCP) pattern to make normalized market data available to downstream models, agents, dashboards, or automated strategies. By aggregating rates from 13+ protocols and chains, it simplifies cross-protocol comparisons and enables programmatic calculation of looping (borrow-to-lend) strategies.

This server is useful when you need a single canonical view of supply/borrow APYs, utilization, and collateral parameters across heterogeneous lending markets. Typical consumers include trading bots, portfolio analytics, front-end rate explorers, and research workflows that require up-to-date, comparable rate data and simple strategy calculations.

Features

  • Aggregates live lending/borrowing rates across 13+ DeFi protocols and multiple chains
  • Normalizes disparate provider formats into a consistent JSON schema
  • On-demand comparison API for best-supply / best-borrow opportunities
  • Looping strategy calculator to estimate effective APY for repeated borrow→lend cycles
  • Simple REST API and model-friendly outputs (MCP-compatible context)
  • Configurable adapters for adding new protocols or chains
  • Docker-ready for easy deployment and CI integration

Installation / Configuration

Clone the repo and install dependencies:

git clone https://github.com/qingfeng/defi-rates-mcp.git
cd defi-rates-mcp
# If Node.js project
npm ci
# Or if Python-based, use pip:
# pip install -r requirements.txt

Environment-driven configuration (example):

# Example environment variables
export PORT=3000
export RPC_URL_MAINNET=https://mainnet.infura.io/v3/YOUR_KEY
export RPC_URL_BSC=https://bsc-dataseed.binance.org/
export CACHE_TTL=30               # seconds
export LOG_LEVEL=info

Run locally:

# npm start
npm run start
# or
node src/server.js

Run with Docker:

docker build -t defi-rates-mcp .
docker run -p 3000:3000 \
  -e RPC_URL_MAINNET=https://mainnet.infura.io/v3/YOUR_KEY \
  -e RPC_URL_BSC=https://bsc-dataseed.binance.org/ \
  defi-rates-mcp

Adapter configuration (example JSON snippet):

{
  "adapters": [
    { "name": "aave-v3", "chain": "ethereum", "enabled": true },
    { "name": "compound-v2", "chain": "ethereum", "enabled": true },
    { "name": "venus", "chain": "bsc", "enabled": true }
  ],
  "pollInterval": 15
}

Place adapter config in config/adapters.json or set the path via CONFIG_PATH env var.

Available Resources

  • GitHub repository: https://github.com/qingfeng/defi-rates-mcp (source, adapters, and tests)
  • API base (local): http://localhost:3000
  • Typical endpoints (see repo for exact routes and OpenAPI spec):
    • GET /health — server status
    • GET /rates — current normalized rates for all markets
    • POST /compare — compare supplied asset across protocols
    • POST /loop — estimates for looping strategies
  • Adapter templates: add support for new protocols by implementing an adapter module (see adapters/README)
  • Example clients: simple Python and TypeScript examples in examples/ folder

Response Schema (example)

The server normalizes provider outputs; a typical market object looks like:

FieldTypeDescription
assetstringToken symbol (e.g., USDC)
chainstringChain identifier (ethereum, bsc, polygon)
protocolstringProtocol name (Aave, Compound, etc.)
supplyApynumberCurrent supply APY (percentage)
borrowApynumberCurrent borrow APY (percentage)
utilizationnumberUtilization ratio (0-1)
collateralFactornumberLoan-to-value or borrow factor
timestampstringISO timestamp of the source reading

Use Cases

  1. Find the best place to lend USDC right now

    • Request: POST /compare with body { “asset”: “USDC”, “side”: “supply” }
    • Result: server returns a ranked list of markets with supplyApy, chain, and protocol so you can pick the highest APY.
  2. Compare borrowing cost across chains for a leveraged position

    • Request: POST /compare with { “asset”: “ETH”, “side”: “borrow”, “amount”: 10 }
    • Result: ranked borrow rates across protocols; feed the best borrow into a leverage simulator or execution agent.
  3. Estimate a looping strategy (borrow → lend multiple times)

    • Request: POST /loop with { “asset”: “DAI”, “initialAmount”: 1000, “loops”: 3, “collateralFactor”: 0.75, “supplyProtocol”: “aave”, “borrowProtocol”: “compound” }
    • Result: estimated effective APY,