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
| Name | Required | Description | Default |
|---|---|---|---|
| amount | Yes | ||
| convert | No | ||
| convert_id | No | ||
| id | No | ||
| symbol | No | ||
| time | No |
Implementation Reference
- index.js:598-603 (handler)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) }) }
- index.js:591-597 (schema)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) }) } )
- index.js:50-73 (helper)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() }