MCP DefiLlama
Access DeFi protocol TVL, yields, stablecoin data, and market analytics from DefiLlama.
- Package:
@iqai/defillama-mcp - Provider: DefiLlama
Overview
The DefiLlama MCP server gives your agent access to DeFi market data aggregated by DefiLlama. It covers protocol TVL, yield farming opportunities, stablecoin metrics, token prices, and bridge volumes. No API key is required for basic usage.
Getting Started
Install the package:
pnpm add @iqai/defillama-mcpUse the server in your agent:
import { McpDefillama } from "@iqai/adk";
const toolset = McpDefillama();
const tools = await toolset.getTools();import { McpToolset } from "@iqai/adk";
const toolset = new McpToolset({
name: "Defillama MCP Client",
description: "Client for DeFi analytics via DefiLlama",
transport: {
mode: "stdio",
command: "npx",
args: ["-y", "@iqai/defillama-mcp"],
},
});
const tools = await toolset.getTools();{
"mcpServers": {
"defillama-mcp-server": {
"command": "npx",
"args": ["-y", "@iqai/defillama-mcp"]
}
}
}Environment Variables
No environment variables are required. The following optional variables enable enhanced functionality:
| Variable | Required | Description |
|---|---|---|
DEFILLAMA_API_KEY | No | DefiLlama API key for higher rate limits |
IQ_GATEWAY_URL | No | Custom IQ Gateway URL for enhanced data resolution |
IQ_GATEWAY_KEY | No | Authentication key for the IQ Gateway |
OPENROUTER_API_KEY | No | OpenRouter API key for LLM integration |
GOOGLE_GENERATIVE_AI_API_KEY | No | Google Generative AI key (alternative to OpenRouter) |
LLM_MODEL | No | LLM model name for AI-enhanced queries (default: openai/gpt-4.1-mini) |
Available Tools
defillama_get_chainsorder:string_userQuery:string
defillama_get_chainsDescription
Fetches blockchain chains ranked by Total Value Locked (TVL), returning the top 20. Use this tool to: (1) answer user queries about leading DeFi blockchains, or (2) discover valid chain name formats before calling other tools.
defillama_get_protocol_dataprotocol:stringsortCondition:stringorder:string_userQuery:string
defillama_get_protocol_dataDescription
Fetches TVL (Total Value Locked) data for DeFi protocols. AUTO-RESOLUTION ENABLED: Pass protocol names as users mention them (e.g., 'Lido', 'Uniswap', 'Aave', 'MakerDAO') - they're automatically resolved to correct slugs via AI.
defillama_get_historical_chain_tvlchain:string_userQuery:string
defillama_get_historical_chain_tvlDescription
Fetches historical TVL (Total Value Locked) data for blockchain chains over time. Returns the last 10 data points showing TVL evolution. Can return data for a specific chain or aggregated data across all chains.
defillama_get_dexs_dataexcludeTotalDataChart:booleanexcludeTotalDataChartBreakdown:booleanprotocol:stringchain:stringsortCondition:stringorder:string_userQuery:string
defillama_get_dexs_dataDescription
Fetches DEX (decentralized exchange) trading volume data and metrics. Returns different levels of data based on parameters: specific protocol data (most detailed), chain-specific overview, or global overview (all DEXs). AUTO-RESOLUTION ENABLED: Protocol and chain names are automatically matched.
defillama_get_fees_and_revenueexcludeTotalDataChart:booleanexcludeTotalDataChartBreakdown:booleandataType:stringchain:stringprotocol:stringsortCondition:stringorder:string_userQuery:string
defillama_get_fees_and_revenueDescription
Fetches fees and revenue metrics for DeFi protocols. Can filter by specific protocol and/or chain. AUTO-RESOLUTION ENABLED: Protocol and chain names are automatically matched.
defillama_get_stablecoinincludePrices:boolean_userQuery:string
defillama_get_stablecoinDescription
Fetches stablecoin data including circulation and price information. Returns top 20 stablecoins
defillama_get_stablecoin_chains_userQuery:string
defillama_get_stablecoin_chainsDescription
Fetches stablecoin data by chains. Returns last 3 chains with market cap data
defillama_get_stablecoin_chartsstablecoin:anychain:string_userQuery:string
defillama_get_stablecoin_chartsDescription
Fetches historical market cap charts for stablecoins over time. Returns the last 10 data points showing circulation, USD values, and bridged amounts. Can filter by blockchain or specific stablecoin, or show global aggregated data
defillama_get_stablecoin_prices_userQuery:string
defillama_get_stablecoin_pricesDescription
Fetches historical stablecoin price data. Returns last 3 data points
defillama_get_prices_current_coinscoins:stringsearchWidth:any_userQuery:string
defillama_get_prices_current_coinsDescription
Fetches current token prices from DefiLlama. Requires token addresses in the format chain:address (e.g., 'ethereum:0xdac17f958d2ee523a2206206994597c13d831ec7' for USDT). Can fetch multiple tokens at once by comma-separating them
defillama_get_prices_first_coinscoins:string_userQuery:string
defillama_get_prices_first_coinsDescription
Fetches the first recorded historical prices for specified cryptocurrency tokens. Useful for finding when a token was first listed/tracked or its initial price point
defillama_get_batch_historicalcoins:anysearchWidth:any_userQuery:string
defillama_get_batch_historicalDescription
Fetches historical price data for multiple cryptocurrencies at specific timestamps. Useful for getting prices of multiple coins at the same or different points in time
defillama_get_historical_prices_by_contractcoins:stringtimestamp:anysearchWidth:any_userQuery:string
defillama_get_historical_prices_by_contractDescription
Fetches historical prices for tokens at a specific point in time using their contract addresses. Useful for getting price data at exact timestamps for analysis or backtesting
defillama_get_percentage_coinscoins:stringtimestamp:anyperiod:stringlookForward:boolean_userQuery:string
defillama_get_percentage_coinsDescription
Fetches percentage price change for tokens over a specified time period. Calculates how much token prices changed from a starting point, either looking backward (default) or forward in time
defillama_get_chart_coinscoins:stringstart:anyend:anyspan:integerperiod:stringsearchWidth:any_userQuery:string
defillama_get_chart_coinsDescription
Fetches historical price chart data for one or more cryptocurrency tokens across different blockchains. Returns time-series price data with customizable time range and data point frequency
defillama_get_latest_pool_datasortCondition:stringorder:stringlimit:integer_userQuery:string
defillama_get_latest_pool_dataDescription
Fetches current yield farming pool data including APY rates, TVL, and rewards. Returns a list of pools that can be filtered and sorted by various metrics
defillama_get_historical_pool_datapool:string_userQuery:string
defillama_get_historical_pool_dataDescription
Fetches historical APY and TVL data for a specific yield farming pool over time. Returns the last 10 data points showing how the pool's metrics have changed
defillama_get_options_datadataType:stringprotocol:stringchain:stringsortCondition:stringorder:stringexcludeTotalDataChart:booleanexcludeTotalDataChartBreakdown:boolean_userQuery:string
defillama_get_options_dataDescription
Fetches options protocol data including trading volume and premium metrics. Returns different levels of data: specific protocol data (most detailed), chain-specific overview, or global overview (all options protocols). AUTO-RESOLUTION ENABLED: Protocol and chain names are automatically matched.
defillama_get_blockchain_timestampchain:stringtimestamp:any_userQuery:string
defillama_get_blockchain_timestampDescription
Fetches blockchain block information for a specific chain at a given timestamp. Returns the block number, timestamp, and height that existed at that point in time.
Integration Example
import { AgentBuilder, McpDefillama } from "@iqai/adk";
import * as dotenv from "dotenv";
dotenv.config();
async function main() {
// Initialize McpDefillama toolset
const toolset = McpDefillama();
// Get available McpDefillama tools
const defillamaTools = await toolset.getTools();
// Create agent with McpDefillama tools
const { runner } = await AgentBuilder.create("defillama_agent")
.withModel("gemini-2.5-flash")
.withDescription("A DeFi research agent powered by DefiLlama data")
.withTools(...defillamaTools)
.build();
const response = await runner.ask(
"What are the top 5 DeFi protocols by TVL right now?",
);
console.log(response);
}
main().catch(console.error);