exchangeAssets
Retrieve detailed asset and token holdings of an exchange using CoinMarketCap MCP's API. Ideal for tracking cryptocurrency exchange inventories and managing blockchain data.
Instructions
Returns the assets/token holdings of an exchange.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | No | ||
| slug | No |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"id": {
"type": "string"
},
"slug": {
"type": "string"
}
},
"type": "object"
}
Implementation Reference
- index.js:445-450 (handler)Inline handler function for the 'exchangeAssets' tool. It uses handleEndpoint to wrap a call to makeApiRequest on the CoinMarketCap '/v1/exchange/assets' endpoint specific to the tool, followed by formatting the response.async (params) => { return handleEndpoint(async () => { const data = await makeApiRequest(apiKey, '/v1/exchange/assets', params) return formatResponse(data) }) }
- index.js:441-444 (schema)Zod input schema defining optional 'id' or 'slug' parameters for specifying the exchange.{ id: z.string().optional(), slug: z.string().optional() },
- index.js:439-451 (registration)Registration of the 'exchangeAssets' MCP tool using server.tool(), including description, Zod schema, and inline handler function.server.tool("exchangeAssets", "Returns the assets/token holdings of an exchange.", { id: z.string().optional(), slug: z.string().optional() }, async (params) => { return handleEndpoint(async () => { const data = await makeApiRequest(apiKey, '/v1/exchange/assets', params) return formatResponse(data) }) } )
- index.js:50-73 (helper)Shared helper function that constructs and executes the HTTP request to CoinMarketCap Pro API endpoints, used by all tools including exchangeAssets.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)Shared wrapper helper for handling API calls and errors, used in the exchangeAssets handler.async function handleEndpoint(apiCall) { try { return await apiCall() } catch (error) { return formatErrorResponse(error.message, error.status || 403) } }