TypeScriptADK-TS

MCP DefiLlama

Access DeFi protocol TVL, yields, stablecoin data, and market analytics from 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-mcp

Use 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:

VariableRequiredDescription
DEFILLAMA_API_KEYNoDefiLlama API key for higher rate limits
IQ_GATEWAY_URLNoCustom IQ Gateway URL for enhanced data resolution
IQ_GATEWAY_KEYNoAuthentication key for the IQ Gateway
OPENROUTER_API_KEYNoOpenRouter API key for LLM integration
GOOGLE_GENERATIVE_AI_API_KEYNoGoogle Generative AI key (alternative to OpenRouter)
LLM_MODELNoLLM model name for AI-enhanced queries (default: openai/gpt-4.1-mini)

Available Tools

defillama_get_chains
order:string_userQuery:string

Description

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_data
protocol:stringsortCondition:stringorder:string_userQuery:string

Description

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_tvl
chain:string_userQuery:string

Description

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_data
excludeTotalDataChart:booleanexcludeTotalDataChartBreakdown:booleanprotocol:stringchain:stringsortCondition:stringorder:string_userQuery:string

Description

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_revenue
excludeTotalDataChart:booleanexcludeTotalDataChartBreakdown:booleandataType:stringchain:stringprotocol:stringsortCondition:stringorder:string_userQuery:string

Description

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_stablecoin
includePrices:boolean_userQuery:string

Description

Fetches stablecoin data including circulation and price information. Returns top 20 stablecoins

defillama_get_stablecoin_chains
_userQuery:string

Description

Fetches stablecoin data by chains. Returns last 3 chains with market cap data

defillama_get_stablecoin_charts
stablecoin:anychain:string_userQuery:string

Description

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

Description

Fetches historical stablecoin price data. Returns last 3 data points

defillama_get_prices_current_coins
coins:stringsearchWidth:any_userQuery:string

Description

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_coins
coins:string_userQuery:string

Description

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_historical
coins:anysearchWidth:any_userQuery:string

Description

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_contract
coins:stringtimestamp:anysearchWidth:any_userQuery:string

Description

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_coins
coins:stringtimestamp:anyperiod:stringlookForward:boolean_userQuery:string

Description

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_coins
coins:stringstart:anyend:anyspan:integerperiod:stringsearchWidth:any_userQuery:string

Description

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_data
sortCondition:stringorder:stringlimit:integer_userQuery:string

Description

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_data
pool:string_userQuery:string

Description

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_data
dataType:stringprotocol:stringchain:stringsortCondition:stringorder:stringexcludeTotalDataChart:booleanexcludeTotalDataChartBreakdown:boolean_userQuery:string

Description

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_timestamp
chain:stringtimestamp:any_userQuery:string

Description

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);

Further Resources