MCPcopy Create free account
hub / github.com/github/gh-aw / loggingHandler

Function loggingHandler

pkg/cli/mcp_server_http.go:32–62  ·  view source on GitHub ↗
(handler http.Handler)

Source from the content-addressed store, hash-verified

30}
31
32func loggingHandler(handler http.Handler) http.Handler {
33 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
34 start := time.Now()
35
36 // Create a response writer wrapper to capture status code.
37 wrapped := &responseWriter{ResponseWriter: w, statusCode: http.StatusOK}
38
39 // Sanitize user-controlled input before logging to prevent log injection
40 sanitizedPath := sanitizeForLog(r.URL.Path)
41
42 // Log request details.
43 mcpHTTPLog.Printf("[REQUEST] %s | %s | %s %s",
44 start.Format(time.RFC3339),
45 r.RemoteAddr,
46 r.Method,
47 sanitizedPath)
48
49 // Call the actual handler.
50 handler.ServeHTTP(wrapped, r)
51
52 // Log response details.
53 duration := time.Since(start)
54 mcpHTTPLog.Printf("[RESPONSE] %s | %s | %s %s | Status: %d | Duration: %v",
55 time.Now().Format(time.RFC3339),
56 r.RemoteAddr,
57 r.Method,
58 sanitizedPath,
59 wrapped.statusCode,
60 duration)
61 })
62}
63
64// runHTTPServer runs the MCP server with HTTP/SSE transport
65func runHTTPServer(server *mcp.Server, port int) error {

Calls 2

sanitizeForLogFunction · 0.85
PrintfMethod · 0.45