Skip to main content
Glama

CoinStats MCP Server

Official

get-news

Retrieve cryptocurrency news articles with pagination and date filtering to stay informed about market developments and trends.

Instructions

Get news articles with pagination.

Input Schema

NameRequiredDescriptionDefault
fromNoStart date in ISO 8601 format
limitNoNumber of results per page
pageNoPage number
toNoEnd date in ISO 8601 format

Input Schema (JSON Schema)

{ "properties": { "from": { "description": "Start date in ISO 8601 format", "type": "string" }, "limit": { "default": 20, "description": "Number of results per page", "type": "number" }, "page": { "default": 1, "description": "Page number", "type": "number" }, "to": { "description": "End date in ISO 8601 format", "type": "string" } }, "type": "object" }

Implementation Reference

  • The universal API handler function that executes the HTTP request to the CoinStats /news endpoint for the get-news tool. Handles path parameters, query parameters, special cases, fetches data, and formats response for MCP.
    export async function universalApiHandler<T>( basePath: string, endpoint: string, method: string = 'GET', params: Record<string, any> = {}, body?: any ): Promise<{ content: Array<{ type: 'text'; text: string; isError?: boolean }>; }> { try { // Handle path parameters - replace {paramName} in endpoint with actual values let processedEndpoint = endpoint; let processedParams = { ...params }; // Find all path parameters in the endpoint (e.g., {coinId}, {id}, {type}) const pathParamMatches = endpoint.match(/\{([^}]+)\}/g); if (pathParamMatches) { for (const match of pathParamMatches) { const paramName = match.slice(1, -1); // Remove { and } if (processedParams[paramName] !== undefined) { // Replace the placeholder with the actual value processedEndpoint = processedEndpoint.replace(match, processedParams[paramName]); // Remove the parameter from query params since it's now part of the path delete processedParams[paramName]; } else { throw new Error(`Required path parameter '${paramName}' is missing`); } } } // MCP clients might not support '~' in parameter names, so we replace '-' with '~' specifically for the /coins endpoint before making the request. if (endpoint === '/coins') { processedParams = Object.entries(processedParams).reduce((acc, [key, value]) => { acc[key.replace(/-/g, '~')] = value; return acc; }, {} as Record<string, any>); } const url = `${basePath}${processedEndpoint}`; const data = await makeRequestCsApi<T>(url, method, processedParams, body); if (!data) { return { content: [{ type: 'text', text: 'Something went wrong', isError: true }], }; } return { content: [ { type: 'text', text: JSON.stringify(data), }, ], }; } catch (error) { return { content: [{ type: 'text', text: `Error: ${error}`, isError: true }], }; } }
  • The inline async handler function registered with MCP server.tool for 'get-news' (via loop). Dispatches non-local tools like get-news to universalApiHandler with endpoint '/news' and parameters.
    server.tool(config.name, config.description, config.parameters, async (params: Record<string, any>) => { // Handle local operations if (config.isLocal) { // Handle specific local tools if (config.name === 'save-share-token') { await saveToCache('shareToken', params.shareToken); return { content: [ { type: 'text', text: 'Share token saved successfully', }, ], }; } if (config.name === 'get-share-token') { const shareToken = await getFromCache('shareToken'); return { content: [ { type: 'text', text: shareToken ? shareToken : 'No share token found in cache', isError: !shareToken, }, ], }; } // Future local tools can be added here // Default response for unhandled local tools return { content: [ { type: 'text', text: 'Operation completed', }, ], }; } // Handle API operations const basePath = config.basePath || COINSTATS_API_BASE; const method = config.method || 'GET'; // Methods that typically have a request body const bodyMethods = ['POST', 'PUT', 'PATCH', 'DELETE']; // For GET/DELETE requests, all params go in the URL // For POST/PUT/PATCH, send params as the body if (bodyMethods.includes(method.toUpperCase())) { return universalApiHandler(basePath, config.endpoint, method, {}, params); } else { return universalApiHandler(basePath, config.endpoint, method, params); } });
  • Tool configuration object for 'get-news' defining name, description, endpoint, method, and Zod input schema (parameters). Used for registration and validation.
    { name: 'get-news', description: 'Get news articles with pagination.', endpoint: '/news', method: 'GET', parameters: { page: z.number().optional().describe('Page number').default(1), limit: z.number().optional().describe('Number of results per page').default(20), from: z.string().optional().describe('Start date in ISO 8601 format'), to: z.string().optional().describe('End date in ISO 8601 format'), }, },
  • registerTools function that iterates over allToolConfigs (including get-news) and calls server.tool to register each tool with MCP server.
    export function registerTools(server: McpServer, toolConfigs: ToolConfig<any>[]) { toolConfigs.forEach((config) => { server.tool(config.name, config.description, config.parameters, async (params: Record<string, any>) => { // Handle local operations if (config.isLocal) { // Handle specific local tools if (config.name === 'save-share-token') { await saveToCache('shareToken', params.shareToken); return { content: [ { type: 'text', text: 'Share token saved successfully', }, ], }; } if (config.name === 'get-share-token') { const shareToken = await getFromCache('shareToken'); return { content: [ { type: 'text', text: shareToken ? shareToken : 'No share token found in cache', isError: !shareToken, }, ], }; } // Future local tools can be added here // Default response for unhandled local tools return { content: [ { type: 'text', text: 'Operation completed', }, ], }; } // Handle API operations const basePath = config.basePath || COINSTATS_API_BASE; const method = config.method || 'GET'; // Methods that typically have a request body const bodyMethods = ['POST', 'PUT', 'PATCH', 'DELETE']; // For GET/DELETE requests, all params go in the URL // For POST/PUT/PATCH, send params as the body if (bodyMethods.includes(method.toUpperCase())) { return universalApiHandler(basePath, config.endpoint, method, {}, params); } else { return universalApiHandler(basePath, config.endpoint, method, params); } }); }); }
  • src/index.ts:17-18 (registration)
    Top-level call to registerTools(server, allToolConfigs) in the MCP server setup, which registers the 'get-news' tool.
    // Register all tools from configurations registerTools(server, allToolConfigs);

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/CoinStatsHQ/coinstats-mcp'

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