fetchTokenPriceBySymbol
Retrieve current cryptocurrency prices by providing token symbols like BTC or ETH. This tool queries blockchain token data through Alchemy's MCP Server.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbols | Yes | A list of blockchaintoken symbols to query. e.g. ["BTC", "ETH"] |
Implementation Reference
- index.ts:17-38 (registration)Registration of the fetchTokenPriceBySymbol tool, including Zod input schema and inline error-handling wrapper that delegates to alchemyApi.getTokenPriceBySymbolserver.tool('fetchTokenPriceBySymbol', { symbols: z.array(z.string()).describe('A list of blockchaintoken symbols to query. e.g. ["BTC", "ETH"]'), }, async (params) => { try { const result = await alchemyApi.getTokenPriceBySymbol(params); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], }; } catch (error) { if (error instanceof Error) { console.error('Error in getTokenPriceBySymbol:', error); return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true }; } return { content: [{ type: "text", text: 'Unknown error occurred' }], isError: true }; } });
- api/alchemyApi.ts:11-27 (handler)Core implementation of the token price fetching logic via Alchemy Prices API client, called by the tool handlerasync getTokenPriceBySymbol(params: TokenPriceBySymbol) { try { const client = createPricesClient(); const queryParams = new URLSearchParams(); params.symbols.forEach(symbol => { queryParams.append('symbols', symbol.toUpperCase()); }); const response = await client.get(`/by-symbol?${queryParams}`); return response.data; } catch (error) { console.error('Error fetching token prices:', error); throw error; } },
- types/types.d.ts:2-4 (schema)TypeScript interface defining the input shape for getTokenPriceBySymbol (matches the Zod schema)export interface TokenPriceBySymbol { symbols: string[]; }