defi-yield-mcp
Enables querying DeFi yield pool data and risk signals from DefiLlama, including APY, TVL, exploit history, and a gate-then-score risk assessment for curated protocols.
README
defi-yield-mcp
An MCP server for querying DeFi yield pool data and (eventually) risk signals — built for anyone deciding where idle funds should earn yield, without having to manually cross-reference DefiLlama, protocol docs, and exploit trackers.
Why this exists
DefiLlama has the raw data but no MCP server exposing it in agent-friendly form with any risk framing layered on.
Setup
pip install -r requirements.txt
python server.py
Add to your MCP client config (e.g. Claude Desktop claude_desktop_config.json):
{
"mcpServers": {
"defi-yield": {
"command": "python",
"args": ["/absolute/path/to/server.py"]
}
}
}
No API key required — DefiLlama's public endpoints are used as-is.
Tools — implemented
| Tool | Description |
|---|---|
get_pool_apy |
Current APY/TVL for pools on a given protocol, optionally filtered by asset symbol and chain |
list_pools |
Filter/sort pools across all protocols by APY, TVL, chain, symbol |
compare_pools |
Side-by-side comparison of specific pools by DefiLlama pool id |
get_exploit_history |
Historical hack/exploit records, optionally filtered by protocol |
get_pool_risk_score |
Gated risk assessment (audit + liquidity gates, then yield/TVL stability score) — see methodology below |
get_protocol_audit_status |
Audit firm(s), count, launch date, bug bounty status, liquidity category — from the curated dataset |
get_pool_risk_score and get_protocol_audit_status are only populated for
protocols in CURATED_PROTOCOL_DATA in server.py (currently: aave-v3,
compound-v3, morpho-blue, curve-dex, makerdao). Anything else returns an
honest "not in dataset" response rather than a fabricated score.
Data sources
- DefiLlama Yields API (
yields.llama.fi/pools) — APY, TVL, pool metadata. Free, no key, refreshes ~hourly. Responses are cached in-process for 5 minutes to avoid redundant calls. - DefiLlama hacks dataset (
api.llama.fi/hacks) — historical exploit records.
Risk scoring methodology (implemented)
This is deliberately not a single blended score. For a payments protocol holding funds earmarked for payees, some failures shouldn't be averaged away by a good number elsewhere — so the design is gate-then-score:
Hard gates (fail either → pool is excluded, no score computed):
- Audit gate — protocol must have ≥ 2 audits from recognized firms and
be live ≥ 12 months (
MIN_AUDIT_COUNT,MIN_PROTOCOL_AGE_DAYSinserver.py). - Liquidity gate — protocol category must support instant withdrawal
(lending markets, savings-style primitives, stable AMMs — not locked farms),
and the specific pool's TVL must be ≥ 20x the assumed position size
(
MIN_TVL_DEPTH_MULTIPLE), so an exit doesn't move the market.
Secondary score (only computed if both gates pass):
- Yield stability — coefficient of variation of daily APY over the trailing 30 days, converted to a 0–100 score (lower variance → higher score).
- TVL stability — same calculation applied to daily TVL.
- These are averaged into a
composite_stability_score. Note this ranks steadiness, not size — a steady 4% outranks a volatile 9% by design.
The curated dataset and thresholds are plain module-level constants in
server.py, not hidden in a black box — adjust MIN_AUDIT_COUNT,
MIN_PROTOCOL_AGE_DAYS, or MIN_TVL_DEPTH_MULTIPLE to fit a different
risk appetite.
Extending the curated dataset
To add a protocol, add an entry to CURATED_PROTOCOL_DATA in server.py
with audits, audit_count, live_since, bug_bounty, category, and
instant_liquidity, sourced from the protocol's own docs/GitHub. There's no
public API for audit status across protocols, so this stays hand-maintained
by design — a fabricated automated score would be worse than an honest gap.
Testing
Offline (no network needed):
pip install "mcp[cli]" httpx
python test_offline.py
Runs all six tools against realistic mock fixtures (patched in place of the real HTTP calls) so you can see the gate-then-score logic execute end to end — including one fixture deliberately sized to fail the liquidity gate, and one protocol deliberately left out of the curated dataset, so you can see both failure paths behave correctly, not just the happy path.
Live (hits the real DefiLlama API):
pip install "mcp[cli]" httpx
python server.py
Then connect via an MCP client (see Setup above) and call the tools directly,
or add a small if __name__ == "__main__": block calling the async functions
with asyncio.run(...) the same way test_offline.py does, minus the
monkeypatch. Worth checking the live /pools and /chart/{pool} response
shapes against what's assumed in server.py the first time you run it —
those field names were reconstructed from documentation, not verified live.
Known limitations
_looks_lockedis a keyword heuristic, not a guarantee. It catches obvious cases (apoolMetaorsymbolcontaining "stake", "umbrella", "vault", "lock", etc. — added after live testing surfaced an Aave "Umbrella" staking pool passing the liquidity gate incorrectly) but a new locked product with unrelated naming could still slip through the protocol-levelinstant_liquidityflag. Treatgate_status: passedas a strong signal, not a certainty — check thepool_metafield in the response yourself for anything unfamiliar.- No risk scoring for protocols outside
CURATED_PROTOCOL_DATA— those correctly come backgate_status: unknownrather than a fabricated score. - Exploit history depends on DefiLlama's dataset being current; cross-check anything decision-relevant against the protocol's own disclosures.
- Not audited or battle-tested — this is a portfolio/reference project, not
a production risk tool. Don't make real allocation decisions off
get_pool_apyalone.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。