cryptoCurrencyMap
Retrieve a mapping of all cryptocurrencies to their unique CoinMarketCap IDs. Filter by status, start, limit, sort, symbol, or auxiliary fields.
Instructions
Returns a mapping of all cryptocurrencies to unique CoinMarketCap IDs.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| listing_status | No | ||
| start | No | ||
| limit | No | ||
| sort | No | ||
| symbol | No | ||
| aux | No |
Implementation Reference
- index.js:158-180 (registration)Registration of the 'cryptoCurrencyMap' tool on the MCP server with Zod schema for parameters.
server.tool("cryptoCurrencyMap", "Returns a mapping of all cryptocurrencies to unique CoinMarketCap IDs.", { listing_status: z.string().optional(), start: z.number().optional(), limit: z.number().optional(), sort: z.string().optional(), symbol: z.string().optional(), aux: z.string().optional() }, async ({ listing_status = 'active', start = 1, limit = 100, sort = 'id', symbol, aux }) => { return handleEndpoint(async () => { return await makeApiRequestWithErrorHandling(apiKey, '/v1/cryptocurrency/map', { listing_status, start, limit, sort, symbol, aux }) }) } ) - index.js:160-167 (schema)Zod schema defining input parameters: listing_status, start, limit, sort, symbol, aux.
{ listing_status: z.string().optional(), start: z.number().optional(), limit: z.number().optional(), sort: z.string().optional(), symbol: z.string().optional(), aux: z.string().optional() }, - index.js:168-179 (handler)Handler function that calls the CoinMarketCap /v1/cryptocurrency/map endpoint with default parameters (listing_status='active', start=1, limit=100, sort='id') and returns formatted response.
async ({ listing_status = 'active', start = 1, limit = 100, sort = 'id', symbol, aux }) => { return handleEndpoint(async () => { return await makeApiRequestWithErrorHandling(apiKey, '/v1/cryptocurrency/map', { listing_status, start, limit, sort, symbol, aux }) }) } - index.js:40-47 (helper)Wrapper that calls makeApiRequest and formats the response, with error handling.
async function makeApiRequestWithErrorHandling(apiKey, endpoint, params = {}) { try { const data = await makeApiRequest(apiKey, endpoint, params) return formatResponse(data) } catch (error) { return formatErrorResponse(`Error fetching data from CoinMarketCap: ${error.message}`, 500) } } - index.js:50-73 (helper)Core API request function that builds the URL, appends query params, and fetches from CoinMarketCap with the API key.
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() }