Skip to main content
Glama
Panth1823

Formula1 MCP Server

auth.ts1.19 kB
/** * Authentication middleware - API key validation */ import { Request, Response, NextFunction } from 'express'; import { config } from '../config/index.js'; import { logger } from '../utils/logger.js'; import { RequestWithId } from './request-id.js'; /** * API key authentication middleware */ export function authMiddleware( req: RequestWithId, res: Response, next: NextFunction ): Response | void { // Skip auth if not required if (!config.apiKeyRequired) { return next(); } // Get API key from header const apiKey = req.headers['x-api-key'] as string; if (!apiKey) { logger.warn('Missing API key', { requestId: req.requestId }); return res.status(401).json({ error: 'Unauthorized', message: 'API key is required', requestId: req.requestId, }); } // Validate API key if (!config.apiKeys.includes(apiKey)) { logger.warn('Invalid API key', { requestId: req.requestId }); return res.status(403).json({ error: 'Forbidden', message: 'Invalid API key', requestId: req.requestId, }); } // Attach user context (could extract from API key) (req as any).apiKey = apiKey; next(); }

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

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