Skip to main content
Glama

fetchTokenPriceBySymbol

Retrieve real-time cryptocurrency prices by providing token symbols like BTC or ETH. Simplify blockchain price queries with this Alchemy MCP Server tool.

Input Schema

NameRequiredDescriptionDefault
symbolsYesA list of blockchaintoken symbols to query. e.g. ["BTC", "ETH"]

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "symbols": { "description": "A list of blockchaintoken symbols to query. e.g. [\"BTC\", \"ETH\"]", "items": { "type": "string" }, "type": "array" } }, "required": [ "symbols" ], "type": "object" }

Implementation Reference

  • The main handler function that implements the logic for fetching token prices by symbol using the Alchemy Prices API client. It constructs the query parameters from the input symbols and makes a GET request to the /by-symbol endpoint.
    async 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; } },
  • index.ts:17-38 (registration)
    Registers the MCP tool 'fetchTokenPriceBySymbol' with input schema and an inline handler that delegates to alchemyApi.getTokenPriceBySymbol and formats the response.
    server.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 }; } });
  • TypeScript interface defining the input parameters for getTokenPriceBySymbol, matching the Zod schema used in registration.
    export interface TokenPriceBySymbol { symbols: string[]; }
  • Helper function that creates an Axios client configured for the Alchemy Prices API, used by the handler to make HTTP requests.
    export const createPricesClient = () => axios.create({ baseURL: `https://api.g.alchemy.com/prices/v1/${API_KEY}/tokens`, headers: { 'accept': 'application/json', 'content-type': 'application/json', 'x-alchemy-client-breadcrumb': BREADCRUMB_HEADER }, });

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/alchemyplatform/alchemy-mcp-server'

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