keyInfo
Retrieve API key details and usage statistics to monitor access and optimize performance for CoinMarketCap API integration.
Instructions
Returns API key details and usage stats.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- index.js:610-615 (handler)The handler function for the 'keyInfo' tool. It calls the CoinMarketCap '/v1/key/info' endpoint using helper functions to retrieve API key details and usage stats, then formats the response.async () => { return handleEndpoint(async () => { const data = await makeApiRequest(apiKey, '/v1/key/info') return formatResponse(data) }) }
- index.js:609-609 (schema)Input schema for the 'keyInfo' tool, which requires no parameters.{},
- index.js:607-616 (registration)Registration of the 'keyInfo' tool using McpServer.tool(), available under Basic subscription level.server.tool("keyInfo", "Returns API key details and usage stats.", {}, async () => { return handleEndpoint(async () => { const data = await makeApiRequest(apiKey, '/v1/key/info') return formatResponse(data) }) } )
- index.js:82-88 (helper)Helper function used by the keyInfo handler to wrap API calls with try-catch error handling.async function handleEndpoint(apiCall) { try { return await apiCall() } catch (error) { return formatErrorResponse(error.message, error.status || 403) } }
- index.js:50-73 (helper)Core helper function that makes authenticated HTTP requests to the CoinMarketCap API, used by the keyInfo 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() }