Skip to content

Commit ab5d495

Browse files
authored
[Repo Assist] fix: remove redundant log.Printf calls from connection.go (#3640)
🤖 *This PR was created by Repo Assist, an automated AI assistant.* Addresses #3633. ## Problem `internal/mcp/connection.go` had five `log.Printf` calls that either duplicated adjacent `logger.LogInfo` structured-log calls or wrote to stderr with no structured counterpart. This meant: - Operators monitoring `mcp-gateway.log` would miss some events (e.g. "Started MCP server") - Operators watching stderr got duplicate lines for the same event with slightly different wording - The `"log"` standard-library import persisted only to serve these calls ## Changes | Line | Old | New | |------|-----|-----| | 144 | `log.Printf("Starting MCP server command: ...")` | Removed — `logger.LogInfo` on line 143 already covers this | | 148 | `log.Printf("Connecting to MCP server...")` | Removed — `logConn.Print("Initiating MCP server connection and handshake")` on the next line already covers this at debug level | | 178 | `log.Printf("Started MCP server: ...")` | Replaced with `logger.LogInfo("backend", "Started MCP server: ...")` — now written to `mcp-gateway.log` | | 241 | `log.Printf("Configured HTTP MCP server with streamable transport: ...")` | Removed — `logger.LogInfo` on line 240 already covers this | | 264 | `log.Printf("Configured HTTP MCP server with plain JSON-RPC transport: ...")` | Removed — `logger.LogInfo` on line 263 already covers this | The now-unused `"log"` standard-library import is also removed. ## Test Status ⚠️ **Infrastructure note**: The Go 1.25.0 toolchain required by `go.mod` is unavailable in this environment (blocked by network firewall). All changes are mechanical deletions of `log.Printf` calls with no logic changes. `go vet` and `make test` will run in the GitHub Actions CI environment where Go 1.25.0 is available. ## Trade-offs - The "Started MCP server" event (previously only on stderr) is now in `mcp-gateway.log`. This is strictly better — it was a gap in structured logging. - Removing the two "Connecting" and "Starting" stderr echoes reduces startup noise on stderr; the events are still visible via `DEBUG=mcp:*` through `logConn`. Closes #3633 > Generated by [Repo Assist](https://github.com/github/gh-aw-mcpg/actions/runs/24306753924/agentic_workflow) · ● 2.8M · [◷](https://github.com/search?q=repo%3Agithub%2Fgh-aw-mcpg+%22gh-aw-workflow-id%3A+repo-assist%22&type=pullrequests) > > To install this [agentic workflow](https://github.com/githubnext/agentics/blob/851905c06e905bf362a9f6cc54f912e3df747d55/workflows/repo-assist.md), run > ``` > gh aw add githubnext/agentics@851905c > ``` <!-- gh-aw-agentic-workflow: Repo Assist, engine: copilot, model: auto, id: 24306753924, workflow_id: repo-assist, run: https://github.com/github/gh-aw-mcpg/actions/runs/24306753924 --> <!-- gh-aw-workflow-id: repo-assist -->
2 parents a82e67c + 4462ca9 commit ab5d495

1 file changed

Lines changed: 1 addition & 6 deletions

File tree

internal/mcp/connection.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"encoding/json"
88
"fmt"
99
"io"
10-
"log"
1110
"net/http"
1211
"os/exec"
1312
"strings"
@@ -141,11 +140,9 @@ func NewConnection(ctx context.Context, serverID, command string, args []string,
141140
}()
142141

143142
logger.LogInfo("backend", "Starting MCP backend server, command=%s, args=%v", command, sanitize.SanitizeArgs(expandedArgs))
144-
log.Printf("Starting MCP server command: %s %v", command, sanitize.SanitizeArgs(expandedArgs))
145143
transport := &sdk.CommandTransport{Command: cmd}
146144

147145
// Connect to the server (this handles the initialization handshake automatically)
148-
log.Printf("Connecting to MCP server...")
149146
logConn.Print("Initiating MCP server connection and handshake")
150147
session, err := client.Connect(ctx, transport, nil)
151148
if err != nil {
@@ -175,7 +172,7 @@ func NewConnection(ctx context.Context, serverID, command string, args []string,
175172
isHTTP: false,
176173
}
177174

178-
log.Printf("Started MCP server: %s %v", command, sanitize.SanitizeArgs(args))
175+
logger.LogInfo("backend", "Started MCP server: %s %v", command, sanitize.SanitizeArgs(expandedArgs))
179176
return conn, nil
180177
}
181178

@@ -238,7 +235,6 @@ func NewHTTPConnection(ctx context.Context, serverID, url string, headers map[st
238235
conn, err := tryStreamableHTTPTransport(ctx, cancel, serverID, url, headers, headerClient, keepAlive)
239236
if err == nil {
240237
logger.LogInfo("backend", "Successfully connected using streamable HTTP transport, url=%s", url)
241-
log.Printf("Configured HTTP MCP server with streamable transport: %s", url)
242238
return conn, nil
243239
}
244240
logConn.Printf("Streamable HTTP failed: %v", err)
@@ -261,7 +257,6 @@ func NewHTTPConnection(ctx context.Context, serverID, url string, headers map[st
261257
conn, err = tryPlainJSONTransport(ctx, cancel, serverID, url, headers, headerClient)
262258
if err == nil {
263259
logger.LogInfo("backend", "Successfully connected using plain JSON-RPC transport, url=%s", url)
264-
log.Printf("Configured HTTP MCP server with plain JSON-RPC transport: %s", url)
265260
return conn, nil
266261
}
267262
logConn.Printf("Plain JSON-RPC transport failed: %v", err)

0 commit comments

Comments
 (0)