Skip to main content
Glama

1MCP Server

httpRequestLogger.ts1.54 kB
import logger from '@src/logger/logger.js'; import { sanitizeHeaders } from '@src/utils/validation/sanitization.js'; import { NextFunction, Request, Response } from 'express'; /** * HTTP request logging middleware that provides comprehensive request/response logging * * Features: * - Logs all HTTP requests with method, URL, headers, query, and body * - Tracks request duration for performance monitoring * - Sanitizes sensitive headers for security * - Unified logging format replacing manual route-level logging * * @param req Express request object * @param res Express response object * @param next Express next function */ export function httpRequestLogger(req: Request, res: Response, next: NextFunction): void { const startTime = Date.now(); // Log the incoming request logger.info(`[${req.method}] ${req.path}`, { query: req.query, body: req.body, headers: sanitizeHeaders(req.headers), userAgent: req.get('User-Agent'), ip: req.ip || req.connection.remoteAddress, }); // Capture the original end method to log response details const originalEnd = res.end; res.end = function (chunk?: any, encoding?: any): Response { const duration = Date.now() - startTime; // Log response details logger.info(`[${req.method}] ${req.path} completed`, { statusCode: res.statusCode, duration: `${duration}ms`, contentType: res.get('Content-Type'), }); // Call the original end method return originalEnd.call(this, chunk, encoding); }; next(); }

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/1mcp-app/agent'

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