cryptoCategories
Retrieve detailed information about cryptocurrency categories, including IDs, slugs, and symbols, using CoinMarketCap's comprehensive API for market data analysis.
Instructions
Returns information about all coin categories available on CoinMarketCap.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | No | ||
| limit | No | ||
| slug | No | ||
| start | No | ||
| symbol | No |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"id": {
"type": "string"
},
"limit": {
"type": "number"
},
"slug": {
"type": "string"
},
"start": {
"type": "number"
},
"symbol": {
"type": "string"
}
},
"type": "object"
}
Implementation Reference
- index.js:122-137 (registration)Registration of the 'cryptoCategories' MCP tool. Includes the description, Zod input schema (start, limit, id, slug, symbol), and inline async handler function that calls the CoinMarketCap API endpoint '/v1/cryptocurrency/categories' using the makeApiRequest helper, wrapped in handleEndpoint for error handling, and formats the JSON response.server.tool("cryptoCategories", "Returns information about all coin categories available on CoinMarketCap.", { start: z.number().optional(), limit: z.number().optional(), id: z.string().optional(), slug: z.string().optional(), symbol: z.string().optional() }, async (params) => { return handleEndpoint(async () => { const data = await makeApiRequest(apiKey, '/v1/cryptocurrency/categories', params) return formatResponse(data) }) } )
- index.js:124-130 (schema)Input schema (Zod object) for the cryptoCategories tool defining optional parameters: start, limit, id, slug, symbol.{ start: z.number().optional(), limit: z.number().optional(), id: z.string().optional(), slug: z.string().optional(), symbol: z.string().optional() },
- index.js:131-136 (handler)Inline handler function for the cryptoCategories tool. It executes the API call to CoinMarketCap's categories endpoint using helpers handleEndpoint, makeApiRequest, and formatResponse.async (params) => { return handleEndpoint(async () => { const data = await makeApiRequest(apiKey, '/v1/cryptocurrency/categories', params) return formatResponse(data) }) }
- index.js:50-73 (helper)Helper function makeApiRequest that constructs the full URL with query params and makes authenticated GET request to CoinMarketCap API, used by the cryptoCategories handler.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)Wrapper helper handleEndpoint that executes the API call and catches errors, returning formatted error response via formatErrorResponse.async function handleEndpoint(apiCall) { try { return await apiCall() } catch (error) { return formatErrorResponse(error.message, error.status || 403) } }