Part of duplicate code analysis: #3631
Summary
Three transport-connection success paths in internal/mcp/connection.go each emit two log entries for the same event: one via the structured logger.LogInfo pipeline (which writes to mcp-gateway.log) and a second via the standard log.Printf (which writes only to stderr). This creates redundant log noise and partial bypass of the structured logging pipeline — the problem the most recent commit (a82e67c) addressed for SSE deprecation warnings but did not fully resolve for the other transport paths.
Duplication Details
Pattern: logger.LogInfo + log.Printf paired for the same operational event
- Severity: Medium
- Occurrences: 3 paired call sites + 2 additional solo
log.Printf calls
- Locations:
internal/mcp/connection.go lines 240–241 (streamable HTTP success)
internal/mcp/connection.go lines 263–264 (plain JSON-RPC success)
internal/mcp/connection.go lines 143–144 (stdio server start)
internal/mcp/connection.go lines 148 and 178 (solo log.Printf with no structured counterpart)
Code Sample — duplicate pair at lines 240–241:
logger.LogInfo("backend", "Successfully connected using streamable HTTP transport, url=%s", url)
log.Printf("Configured HTTP MCP server with streamable transport: %s", url) // ← redundant
Code Sample — duplicate pair at lines 263–264:
logger.LogInfo("backend", "Successfully connected using plain JSON-RPC transport, url=%s", url)
log.Printf("Configured HTTP MCP server with plain JSON-RPC transport: %s", url) // ← redundant
Code Sample — duplicate pair at lines 143–144:
logger.LogInfo("backend", "Starting MCP backend server, command=%s, args=%v", command, sanitize.SanitizeArgs(expandedArgs))
log.Printf("Starting MCP server command: %s %v", command, sanitize.SanitizeArgs(expandedArgs)) // ← redundant
Code Sample — solo log.Printf (no structured counterpart) at lines 148, 178:
log.Printf("Connecting to MCP server...") // line 148
log.Printf("Started MCP server: %s %v", ...) // line 178
Impact Analysis
- Maintainability: Messages that appear in two formats (structured log file vs. raw stderr) diverge over time — the
log.Printf version already uses slightly different wording than the logger.LogInfo version in all three pairs.
- Bug Risk: Operators relying on
mcp-gateway.log for monitoring miss events logged only via log.Printf; operators watching stderr receive duplicate lines.
- Code Bloat: 5 extra
log.Printf lines; also requires the "log" standard-library import in connection.go to remain.
Refactoring Recommendations
-
Remove the redundant log.Printf calls (preferred)
- Delete lines 144, 148, 178, 241, 264 in
connection.go.
- Convert the solo
log.Printf at line 148 ("Connecting to MCP server...") and line 178 to logger.LogInfo or logConn.Printf (the debug-gated logger already used in the same function).
- Estimated effort: 15 minutes
- Benefits: consistent structured logging;
"log" import can be removed from connection.go entirely (it is only used for these five calls in the non-test code)
-
Replace remaining log.Printf calls with logConn.Printf for purely diagnostic messages (lines 148)
- These are debug-level traces that are better gated by the
DEBUG env var than always-on stderr.
Implementation Checklist
Parent Issue
See parent analysis report: #3631
Related to #3631
Generated by Duplicate Code Detector · ● 1.3M · ◷
Part of duplicate code analysis: #3631
Summary
Three transport-connection success paths in
internal/mcp/connection.goeach emit two log entries for the same event: one via the structuredlogger.LogInfopipeline (which writes tomcp-gateway.log) and a second via the standardlog.Printf(which writes only to stderr). This creates redundant log noise and partial bypass of the structured logging pipeline — the problem the most recent commit (a82e67c) addressed for SSE deprecation warnings but did not fully resolve for the other transport paths.Duplication Details
Pattern:
logger.LogInfo+log.Printfpaired for the same operational eventlog.Printfcallsinternal/mcp/connection.golines 240–241 (streamable HTTP success)internal/mcp/connection.golines 263–264 (plain JSON-RPC success)internal/mcp/connection.golines 143–144 (stdio server start)internal/mcp/connection.golines 148 and 178 (sololog.Printfwith no structured counterpart)Code Sample — duplicate pair at lines 240–241:
Code Sample — duplicate pair at lines 263–264:
Code Sample — duplicate pair at lines 143–144:
Code Sample — solo
log.Printf(no structured counterpart) at lines 148, 178:Impact Analysis
log.Printfversion already uses slightly different wording than thelogger.LogInfoversion in all three pairs.mcp-gateway.logfor monitoring miss events logged only vialog.Printf; operators watching stderr receive duplicate lines.log.Printflines; also requires the"log"standard-library import inconnection.goto remain.Refactoring Recommendations
Remove the redundant
log.Printfcalls (preferred)connection.go.log.Printfat line 148 ("Connecting to MCP server...") and line 178 tologger.LogInfoorlogConn.Printf(the debug-gated logger already used in the same function)."log"import can be removed fromconnection.goentirely (it is only used for these five calls in the non-test code)Replace remaining
log.Printfcalls withlogConn.Printffor purely diagnostic messages (lines 148)DEBUGenv var than always-on stderr.Implementation Checklist
log.Printfat lines 144, 241, 264 (have structured counterpart)log.Printfat lines 148, 178 withlogConn.Printforlogger.LogInfo"log"from imports inconnection.goif no remaining usesmake lintto verify no unused importsmake testto verify no regressionsParent Issue
See parent analysis report: #3631
Related to #3631