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.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.