Skip to main content
Glama

queryPriceByRound

Retrieve historical price data for a specific trading pair and round ID using Chainlink's decentralized price feeds, enabling precise analysis and integration into autonomous systems.

Instructions

Queries the price for a given pair and round ID on a specified chain (placeholder due to historical data limitations)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Handler function for queryPriceByRound tool. Fetches price data from Chainlink feed contract using ethers.js. Note: Currently uses latestRoundData as a placeholder instead of getRoundData(roundId).
    async ({ roundId, pair, chain }) => { try { // Validate inputs const chainKey = chain.toLowerCase(); queryPriceSchema.parse({ roundId, pair, chain }); // Find feed by pair const feed = feedsData[chainKey].feeds.find((f) => f.name.toLowerCase() === pair.toLowerCase()); if (!feed) { throw new Error(`Pair ${pair} not found on chain ${chain}`); } // Initialize provider and contract const provider = new ethers.JsonRpcProvider(`${feedsData[chainKey].baseUrl}/${process.env.INFURA_API_KEY}`); const priceFeedContract = new ethers.Contract(feed.proxyAddress, priceFeedAbi, provider); // Note: getRoundData may not be supported for historical rounds const decimals = await priceFeedContract.decimals(); const roundData = await priceFeedContract.latestRoundData(); // Placeholder const price = ethers.formatUnits(roundData.answer, decimals); const timestamp = Number(roundData.updatedAt) * 1000; return { content: [{ type: 'text', text: JSON.stringify({ chain, pair, price: Number(price), decimals: Number(decimals), roundId, timestamp: new Date(timestamp).toISOString(), proxyAddress: feed.proxyAddress, feedCategory: feed.feedCategory }, null, 2) }] }; } catch (error) { return { content: [{ type: 'text', text: `Error: ${error.message}` }], isError: true }; } }
  • Zod input schema for queryPriceByRound tool defining parameters: roundId, pair, chain with validation.
    const queryPriceSchema = z.object({ roundId: z.string().regex(/^\d+$/, 'Round ID must be a number').describe('The round ID for the price data'), pair: z.string().describe('The price feed pair, e.g., FIL/ETH or FDUSD/USD'), chain: z.string().refine((val) => feedsData[val.toLowerCase()], { message: 'Unsupported chain' }).describe('The blockchain network, e.g., ethereum or base') });
  • index.js:103-155 (registration)
    Registers the 'queryPriceByRound' tool with MCP server using server.tool method, providing name, description, schema, and handler function.
    server.tool( 'queryPriceByRound', 'Queries the price for a given pair and round ID on a specified chain (placeholder due to historical data limitations)', queryPriceSchema, async ({ roundId, pair, chain }) => { try { // Validate inputs const chainKey = chain.toLowerCase(); queryPriceSchema.parse({ roundId, pair, chain }); // Find feed by pair const feed = feedsData[chainKey].feeds.find((f) => f.name.toLowerCase() === pair.toLowerCase()); if (!feed) { throw new Error(`Pair ${pair} not found on chain ${chain}`); } // Initialize provider and contract const provider = new ethers.JsonRpcProvider(`${feedsData[chainKey].baseUrl}/${process.env.INFURA_API_KEY}`); const priceFeedContract = new ethers.Contract(feed.proxyAddress, priceFeedAbi, provider); // Note: getRoundData may not be supported for historical rounds const decimals = await priceFeedContract.decimals(); const roundData = await priceFeedContract.latestRoundData(); // Placeholder const price = ethers.formatUnits(roundData.answer, decimals); const timestamp = Number(roundData.updatedAt) * 1000; return { content: [{ type: 'text', text: JSON.stringify({ chain, pair, price: Number(price), decimals: Number(decimals), roundId, timestamp: new Date(timestamp).toISOString(), proxyAddress: feed.proxyAddress, feedCategory: feed.feedCategory }, null, 2) }] }; } catch (error) { return { content: [{ type: 'text', text: `Error: ${error.message}` }], isError: true }; } } );

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/kukapay/chainlink-feeds-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server