Skip to content

[log] mcp: add debug logger to http_transport.go#2906

Merged
lpcox merged 1 commit intomainfrom
add-http-transport-debug-logging-0ce326a1fc03bd5e
Mar 31, 2026
Merged

[log] mcp: add debug logger to http_transport.go#2906
lpcox merged 1 commit intomainfrom
add-http-transport-debug-logging-0ce326a1fc03bd5e

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Adds a dedicated logHTTP = logger.New("mcp:http_transport") debug logger to internal/mcp/http_transport.go and 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

var logHTTP = logger.New("mcp:http_transport")

Logging added to 6 functions

Function Log message
newHTTPConnection Connection creation: serverID, URL, transport type, header count, sessionID
buildHTTPClientWithHeaders Custom header count being injected
oidcRoundTripper.RoundTrip OIDC token acquisition per request with audience
buildHTTPClientWithOIDC OIDC provider wrapping setup with audience
ensureToolCallArguments Protocol normalization when arguments field is missing or nil
setupHTTPRequest URL, payload size, and custom header count before request creation

Why this file?

http_transport.go handles 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 imported logger and used logConn (from the same package's connection.go), but a dedicated logHTTP namespace allows independent filtering:

# Debug only HTTP transport setup (separate from connection-level events)
DEBUG=mcp:http_transport ./awmg --config config.toml

# Or combine with connection events
DEBUG=mcp:* ./awmg --config config.toml

Validation

  • All changes follow the pkg:filename naming convention (mcp:http_transport)
  • Logger arguments contain no side-effecting computations
  • No duplication of existing logConn logging in the same file
  • Only 1 file modified (focused, reviewable PR)

Generated by Go Logger Enhancement ·

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>
@github-actions github-actions bot added automation enhancement New feature or request labels Mar 31, 2026
@lpcox lpcox marked this pull request as ready for review March 31, 2026 18:04
Copilot AI review requested due to automatic review settings March 31, 2026 18:04
@lpcox lpcox merged commit b84d62e into main Mar 31, 2026
3 checks passed
@lpcox lpcox deleted the add-http-transport-debug-logging-0ce326a1fc03bd5e branch March 31, 2026 18:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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") in internal/mcp/http_transport.go.
  • Adds debug logs around HTTP connection creation, client wrapping (headers/OIDC), request setup, and tools/call argument 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)
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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))

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants