getProtocolTVL
Retrieve Total Value Locked (TVL) data for DeFi protocols including chain distribution and 24h/7d change rates using DefiLlama data.
Instructions
DeFi 프로토콜의 TVL(Total Value Locked)을 조회합니다 (DefiLlama 기반, 체인별 분포, 24h/7d 변동률)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| protocol | Yes | 프로토콜 이름 (Aave, Uniswap 등) 또는 DefiLlama slug |
Implementation Reference
- src/tools/getProtocolTVL.ts:45-89 (handler)The handler function that executes the logic to fetch and format protocol TVL data using the DefiLlama API.
async function handler(args: z.infer<typeof inputSchema>): Promise<ToolResult<ProtocolTVLData>> { const { protocol } = args; const slug = resolveSlug(protocol); if (!slug) { return makeError(`Protocol '${protocol}' not found`, "PROTOCOL_NOT_FOUND"); } try { const data = await getProtocolData(slug); if (!data) { return makeError(`Protocol '${slug}' not found on DefiLlama`, "PROTOCOL_NOT_FOUND"); } // 체인별 TVL 분포 const chainBreakdown: ChainTvl[] = []; const totalTvl = data.tvl || 0; for (const [chain, tvl] of Object.entries(data.chainTvls)) { // staking, borrowed 등 비-체인 카테고리 제외 if (chain.includes("-") || chain === "staking" || chain === "borrowed" || chain === "pool2" || chain === "vesting") continue; chainBreakdown.push({ chain, tvlUsd: tvl, percentage: totalTvl > 0 ? Math.round((tvl / totalTvl) * 10000) / 100 : 0, }); } // TVL 내림차순 정렬 chainBreakdown.sort((a, b) => b.tvlUsd - a.tvlUsd); const result: ProtocolTVLData = { protocol: data.name, slug: data.slug, totalTvlUsd: totalTvl, change24h: data.change_1d, change7d: data.change_7d, chainBreakdown, }; return makeSuccess("ethereum", result, false); } catch (err) { const message = sanitizeError(err); return makeError(`Failed to fetch TVL: ${message}`, "API_ERROR"); } } - src/tools/getProtocolTVL.ts:24-26 (schema)Zod input schema defining the required 'protocol' argument.
const inputSchema = z.object({ protocol: z.string().describe("프로토콜 이름 (Aave, Uniswap 등) 또는 DefiLlama slug"), }); - src/tools/getProtocolTVL.ts:91-101 (registration)Registration function that exposes the getProtocolTVL tool to the MCP server.
export function register(server: McpServer) { server.tool( "getProtocolTVL", "DeFi 프로토콜의 TVL(Total Value Locked)을 조회합니다 (DefiLlama 기반, 체인별 분포, 24h/7d 변동률)", inputSchema.shape, async (args) => { const result = await handler(args as z.infer<typeof inputSchema>); return { content: [{ type: "text" as const, text: JSON.stringify(result, null, 2) }] }; }, ); }