Skip to main content
Glama

Formula1 MCP Server

MIT License
11
  • Apple
  • Linux
live-timing.ts1.57 kB
import axios from "axios"; import { McpError, ErrorCode } from "@modelcontextprotocol/sdk"; export class F1DataService { private static instance: F1DataService; private cache: Map<string, { data: any; expiry: number }> = new Map(); private constructor() {} public static getInstance(): F1DataService { if (!F1DataService.instance) { F1DataService.instance = new F1DataService(); } return F1DataService.instance; } private getCachedData<T>(key: string): T | null { const cachedItem = this.cache.get(key); if (cachedItem && cachedItem.expiry > Date.now()) { return cachedItem.data; } return null; } private setCachedData<T>(key: string, data: T, ttl?: number): void { const expiry = ttl ? Date.now() + ttl * 1000 : Infinity; this.cache.set(key, { data, expiry }); } private async fetchWithErrorHandling<T>( url: string, errorMessage: string, useCache: boolean = true, cacheTTL?: number ): Promise<T> { const cacheKey = url; if (useCache) { const cachedData = this.getCachedData<T>(cacheKey); if (cachedData) { return cachedData; } } try { const response = await axios.get<T>(url); if (useCache) { this.setCachedData(cacheKey, response.data, cacheTTL); } return response.data; } catch (error: any) { console.error(`${errorMessage}:`, error); throw new McpError( ErrorCode.InternalError, `${errorMessage}: ${error.response?.status || "Unknown error"}` ); } } }

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/Panth1823/formula1-mcp'

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