cryptoCategories
Retrieves details of cryptocurrency categories listed on CoinMarketCap, filterable by ID, slug, or symbol.
Instructions
Returns information about all coin categories available on CoinMarketCap.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "cryptoCategories"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| start | No | ||
| limit | No | ||
| id | No | ||
| slug | No | ||
| symbol | No |
Implementation Reference
- index.js:122-137 (registration)Registration of the 'cryptoCategories' tool via server.tool() with schema definition and async handler.
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 for cryptoCategories tool using Zod: optional start (number), limit (number), id (string), slug (string), symbol (string).
{ 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)Handler function that calls the CoinMarketCap API endpoint /v1/cryptocurrency/categories with the provided parameters and formats the response.
async (params) => { return handleEndpoint(async () => { const data = await makeApiRequest(apiKey, '/v1/cryptocurrency/categories', params) return formatResponse(data) }) } - index.js:40-47 (helper)makeApiRequestWithErrorHandling - helper used as wrapper for API calls with error formatting.
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)makeApiRequest - core helper that constructs the URL, calls the CoinMarketCap API with the API key, and returns the JSON response.
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() }