priceConversion
Convert an amount of cryptocurrency or fiat currency to one or more different currencies using current market rates.
Instructions
Convert an amount of one cryptocurrency or fiat currency into one or more different currencies.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| amount | Yes | ||
| id | No | ||
| symbol | No | ||
| time | No | ||
| convert | No | ||
| convert_id | No |
Implementation Reference
- index.js:588-604 (registration)Tool registration for 'priceConversion' on the MCP server. Defines the tool name, description, Zod schema for inputs (amount required; id, symbol, time, convert, convert_id optional), and the handler that calls the CoinMarketCap API.
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:598-603 (handler)The handler function for priceConversion. It wraps the API call to '/v2/tools/price-conversion' via makeApiRequest, then formats the response.
async (params) => { return handleEndpoint(async () => { const data = await makeApiRequest(apiKey, '/v2/tools/price-conversion', params) return formatResponse(data) }) } - index.js:590-597 (schema)Input schema for priceConversion using Zod: amount (number, required), id, symbol, time, convert, convert_id (all optional strings).
{ 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:50-73 (helper)The makeApiRequest helper that constructs and executes the HTTP GET request to the CoinMarketCap API.
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() } - index.js:82-88 (helper)The handleEndpoint wrapper that catches errors and formats error responses.
async function handleEndpoint(apiCall) { try { return await apiCall() } catch (error) { return formatErrorResponse(error.message, error.status || 403) } }