This project implements a Model Context Protocol (MCP) server to interact with the DefiLlama API. It allows MCP-compatible clients (like AI assistants, IDE extensions, or custom applications) to access DeFi data including TVL metrics, DEX volumes, protocol statistics, stablecoin data, token prices, yield farming pools, and more.
This server is built using TypeScript and fastmcp.
The server exposes the following tools that MCP clients can utilize:
defillama_get_chains: Fetch blockchain chains ranked by Total Value Locked (TVL).- Parameters:
order(asc/desc)
- Parameters:
defillama_get_protocol_data: Fetch TVL data for DeFi protocols with auto-resolution of protocol names.- Parameters:
protocol(string, optional),sortCondition,order
- Parameters:
defillama_get_historical_chain_tvl: Fetch historical TVL data for blockchain chains over time.- Parameters:
chain(string, optional)
- Parameters:
defillama_get_dexs_data: Fetch DEX trading volume data and metrics.- Parameters:
protocol(optional),chain(optional),sortCondition,order,excludeTotalDataChart,excludeTotalDataChartBreakdown
- Parameters:
defillama_get_fees_and_revenue: Fetch fees and revenue metrics for DeFi protocols.- Parameters:
dataType,chain(optional),protocol(optional),sortCondition,order,excludeTotalDataChart,excludeTotalDataChartBreakdown
- Parameters:
defillama_get_stablecoin: Fetch stablecoin data including circulation and price information.- Parameters:
includePrices(boolean, optional)
- Parameters:
defillama_get_stablecoin_chains: Fetch stablecoin data by chains.defillama_get_stablecoin_charts: Fetch historical market cap charts for stablecoins.- Parameters:
stablecoin(number/string, optional),chain(string, optional)
- Parameters:
defillama_get_stablecoin_prices: Fetch historical stablecoin price data.
defillama_get_prices_current_coins: Fetch current token prices.- Parameters:
coins(string),searchWidth(string/number)
- Parameters:
defillama_get_prices_first_coins: Fetch first recorded historical prices for tokens.- Parameters:
coins(string)
- Parameters:
defillama_get_batch_historical: Fetch historical price data for multiple cryptocurrencies at specific timestamps.- Parameters:
coins(string/object),searchWidth(optional)
- Parameters:
defillama_get_historical_prices_by_contract: Fetch historical prices for tokens at specific timestamps.- Parameters:
coins(string),timestamp(number/string),searchWidth(optional)
- Parameters:
defillama_get_percentage_coins: Fetch percentage price change for tokens over time.- Parameters:
coins(string),timestamp(optional),period(string),lookForward(boolean)
- Parameters:
defillama_get_chart_coins: Fetch historical price chart data for tokens.- Parameters:
coins(string),start(optional),end(optional),span(optional),period(optional),searchWidth(optional)
- Parameters:
defillama_get_latest_pool_data: Fetch current yield farming pool data including APY rates and TVL.- Parameters:
sortCondition,order,limit
- Parameters:
defillama_get_historical_pool_data: Fetch historical APY and TVL data for a specific pool.- Parameters:
pool(string)
- Parameters:
defillama_get_options_data: Fetch options protocol data including trading volume and premium metrics.- Parameters:
dataType,protocol(optional),chain(optional),sortCondition,order,excludeTotalDataChart,excludeTotalDataChartBreakdown
- Parameters:
defillama_get_blockchain_timestamp: Fetch blockchain block information at a specific timestamp.- Parameters:
chain(string),timestamp(number/string)
- Parameters:
- Node.js (v18 or newer recommended)
- pnpm (See https://pnpm.io/installation)
There are a few ways to use defillama-mcp:
1. Using pnpm dlx (Recommended for most MCP client setups):
You can run the server directly using pnpm dlx without needing a global installation. This is often the easiest way to integrate with MCP clients. See the "Running the Server with an MCP Client" section for examples.
(pnpm dlx is pnpm's equivalent of npx)
2. Global Installation from npm (via pnpm):
Install the package globally to make the defillama-mcp command available system-wide:
pnpm add -g @iqai/defillama-mcp3. Building from Source (for development or custom modifications):
-
Clone the repository:
git clone https://github.com/IQAIcom/defillama-mcp.git cd defillama-mcp -
Install dependencies:
pnpm install
-
Build the server: This compiles the TypeScript code to JavaScript in the
distdirectory.pnpm run build
The
preparescript also runspnpm run build, so dependencies are built upon installation if you clone and runpnpm install.
This MCP server can be configured with environment variables set by the MCP client that runs it. These are typically configured in the client's MCP server definition (e.g., in a mcp.json file for Cursor, or similar for other clients).
All environment variables are optional, but you may want to configure one of the following for API access:
-
Direct DefiLlama API Access (Recommended for most users):
DEFILLAMA_API_KEY: Your DefiLlama API key (get one at https://defillama.com)- If not provided, the server will make unauthenticated requests to DefiLlama (subject to rate limits)
-
IQ Gateway (For advanced caching and monitoring):
IQ_GATEWAY_URL: Custom IQ Gateway URL for enhanced resolution capabilitiesIQ_GATEWAY_KEY: API key for IQ Gateway access- This option is primarily for IQAI internal use but available for users with their own gateway infrastructure
OPENROUTER_API_KEY: API key for OpenRouter LLM integration for enhanced entity resolutionLLM_MODEL: LLM model to use for entity resolution (default:openai/gpt-4.1-mini)GOOGLE_GENERATIVE_AI_API_KEY: Google Generative AI API key for alternative LLM integration
MCP clients (like AI assistants, IDE extensions, etc.) will run this server as a background process. You need to configure the client to tell it how to start your server.
Below are example configuration snippets that an MCP client might use (e.g., in a mcp_servers.json or similar configuration file). These examples show how to run the server using the published npm package via pnpm dlx.
Basic Configuration (Recommended for most users):
{
"mcpServers": {
"defillama-mcp-server": {
"command": "pnpm",
"args": [
"dlx",
"@iqai/defillama-mcp"
],
"env": {
"DEFILLAMA_API_KEY": "your_defillama_api_key_here"
}
}
}
}Minimal Configuration (No API key - uses unauthenticated requests):
{
"mcpServers": {
"defillama-mcp-server": {
"command": "pnpm",
"args": [
"dlx",
"@iqai/defillama-mcp"
],
"env": {}
}
}
}Advanced Configuration (With IQ Gateway):
{
"mcpServers": {
"defillama-mcp-server": {
"command": "pnpm",
"args": [
"dlx",
"@iqai/defillama-mcp"
],
"env": {
"IQ_GATEWAY_URL": "your_iq_gateway_url",
"IQ_GATEWAY_KEY": "your_iq_gateway_key",
"OPENROUTER_API_KEY": "your_openrouter_api_key_if_needed",
"LLM_MODEL": "openai/gpt-4.1-mini",
"GOOGLE_GENERATIVE_AI_API_KEY": "your_google_api_key_if_needed"
}
}
}
}Alternative if Globally Installed:
If you have installed defillama-mcp globally (pnpm add -g @iqai/defillama-mcp), you can simplify the command and args:
{
"mcpServers": {
"defillama-mcp-server": {
"command": "defillama-mcp",
"args": [],
"env": {
"DEFILLAMA_API_KEY": "your_defillama_api_key_here"
}
}
}
}command: The executable to run.- For
pnpm dlx:"pnpm"(with"dlx"as the first arg) - For global install:
"defillama-mcp"
- For
args: An array of arguments to pass to the command.- For
pnpm dlx:["dlx", "@iqai/defillama-mcp"] - For global install:
[]
- For
env: An object containing environment variables to be set when the server process starts. All environment variables are optional.
pnpm run watch– compile on changepnpm run format– format with Biomepnpm run lint– lint with Biomepnpm changeset– create a release note for the next publishpnpm version-packages– apply pending changesets and bump package versionspnpm release– build and publish using the accumulated changesets
Many tools support automatic resolution of human-friendly names to API-compatible identifiers:
- Protocols: Pass names like 'Uniswap', 'Aave', 'Lido' directly
- Chains: Use names like 'Ethereum', 'BSC', 'Polygon', 'Arbitrum'
- Stablecoins: Use names like 'USDC', 'Tether', 'DAI'
The server uses AI-powered entity resolution to match common variations and names to correct API identifiers.