fearAndGreedLatest
Track the Crypto Fear and Greed Index value to analyze market sentiment and make informed cryptocurrency investment decisions using CoinMarketCap MCP.
Instructions
Returns the latest CMC Crypto Fear and Greed Index value.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- index.js:532-541 (registration)Registration of the 'fearAndGreedLatest' tool. Includes tool description, empty input schema (no parameters), and inline asynchronous handler function that uses handleEndpoint to call the CoinMarketCap '/v3/fear-and-greed/latest' API endpoint via makeApiRequest, then formats the response.server.tool("fearAndGreedLatest", "Returns the latest CMC Crypto Fear and Greed Index value.", {}, async () => { return handleEndpoint(async () => { const data = await makeApiRequest(apiKey, '/v3/fear-and-greed/latest') return formatResponse(data) }) } )
- index.js:535-540 (handler)Inline handler function for fearAndGreedLatest tool. Executes the tool logic by making an API request to CoinMarketCap's fear-and-greed/latest endpoint.async () => { return handleEndpoint(async () => { const data = await makeApiRequest(apiKey, '/v3/fear-and-greed/latest') return formatResponse(data) }) }
- index.js:534-534 (schema)Input schema for fearAndGreedLatest: empty object, indicating no input parameters required.{},
- index.js:82-88 (helper)Helper function used by the handler to wrap API calls with 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 GET requests to CoinMarketCap API endpoints, used by the tool 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() }