fearAndGreedLatest
Retrieves the current Crypto Fear and Greed Index value to assess market sentiment.
Instructions
Returns the latest CMC Crypto Fear and Greed Index value.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- index.js:532-541 (registration)Registration of the 'fearAndGreedLatest' tool via server.tool(). No input schema (empty object). The callback is the handler.
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)Handler callback for the fearAndGreedLatest tool. Makes an API call to /v3/fear-and-greed/latest and formats the response.
async () => { return handleEndpoint(async () => { const data = await makeApiRequest(apiKey, '/v3/fear-and-greed/latest') return formatResponse(data) }) } - index.js:30-37 (helper)Helper function that wraps API response data in the MCP content format.
function formatResponse(data) { return { content: [{ type: "text", text: JSON.stringify(data) }] } } - index.js:82-88 (helper)Helper wrapper that catches errors from endpoint handlers and returns formatted error responses.
async function handleEndpoint(apiCall) { try { return await apiCall() } catch (error) { return formatErrorResponse(error.message, error.status || 403) } } - index.js:50-73 (helper)Helper function that makes the HTTP GET request to the CoinMarketCap Pro API with the provided API key.
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() }