Skip to content

Commit 129e87f

Browse files
Copilotlpcox
andauthored
fix: eliminate duplicate log telemetry in reconnect paths and SSE deprecation block
- Extract logReconnectStart() and logReconnectResult(err) helpers to deduplicate the three identical logger.Log* call sites shared by reconnectPlainJSON() and reconnectSDKTransport() (issue #3632) - Consolidate the 5-line SSE deprecation warning burst into 2 concise log calls: one LogWarn with URL and spec info, one LogInfo for the connection confirmation (issue #3634) - Issue #3633 (Mixed log.Printf / logger.LogInfo) was already resolved Agent-Logs-Url: https://github.com/github/gh-aw-mcpg/sessions/adc38ef8-8512-47c3-805e-582ed80d5993 Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
1 parent 777e01a commit 129e87f

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

internal/mcp/connection.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,8 @@ func NewHTTPConnection(ctx context.Context, serverID, url string, headers map[st
243243
logConn.Printf("Attempting SSE transport for %s", url)
244244
conn, err = trySSETransport(ctx, cancel, serverID, url, headers, headerClient, keepAlive)
245245
if err == nil {
246-
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)
247-
logger.LogWarn("backend", "⚠️ WARNING: MCP over SSE (2024-11-05 spec) has been DEPRECATED")
248-
logger.LogWarn("backend", "⚠️ The server at %s is using the deprecated SSE transport", url)
249-
logger.LogWarn("backend", "⚠️ Please migrate to streamable HTTP transport (2025-03-26 spec)")
250-
logger.LogWarn("backend", "Configured HTTP MCP server with SSE transport: %s", url)
246+
logger.LogWarn("backend", "⚠️ MCP over SSE (2024-11-05 spec) is DEPRECATED for url=%s. Please migrate to streamable HTTP transport (2025-03-26 spec).", url)
247+
logger.LogInfo("backend", "Configured HTTP MCP server with SSE transport: %s", url)
251248
return conn, nil
252249
}
253250
logConn.Printf("SSE transport failed: %v", err)
@@ -296,6 +293,21 @@ func (c *Connection) ServerInfo() (name, version string) {
296293
return initResult.ServerInfo.Name, initResult.ServerInfo.Version
297294
}
298295

296+
// logReconnectStart emits the structured log warning that is common to all reconnect paths.
297+
func (c *Connection) logReconnectStart() {
298+
logger.LogWarn("backend", "MCP session expired for %s, attempting to reconnect...", c.serverID)
299+
}
300+
301+
// logReconnectResult emits the structured log entry that signals whether the reconnect
302+
// succeeded or failed. It is the common success/failure telemetry shared by all reconnect paths.
303+
func (c *Connection) logReconnectResult(err error) {
304+
if err != nil {
305+
logger.LogError("backend", "Session reconnect failed for %s: %v", c.serverID, err)
306+
} else {
307+
logger.LogInfo("backend", "Session successfully reconnected for %s", c.serverID)
308+
}
309+
}
310+
299311
// reconnectPlainJSON re-initialises the plain JSON-RPC session with the HTTP backend.
300312
// It is safe for concurrent callers: only one reconnect runs at a time, and the updated
301313
// session ID is available to all callers once the lock is released.
@@ -304,17 +316,16 @@ func (c *Connection) reconnectPlainJSON() error {
304316
defer c.sessionMu.Unlock()
305317

306318
logConn.Printf("Session expired, reconnecting plain JSON-RPC for serverID=%s", c.serverID)
307-
logger.LogWarn("backend", "MCP session expired for %s, attempting to reconnect...", c.serverID)
319+
c.logReconnectStart()
308320

309321
sessionID, err := c.initializeHTTPSession()
322+
c.logReconnectResult(err)
310323
if err != nil {
311-
logger.LogError("backend", "Session reconnect failed for %s: %v", c.serverID, err)
312324
return fmt.Errorf("session reconnect failed: %w", err)
313325
}
314326

315327
c.httpSessionID = sessionID
316328
logConn.Printf("Reconnected plain JSON-RPC session for serverID=%s, new sessionID=%s", c.serverID, sessionID)
317-
logger.LogInfo("backend", "Session successfully reconnected for %s", c.serverID)
318329
return nil
319330
}
320331

@@ -325,7 +336,7 @@ func (c *Connection) reconnectSDKTransport() error {
325336
defer c.sessionMu.Unlock()
326337

327338
logConn.Printf("Session expired, reconnecting SDK transport for serverID=%s, type=%s", c.serverID, c.httpTransportType)
328-
logger.LogWarn("backend", "MCP session expired for %s, attempting to reconnect...", c.serverID)
339+
c.logReconnectStart()
329340

330341
// Close the existing session gracefully (ignore error – it's already dead).
331342
if c.session != nil {
@@ -359,16 +370,15 @@ func (c *Connection) reconnectSDKTransport() error {
359370
defer cancel()
360371

361372
session, err := client.Connect(connectCtx, transport, nil)
373+
c.logReconnectResult(err)
362374
if err != nil {
363-
logger.LogError("backend", "Session reconnect failed for %s: %v", c.serverID, err)
364375
return fmt.Errorf("session reconnect failed: %w", err)
365376
}
366377

367378
c.client = client
368379
c.session = session
369380

370381
logConn.Printf("Reconnected SDK session for serverID=%s", c.serverID)
371-
logger.LogInfo("backend", "Session successfully reconnected for %s", c.serverID)
372382
return nil
373383
}
374384

0 commit comments

Comments
 (0)