Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions internal/mcp/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}
Expand Down
Loading