Skip to main content
Glama

priceConversion

Convert cryptocurrency or fiat amounts into multiple currencies using CoinMarketCap’s API. Input an amount and specify target currencies for accurate conversion results.

Instructions

Convert an amount of one cryptocurrency or fiat currency into one or more different currencies.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
amountYes
convertNo
convert_idNo
idNo
symbolNo
timeNo

Implementation Reference

  • The handler function for the 'priceConversion' tool. It calls the shared makeApiRequest helper to fetch data from CoinMarketCap's '/v2/tools/price-conversion' endpoint, formats the response, and handles errors via handleEndpoint.
    async (params) => { return handleEndpoint(async () => { const data = await makeApiRequest(apiKey, '/v2/tools/price-conversion', params) return formatResponse(data) }) }
  • Zod input schema for the priceConversion tool defining the expected parameters: amount (required number), optional id, symbol, time, convert, convert_id.
    amount: z.number(), id: z.string().optional(), symbol: z.string().optional(), time: z.string().optional(), convert: z.string().optional(), convert_id: z.string().optional() },
  • index.js:588-604 (registration)
    Registration of the priceConversion tool using server.tool, including description, input schema, and inline handler function. Available under Basic subscription level.
    server.tool("priceConversion", "Convert an amount of one cryptocurrency or fiat currency into one or more different currencies.", { amount: z.number(), id: z.string().optional(), symbol: z.string().optional(), time: z.string().optional(), convert: z.string().optional(), convert_id: z.string().optional() }, async (params) => { return handleEndpoint(async () => { const data = await makeApiRequest(apiKey, '/v2/tools/price-conversion', params) return formatResponse(data) }) } )
  • Shared helper function makeApiRequest that constructs and performs the HTTP GET request to CoinMarketCap API endpoints using the provided apiKey, endpoint, and params.
    async function makeApiRequest(apiKey, endpoint, params = {}) { const queryParams = new URLSearchParams() Object.entries(params).forEach(([key, value]) => { if (value !== undefined) { queryParams.append(key, value.toString()) } }) const url = `https://pro-api.coinmarketcap.com${endpoint}${queryParams.toString() ? `?${queryParams.toString()}` : ''}` const response = await fetch(url, { method: 'GET', headers: { 'Accept': 'application/json', 'X-CMC_PRO_API_KEY': apiKey, } }) if (!response.ok) { throw new Error(`Error fetching data from CoinMarketCap: ${response.statusText}`) } return await response.json() }

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/shinzo-labs/coinmarketcap-mcp'

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