Skip to content

[Repo Assist] refactor(mcp): extract logInboundRPCResponse helper in connection.go#3847

Merged
lpcox merged 1 commit intomainfrom
repo-assist/improve-connection-log-helper-34262823ef7f5fee
Apr 15, 2026
Merged

[Repo Assist] refactor(mcp): extract logInboundRPCResponse helper in connection.go#3847
lpcox merged 1 commit intomainfrom
repo-assist/improve-connection-log-helper-34262823ef7f5fee

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This is a Repo Assist automated pull request.

Summary

Addresses the duplicate code pattern identified in #3828.

The three identical if shouldAttachAgentTags { ... } else { ... } blocks in SendRequestWithServerID are replaced with calls to a new unexported helper logInboundRPCResponse. No functional change.

Root cause

SendRequestWithServerID handles three code paths (plain JSON-RPC HTTP, SDK streamable/SSE HTTP, and stdio), each ending with the same 5-line conditional to dispatch logging. Any future change to the response logging signature — adding a tag type, changing the direction argument — had to be applied to three identical sites.

Fix

Added logInboundRPCResponse(serverID string, payload []byte, err error, shouldAttachTags bool, snapshot *AgentTagsSnapshot) just before SendRequest. Each of the three call sites is now a single line.

When shouldAttachTags is true, snapshot is guaranteed non-nil: the caller sets shouldAttachAgentTags := hasSnapshot && difc.IsSinkServerID(serverID), so shouldAttachAgentTags can only be true when GetAgentTagsSnapshotFromContext returned a non-nil result.

Trade-offs

None. This is a pure mechanical refactor — the emitted log calls are byte-for-byte identical to before.

Test Status

The change is a pure refactor with no functional impact. Build and tests could not be run locally due to proxy.golang.org being blocked by the firewall in this environment. The CI pipeline will confirm correctness. The diff reduces connection.go by 2 net lines while removing the maintenance hazard.

Closes #3828

Warning

⚠️ Firewall blocked 6 domains

The following domains were blocked by the firewall during workflow execution:

  • go.opentelemetry.io
  • go.yaml.in
  • golang.org
  • google.golang.org
  • gopkg.in
  • proxy.golang.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "go.opentelemetry.io"
    - "go.yaml.in"
    - "golang.org"
    - "google.golang.org"
    - "gopkg.in"
    - "proxy.golang.org"

See Network Configuration for more information.

Generated by Repo Assist · ● 5M ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@851905c06e905bf362a9f6cc54f912e3df747d55

…sponse 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>
@lpcox lpcox marked this pull request as ready for review April 15, 2026 13:52
Copilot AI review requested due to automatic review settings April 15, 2026 13:52
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

Refactors internal/mcp/connection.go to remove a duplicated inbound RPC response logging block in SendRequestWithServerID by extracting the shared logic into a small unexported helper, improving maintainability without changing behavior.

Changes:

  • Added logInboundRPCResponse helper to centralize inbound RPC response logging (with optional agent DIFC tag snapshots).
  • Replaced three identical if shouldAttachAgentTags { ... } else { ... } blocks with single-line helper calls across the HTTP/plain JSON, HTTP/SDK (streamable/SSE), and stdio code paths.
Show a summary per file
File Description
internal/mcp/connection.go Extracts duplicated inbound response logging into logInboundRPCResponse and updates all three call sites.

Copilot's findings

Tip

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

  • Files reviewed: 1/1 changed files
  • Comments generated: 0

@lpcox lpcox merged commit 23c712f into main Apr 15, 2026
7 checks passed
@lpcox lpcox deleted the repo-assist/improve-connection-log-helper-34262823ef7f5fee branch April 15, 2026 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[duplicate-code] Duplicate Code Pattern: Repeated shouldAttachAgentTags Conditional Logging in connection.go

2 participants