From 7ec0d5fa476ce1f7009301fc3e2578d06e45a754 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 15 Apr 2026 12:51:28 +0000 Subject: [PATCH] refactor(mcp): extract logInboundRPCResponse helper to deduplicate response logging The three identical if/else blocks in SendRequestWithServerID that dispatch to LogRPCResponseWithAgentSnapshot vs LogRPCResponse are replaced with a single unexported logInboundRPCResponse helper. No functional change. Closes #3828 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- internal/mcp/connection.go | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/internal/mcp/connection.go b/internal/mcp/connection.go index e21ee017..5c828284 100644 --- a/internal/mcp/connection.go +++ b/internal/mcp/connection.go @@ -417,6 +417,16 @@ func (c *Connection) callSDKMethodWithReconnect(method string, params interface{ return result, err } +// logInboundRPCResponse logs an inbound RPC response, optionally attaching agent DIFC tag snapshots. +// When shouldAttachTags is true, snapshot must be non-nil. +func logInboundRPCResponse(serverID string, payload []byte, err error, shouldAttachTags bool, snapshot *AgentTagsSnapshot) { + if shouldAttachTags { + logger.LogRPCResponseWithAgentSnapshot(logger.RPCDirectionInbound, serverID, payload, err, snapshot.Secrecy, snapshot.Integrity) + } else { + logger.LogRPCResponse(logger.RPCDirectionInbound, serverID, payload, err) + } +} + // SendRequest sends a JSON-RPC request and waits for the response // The serverID parameter is used for logging to associate the request with a backend server func (c *Connection) SendRequest(method string, params interface{}) (*Response, error) { @@ -454,11 +464,7 @@ func (c *Connection) SendRequestWithServerID(ctx context.Context, method string, if result != nil { responsePayload, _ = json.Marshal(result) } - if shouldAttachAgentTags { - logger.LogRPCResponseWithAgentSnapshot(logger.RPCDirectionInbound, serverID, responsePayload, err, snapshot.Secrecy, snapshot.Integrity) - } else { - logger.LogRPCResponse(logger.RPCDirectionInbound, serverID, responsePayload, err) - } + logInboundRPCResponse(serverID, responsePayload, err, shouldAttachAgentTags, snapshot) return result, err } @@ -469,11 +475,7 @@ func (c *Connection) SendRequestWithServerID(ctx context.Context, method string, if result != nil { responsePayload, _ = json.Marshal(result) } - if shouldAttachAgentTags { - logger.LogRPCResponseWithAgentSnapshot(logger.RPCDirectionInbound, serverID, responsePayload, err, snapshot.Secrecy, snapshot.Integrity) - } else { - logger.LogRPCResponse(logger.RPCDirectionInbound, serverID, responsePayload, err) - } + logInboundRPCResponse(serverID, responsePayload, err, shouldAttachAgentTags, snapshot) return result, err } @@ -485,11 +487,7 @@ func (c *Connection) SendRequestWithServerID(ctx context.Context, method string, if result != nil { responsePayload, _ = json.Marshal(result) } - if shouldAttachAgentTags { - logger.LogRPCResponseWithAgentSnapshot(logger.RPCDirectionInbound, serverID, responsePayload, err, snapshot.Secrecy, snapshot.Integrity) - } else { - logger.LogRPCResponse(logger.RPCDirectionInbound, serverID, responsePayload, err) - } + logInboundRPCResponse(serverID, responsePayload, err, shouldAttachAgentTags, snapshot) return result, err }