fearAndGreedHistorical
Retrieve historical Crypto Fear and Greed Index values from CoinMarketCap to analyze market sentiment over time.
Instructions
Returns historical CMC Crypto Fear and Greed Index values.
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": "fearAndGreedHistorical"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| start | No | ||
| limit | No |
Implementation Reference
- index.js:544-556 (registration)Registration of the 'fearAndGreedHistorical' tool on the McpServer with schema and handler.
server.tool("fearAndGreedHistorical", "Returns historical CMC Crypto Fear and Greed Index values.", { start: z.number().min(1).optional(), limit: z.number().min(1).max(500).optional() }, async (params) => { return handleEndpoint(async () => { const data = await makeApiRequest(apiKey, '/v3/fear-and-greed/historical', params) return formatResponse(data) }) } ) - index.js:550-555 (handler)Handler function that executes the tool logic: calls the /v3/fear-and-greed/historical endpoint via makeApiRequest and formats the response.
async (params) => { return handleEndpoint(async () => { const data = await makeApiRequest(apiKey, '/v3/fear-and-greed/historical', params) return formatResponse(data) }) } - index.js:546-549 (schema)Input schema for the tool: optional 'start' (number, min 1) and 'limit' (number, min 1, max 500) parameters.
{ start: z.number().min(1).optional(), limit: z.number().min(1).max(500).optional() }, - index.js:50-73 (helper)Helper function 'makeApiRequest' that builds the URL and makes the GET request to the CoinMarketCap API with the given params.
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)Helper function 'handleEndpoint' that wraps the API call in try/catch for consistent error handling.
async function handleEndpoint(apiCall) { try { return await apiCall() } catch (error) { return formatErrorResponse(error.message, error.status || 403) } }