[log] Add debug logging to MCP connection SDK method wrappers#1394
[log] Add debug logging to MCP connection SDK method wrappers#1394
Conversation
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>
There was a problem hiding this comment.
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
callSDKMethoddispatcher to trace method routing - Added entry/exit logging to
listTools,listResources,readResource,listPrompts, andgetPromptmethods - 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 usingsanitize.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) |
There was a problem hiding this comment.
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.
Summary
Added
logConndebug logging to the SDK method wrapper functions ininternal/mcp/connection.gothat previously lacked any tracing.Changes
File modified:
internal/mcp/connection.goThe following functions now have debug logging (using the existing
logConnlogger with namespace"mcp:connection"):callSDKMethodlistToolslistResourcesreadResourcelistPromptsgetPromptCloseLogging Guidelines Followed
logConn = logger.New("mcp:connection")logger declarationpkg:filenamenaming convention (already established)Usage
Enable debug logging for this component:
Rationale
The
callToolfunction already had alogConn.Printfcall to trace tool invocations. This PR adds consistent logging to the other SDK method wrappers (listTools,listResources,readResource,listPrompts,getPrompt) and tocallSDKMethoddispatch, making it easier to trace the full lifecycle of MCP backend protocol interactions during debugging.