Skip to content

[log] Add debug logging to MCP connection SDK method wrappers#1394

Merged
lpcox merged 1 commit intomainfrom
add-debug-logging-mcp-connection-a88953331628219e
Feb 25, 2026
Merged

[log] Add debug logging to MCP connection SDK method wrappers#1394
lpcox merged 1 commit intomainfrom
add-debug-logging-mcp-connection-a88953331628219e

Conversation

@github-actions
Copy link
Contributor

Summary

Added logConn debug logging to the SDK method wrapper functions in internal/mcp/connection.go that previously lacked any tracing.

Changes

File modified: internal/mcp/connection.go

The following functions now have debug logging (using the existing logConn logger with namespace "mcp:connection"):

Function New Logging
callSDKMethod Logs method being dispatched and serverID; also logs unsupported method errors
listTools Logs request entry with serverID; logs received tool count
listResources Logs request entry with serverID; logs received resource count
readResource Logs the resource URI being read and serverID
listPrompts Logs request entry with serverID; logs received prompt count
getPrompt Logs the prompt name being requested and serverID
Close Logs connection close with serverID and isHTTP flag

Logging Guidelines Followed

  • ✅ Reuses the existing logConn = logger.New("mcp:connection") logger declaration
  • ✅ No side effects in log arguments (only field access on existing variables)
  • ✅ Follows pkg:filename naming convention (already established)
  • ✅ No test files modified
  • ✅ Messages are meaningful and help troubleshoot MCP backend interactions

Usage

Enable debug logging for this component:

DEBUG=mcp:connection ./awmg --config config.toml
# or all mcp package logs:
DEBUG=mcp:* ./awmg --config config.toml

Rationale

The callTool function already had a logConn.Printf call to trace tool invocations. This PR adds consistent logging to the other SDK method wrappers (listTools, listResources, readResource, listPrompts, getPrompt) and to callSDKMethod dispatch, making it easier to trace the full lifecycle of MCP backend protocol interactions during debugging.

AI generated by Go Logger Enhancement

Add logConn debug logging to the SDK method wrapper functions in
internal/mcp/connection.go that previously lacked any logging:

- callSDKMethod: log method dispatch and unsupported method errors
- listTools: log request entry and received tool count
- listResources: log request entry and received resource count
- readResource: log the resource URI being read
- listPrompts: log request entry and received prompt count
- getPrompt: log the prompt name being requested
- Close: log connection close with serverID and transport type

These 11 new debug logging calls improve troubleshooting visibility
for MCP backend protocol interactions when DEBUG=mcp:* is set.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions bot added automation enhancement New feature or request labels Feb 25, 2026
@lpcox lpcox marked this pull request as ready for review February 25, 2026 17:08
Copilot AI review requested due to automatic review settings February 25, 2026 17:08
@lpcox lpcox merged commit 6cac6df into main Feb 25, 2026
2 checks passed
@lpcox lpcox deleted the add-debug-logging-mcp-connection-a88953331628219e branch February 25, 2026 17:08
Copy link
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 comprehensive debug logging to MCP connection SDK method wrapper functions in internal/mcp/connection.go. The logging uses the existing logConn debug logger with namespace "mcp:connection" and can be enabled via DEBUG=mcp:connection environment variable.

Changes:

  • Added debug logging to callSDKMethod dispatcher to trace method routing
  • Added entry/exit logging to listTools, listResources, readResource, listPrompts, and getPrompt methods
  • Added connection close logging to track cleanup operations
Comments suppressed due to low confidence (1)

internal/mcp/connection.go:483

  • Prompt names could potentially contain sensitive information. While this PR follows the existing pattern in callTool (line 408) which logs parameters without sanitization, consider using sanitize.SanitizeString(getParams.Name) to protect against accidental exposure of sensitive data in debug logs.

Note: This is consistent with how the server-side code handles similar logging (see internal/server/unified.go:346-347 where tool arguments are sanitized).

	logConn.Printf("getPrompt: getting prompt name=%s from serverID=%s", getParams.Name, c.serverID)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

return nil, err
}

logConn.Printf("readResource: reading resource uri=%s from serverID=%s", readParams.URI, c.serverID)
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

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

URIs could potentially contain sensitive information such as query parameters with tokens (e.g., file://path?token=secret) or file paths containing sensitive data. While this PR follows the existing pattern in callTool (line 408) which logs arguments without sanitization, consider using sanitize.SanitizeString(readParams.URI) to protect against accidental exposure of sensitive data in debug logs.

Note: This comment also applies to the existing callTool logging at line 408, which logs arguments without sanitization. Consider addressing both as part of a broader security improvement to the debug logging in this file.

This issue also appears on line 483 of the same file.

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