Skip to content

[duplicate-code] Duplicate Code Pattern: Redundant SSE Deprecation Warning Burst in connection.go #3634

@github-actions

Description

@github-actions

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

  1. 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
  2. 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

  • Replace the 5-line logger.LogWarn burst (lines 250–254) with 1–2 consolidated calls
  • Verify the consolidated message still appears in mcp-gateway.log and Markdown log output
  • Run make test to verify no regressions

Parent Issue

See parent analysis report: #3631
Related to #3631

Generated by Duplicate Code Detector · ● 1.3M ·

  • expires on Apr 19, 2026, 6:07 AM UTC

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions