Part of duplicate code analysis: #3631
Summary
When the gateway successfully connects to an MCP backend using the deprecated SSE transport, internal/mcp/connection.go emits 5 consecutive logger.LogWarn calls that all convey overlapping deprecation information. Four of the five messages say essentially the same thing (SSE is deprecated, please migrate) in slightly different wording. The commit a82e67c added these warnings to route SSE deprecation notices through the structured logger, but introduced redundancy in doing so.
Duplication Details
Pattern: Redundant multi-line SSE deprecation warning burst
- Severity: Medium
- Occurrences: 5
logger.LogWarn calls in a single if err == nil block (lines 250–254)
- Locations:
internal/mcp/connection.go lines 250–254
Code Sample:
if err == nil {
logger.LogWarn("backend", "⚠️ MCP over SSE has been deprecated. Connected using SSE transport for url=%s. Please migrate to streamable HTTP transport (2025-03-26 spec).", url)
logger.LogWarn("backend", "⚠️ WARNING: MCP over SSE (2024-11-05 spec) has been DEPRECATED")
logger.LogWarn("backend", "⚠️ The server at %s is using the deprecated SSE transport", url)
logger.LogWarn("backend", "⚠️ Please migrate to streamable HTTP transport (2025-03-26 spec)")
logger.LogWarn("backend", "Configured HTTP MCP server with SSE transport: %s", url)
return conn, nil
}
Lines 250, 251, 252, and 253 are near-identical: they each state that SSE is deprecated and/or ask the user to migrate. Line 250 is a superset of lines 251–253 (it contains the URL, the spec version, and the migration ask all in one message).
Impact Analysis
- Maintainability: The deprecation message must be kept consistent across 4 near-duplicate lines. Any update to spec version strings (e.g., when SSE support is fully removed) requires editing multiple lines.
- Bug Risk: Low for correctness, but the burst of 5 warning lines in logs is visually noisy and may cause operators to miscount warnings or overlook other log entries.
- Code Bloat: 4 redundant log call sites. In
mcp-gateway.log and Markdown log output, operators see a wall of nearly identical warnings for each SSE-connected backend at startup.
Refactoring Recommendations
-
Consolidate to 2 log calls (preferred)
- Keep one high-signal warning with all relevant info, plus the "configured" confirmation line:
logger.LogWarn("backend",
"⚠️ SSE transport (2024-11-05 spec) is DEPRECATED for url=%s. "+
"Please migrate to streamable HTTP transport (2025-03-26 spec).", url)
logger.LogInfo("backend", "Configured HTTP MCP server with SSE transport: %s", url)
- Estimated effort: 10 minutes
- Benefits: cleaner logs; single location to update when SSE support is eventually removed; the
url is present in the warning so operators know exactly which backend needs migration
-
Alternatively, keep the human-readable multi-line format but use a single logger.LogWarn call with \n separators, so it appears as one log entry in mcp-gateway.log:
logger.LogWarn("backend",
"⚠️ MCP over SSE (2024-11-05 spec) is DEPRECATED\n"+
" Server: %s\n"+
" Please migrate to streamable HTTP transport (2025-03-26 spec).", url)
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
When the gateway successfully connects to an MCP backend using the deprecated SSE transport,
internal/mcp/connection.goemits 5 consecutivelogger.LogWarncalls that all convey overlapping deprecation information. Four of the five messages say essentially the same thing (SSE is deprecated, please migrate) in slightly different wording. The commita82e67cadded these warnings to route SSE deprecation notices through the structured logger, but introduced redundancy in doing so.Duplication Details
Pattern: Redundant multi-line SSE deprecation warning burst
logger.LogWarncalls in a singleif err == nilblock (lines 250–254)internal/mcp/connection.golines 250–254Code Sample:
Lines 250, 251, 252, and 253 are near-identical: they each state that SSE is deprecated and/or ask the user to migrate. Line 250 is a superset of lines 251–253 (it contains the URL, the spec version, and the migration ask all in one message).
Impact Analysis
mcp-gateway.logand Markdown log output, operators see a wall of nearly identical warnings for each SSE-connected backend at startup.Refactoring Recommendations
Consolidate to 2 log calls (preferred)
urlis present in the warning so operators know exactly which backend needs migrationAlternatively, keep the human-readable multi-line format but use a single
logger.LogWarncall with\nseparators, so it appears as one log entry inmcp-gateway.log:Implementation Checklist
logger.LogWarnburst (lines 250–254) with 1–2 consolidated callsmcp-gateway.logand Markdown log outputmake testto verify no regressionsParent Issue
See parent analysis report: #3631
Related to #3631