[log] mcp: add debug logger to http_transport.go#2906
Conversation
Add dedicated logHTTP = logger.New("mcp:http_transport") debug logger to
http_transport.go and instrument key HTTP transport functions that previously
had no debug logging:
- newHTTPConnection: log transport type, URL, serverID, and session ID on
connection creation to help trace which transport variant is being used
- buildHTTPClientWithHeaders: log when custom headers are injected into the
HTTP client transport chain
- oidcRoundTripper.RoundTrip: log OIDC token acquisition per request,
useful when debugging authentication issues with OIDC-backed backends
- buildHTTPClientWithOIDC: log when OIDC provider wrapping is set up
- ensureToolCallArguments: log when the arguments field is missing or nil
in tools/call params (protocol normalization edge cases)
- setupHTTPRequest: log URL and payload size before creating the request
The new namespace (mcp:http_transport) is filterable independently from
mcp:connection, allowing targeted HTTP transport debugging:
DEBUG=mcp:http_transport ./awmg --config config.toml
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds a dedicated debug logger namespace for MCP HTTP transport (mcp:http_transport) and instruments several HTTP-transport-related helpers to improve diagnosability of connection setup and request shaping.
Changes:
- Introduces
logHTTP = logger.New("mcp:http_transport")ininternal/mcp/http_transport.go. - Adds debug logs around HTTP connection creation, client wrapping (headers/OIDC), request setup, and
tools/callargument normalization.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if session != nil { | ||
| sessionID = session.ID() | ||
| } | ||
| logHTTP.Printf("Creating HTTP connection: serverID=%s, url=%s, transport=%s, headers=%d, sessionID=%s", serverID, url, transportType, len(headers), sessionID) |
There was a problem hiding this comment.
This debug log prints the full backend/SDK session ID. Session identifiers are treated as sensitive elsewhere in the repo (they can act like bearer tokens), so logging them verbatim risks credential/session leakage in collected debug logs. Please log a truncated/redacted form (e.g., using internal/auth.TruncateSessionID or similar sanitization) or omit the session ID entirely.
| logHTTP.Printf("Creating HTTP connection: serverID=%s, url=%s, transport=%s, headers=%d, sessionID=%s", serverID, url, transportType, len(headers), sessionID) | |
| logHTTP.Printf("Creating HTTP connection: serverID=%s, url=%s, transport=%s, headers=%d", serverID, url, transportType, len(headers)) |
Adds a dedicated
logHTTP = logger.New("mcp:http_transport")debug logger tointernal/mcp/http_transport.goand instruments key HTTP transport functions that previously had no debug logging.Changes
File modified:
internal/mcp/http_transport.go(1 file, 9 insertions)New logger declaration
Logging added to 6 functions
newHTTPConnectionbuildHTTPClientWithHeadersoidcRoundTripper.RoundTripbuildHTTPClientWithOIDCensureToolCallArgumentsargumentsfield is missing or nilsetupHTTPRequestWhy this file?
http_transport.gohandles the HTTP transport negotiation (Streamable, SSE, Plain JSON-RPC) and connection setup for MCP backends. Despite being 622 lines with complex logic, its utility functions had no debug logging. The file already importedloggerand usedlogConn(from the same package'sconnection.go), but a dedicatedlogHTTPnamespace allows independent filtering:Validation
pkg:filenamenaming convention (mcp:http_transport)logConnlogging in the same file