get_cardano_price
Retrieve aggregated price for Cardano native tokens from DEX liquidity pools using ADA bridge pricing.
Instructions
Get aggregated price for a Cardano native token from DEX liquidity pools (TOKEN/USDT via ADA bridge)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | Cardano token symbol (INDY, SNEK, MIN, NIGHT) |
Implementation Reference
- src/tools/cardano.ts:114-196 (handler)Main implementation of get_cardano_price tool - registers the tool with MCP server and contains the handler logic that fetches ADA price from multiple CEX sources (Binance, MEXC, Coingecko), retrieves Cardano DEX liquidity pools from Iris API, calculates token price weighted by TVL, and returns aggregated USDT price with confidence score.
export function registerCardanoTools(server: McpServer): void { server.tool( 'get_cardano_price', 'Get aggregated price for a Cardano native token from DEX liquidity pools (TOKEN/USDT via ADA bridge)', { symbol: z.string().describe('Cardano token symbol (INDY, SNEK, MIN, NIGHT)'), }, async ({ symbol }) => { const upper = symbol.toUpperCase(); const token = SUPPORTED_TOKENS[upper]; if (!token) { throw new Error( `Unsupported token: ${symbol}. Supported: ${Object.keys(SUPPORTED_TOKENS).join(', ')}` ); } const [adaPrice, allPools] = await Promise.all([fetchADAUSDT(), fetchIrisPools()]); const tokenPools = allPools .filter((p: any) => matchesToken(p, token.policyId)) .filter((p: any) => (p.state?.tvl || 0) >= token.minLiquidity) .sort((a: any, b: any) => (b.state?.tvl || 0) - (a.state?.tvl || 0)) .slice(0, 3); if (tokenPools.length === 0) { throw new Error(`No liquidity pools found for ${upper} above minimum TVL threshold`); } const identifiers = tokenPools.map((p: any) => p.identifier).filter(Boolean); let tokenAdaPrice: number; if (identifiers.length > 0) { const prices = await fetchIrisPrices(identifiers); if (prices.length > 0) { const totalTvl = tokenPools.reduce((sum: number, p: any) => sum + (p.state?.tvl || 0), 0); tokenAdaPrice = tokenPools.reduce((sum: number, p: any, i: number) => { const weight = (p.state?.tvl || 0) / totalTvl; return sum + (prices[i] || 0) * weight; }, 0); } else { tokenAdaPrice = tokenPools.reduce((sum: number, p: any) => sum + (p.state?.price || 0), 0) / tokenPools.length; } } else { tokenAdaPrice = tokenPools.reduce((sum: number, p: any) => sum + (p.state?.price || 0), 0) / tokenPools.length; } const tokenUsdtPrice = tokenAdaPrice * adaPrice.price; const confidence = Math.min(tokenPools.length / 3, 1); return { content: [ { type: 'text' as const, text: JSON.stringify( { symbol: `${upper}/USDT`, price: tokenUsdtPrice, tokenAdaPrice, adaUsdtPrice: adaPrice.price, confidence, poolsUsed: tokenPools.length, sources: { ada: adaPrice.sources, pools: tokenPools.map((p: any) => ({ dex: p.dex || 'unknown', tvl: p.state?.tvl, })), }, timestamp: new Date().toISOString(), }, null, 2 ), }, ], }; } ); - src/tools/cardano.ts:119-120 (schema)Input schema for get_cardano_price tool - accepts a 'symbol' parameter (string) describing the Cardano token symbol (INDY, SNEK, MIN, NIGHT) using Zod validation.
symbol: z.string().describe('Cardano token symbol (INDY, SNEK, MIN, NIGHT)'), }, - src/tools/index.ts:8-14 (registration)Registration point where registerCardanoTools is called within the main registerTools function, which is invoked during server initialization to register all tools including get_cardano_price.
export function registerTools(server: McpServer): void { registerMarketDataTools(server); registerAccountTools(server); registerTradingTools(server); registerCardanoTools(server); registerStrategyTools(server); } - src/tools/cardano.ts:50-77 (helper)Helper function fetchADAUSDT that aggregates ADA/USDT prices from multiple centralized exchange endpoints (Binance, MEXC, Coingecko) with 5-second timeout, filtering valid prices and returning average with source list.
async function fetchADAUSDT(): Promise<{ price: number; sources: string[] }> { const prices: number[] = []; const sources: string[] = []; for (const endpoint of CEX_ENDPOINTS) { try { const resp = await fetch(endpoint.url, { signal: AbortSignal.timeout(5000) }); if (!resp.ok) continue; const data = await resp.json(); const price = endpoint.parse(data); if (price > 0 && !isNaN(price)) { prices.push(price); sources.push(endpoint.name); } } catch { // skip failed endpoint } } if (prices.length === 0) { throw new Error('Failed to fetch ADA/USDT price from any CEX source'); } return { price: prices.reduce((sum, p) => sum + p, 0) / prices.length, sources, }; } - src/tools/cardano.ts:79-89 (helper)Helper function fetchIrisPools that retrieves Cardano DEX liquidity pools from the Indigo Protocol Iris API with 10-second timeout and User-Agent header.
async function fetchIrisPools(): Promise<any[]> { const resp = await fetch(`${IRIS_BASE_URL}/api/liquidity-pools`, { headers: { 'User-Agent': 'OpenMM-MCP-Agent/1.0' }, signal: AbortSignal.timeout(10000), }); if (!resp.ok) { throw new Error(`Iris API error: ${resp.status}`); } const data = await resp.json(); return data?.data || data || []; }