Skip to main content
Glama

globalMetricsLatest

Retrieve current global cryptocurrency market data, including market cap, trading volume, and dominance stats, directly via CoinMarketCap API for informed crypto analysis.

Instructions

Returns the latest global cryptocurrency market metrics.

Input Schema

NameRequiredDescriptionDefault
convertNo
convert_idNo

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "convert": { "type": "string" }, "convert_id": { "type": "string" } }, "type": "object" }

Implementation Reference

  • index.js:488-500 (registration)
    Registration of the globalMetricsLatest tool using server.tool, including description, input schema, and inline handler function.
    server.tool("globalMetricsLatest", "Returns the latest global cryptocurrency market metrics.", { convert: z.string().optional(), convert_id: z.string().optional() }, async (params) => { return handleEndpoint(async () => { const data = await makeApiRequest(apiKey, '/v1/global-metrics/quotes/latest', params) return formatResponse(data) }) } )
  • The handler function for globalMetricsLatest tool. It calls handleEndpoint which makes an API request to CoinMarketCap's /v1/global-metrics/quotes/latest endpoint with params and formats the response.
    async (params) => { return handleEndpoint(async () => { const data = await makeApiRequest(apiKey, '/v1/global-metrics/quotes/latest', params) return formatResponse(data) }) }
  • Zod schema defining optional input parameters 'convert' and 'convert_id' for currency conversion.
    { convert: z.string().optional(), convert_id: z.string().optional() },
  • Core helper function that constructs the CMC API URL, performs the fetch request with API key, and returns parsed JSON. Used by all tools including globalMetricsLatest.
    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() }
  • Helper function to format the API response into MCP content format (JSON string in text content).
    function formatResponse(data) { return { content: [{ type: "text", text: JSON.stringify(data) }] } }
  • Wrapper helper that executes the API call and catches errors, returning formatted error response if failed.
    async function handleEndpoint(apiCall) { try { return await apiCall() } catch (error) { return formatErrorResponse(error.message, error.status || 403) } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/shinzo-labs/coinmarketcap-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server