Commit ac8733a
authored
Refactor
`SendRequestWithServerID` had repeated marshal+log response blocks
across transport branches, creating a maintainability hotspot and risk
of branch-level drift in logging behavior. This change centralizes that
logic into one helper while preserving existing call-site behavior.
- **What changed**
- Added `logInboundRPCResponseFromResult(...)` in
`internal/mcp/connection.go` to:
- marshal `*Response` (when non-nil),
- call `logInboundRPCResponse(...)`,
- return `(result, err)` unchanged.
- Updated `SendRequestWithServerID` to use the helper for its return
path instead of duplicating response logging logic inline.
- **Why this matters**
- Removes copy-pasted logging logic from transport handling flow.
- Makes future changes to inbound response logging single-point edits.
- **Targeted coverage added**
- New tests in `internal/mcp/connection_logging_test.go` validate helper
pass-through behavior for:
- non-nil response + non-nil error,
- nil response + nil error.
```go
func logInboundRPCResponseFromResult(serverID string, result *Response, err error, shouldAttachTags bool, snapshot *AgentTagsSnapshot) (*Response, error) {
var responsePayload []byte
if result != nil {
responsePayload, _ = json.Marshal(result)
}
logInboundRPCResponse(serverID, responsePayload, err, shouldAttachTags, snapshot)
return result, err
}
```
> [!WARNING]
>
> <details>
> <summary>Firewall rules blocked me from connecting to one or more
addresses (expand for details)</summary>
>
> #### I tried to connect to the following addresses, but was blocked by
firewall rules:
>
> - `example.com`
> - Triggering command: `/tmp/go-build2522761549/b510/launcher.test
/tmp/go-build2522761549/b510/launcher.test
-test.testlogfile=/tmp/go-build2522761549/b510/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -test.v=true
ache/go/1.25.8/x-errorsas .cfg 64/pkg/tool/linu-nilfunc -I
/tmp/go-build252-atomic -I 64/pkg/tool/linu-buildtags -o idi.go
racket.go x_amd64/compile -p flag -lang=go1.25 x_amd64/compile` (dns
block)
> - Triggering command: `/tmp/go-build3233101705/b514/launcher.test
/tmp/go-build3233101705/b514/launcher.test
-test.testlogfile=/tmp/go-build3233101705/b514/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -uns�� -unreachable=false
/tmp/go-build2522761549/b245/vet.cfg x_amd64/vet -c=4 -nolocalimports
-importcfg x_amd64/vet -ato�� -bool -buildtags x_amd64/vet -errorsas
0832 -nilfunc x_amd64/vet` (dns block)
> - `invalid-host-that-does-not-exist-12345.com`
> - Triggering command: `/tmp/go-build2522761549/b492/config.test
/tmp/go-build2522761549/b492/config.test
-test.testlogfile=/tmp/go-build2522761549/b492/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -test.v=true` (dns block)
> - Triggering command: `/tmp/go-build3233101705/b496/config.test
/tmp/go-build3233101705/b496/config.test
-test.testlogfile=/tmp/go-build3233101705/b496/testlog.txt
-test.paniconexit0 -test.timeout=10m0s ortc��
pkg/mod/google.golang.org/[email protected]/internal/proxyattributes/-errorsas
stmain.go x_amd64/vet --gdwarf-5 --64 -o x_amd64/vet -o
2761549/b492/config.test -trimpath x_amd64/vet -p golang.org/x/tex--norc
-lang=go1.25 x_amd64/vet` (dns block)
> - `nonexistent.local`
> - Triggering command: `/tmp/go-build2522761549/b510/launcher.test
/tmp/go-build2522761549/b510/launcher.test
-test.testlogfile=/tmp/go-build2522761549/b510/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -test.v=true
ache/go/1.25.8/x-errorsas .cfg 64/pkg/tool/linu-nilfunc -I
/tmp/go-build252-atomic -I 64/pkg/tool/linu-buildtags -o idi.go
racket.go x_amd64/compile -p flag -lang=go1.25 x_amd64/compile` (dns
block)
> - Triggering command: `/tmp/go-build3233101705/b514/launcher.test
/tmp/go-build3233101705/b514/launcher.test
-test.testlogfile=/tmp/go-build3233101705/b514/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -uns�� -unreachable=false
/tmp/go-build2522761549/b245/vet.cfg x_amd64/vet -c=4 -nolocalimports
-importcfg x_amd64/vet -ato�� -bool -buildtags x_amd64/vet -errorsas
0832 -nilfunc x_amd64/vet` (dns block)
> - `slow.example.com`
> - Triggering command: `/tmp/go-build2522761549/b510/launcher.test
/tmp/go-build2522761549/b510/launcher.test
-test.testlogfile=/tmp/go-build2522761549/b510/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -test.v=true
ache/go/1.25.8/x-errorsas .cfg 64/pkg/tool/linu-nilfunc -I
/tmp/go-build252-atomic -I 64/pkg/tool/linu-buildtags -o idi.go
racket.go x_amd64/compile -p flag -lang=go1.25 x_amd64/compile` (dns
block)
> - Triggering command: `/tmp/go-build3233101705/b514/launcher.test
/tmp/go-build3233101705/b514/launcher.test
-test.testlogfile=/tmp/go-build3233101705/b514/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -uns�� -unreachable=false
/tmp/go-build2522761549/b245/vet.cfg x_amd64/vet -c=4 -nolocalimports
-importcfg x_amd64/vet -ato�� -bool -buildtags x_amd64/vet -errorsas
0832 -nilfunc x_amd64/vet` (dns block)
> - `this-host-does-not-exist-12345.com`
> - Triggering command: `/tmp/go-build2522761549/b519/mcp.test
/tmp/go-build2522761549/b519/mcp.test
-test.testlogfile=/tmp/go-build2522761549/b519/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -test.v=true
1.5.0/internal/xcontext/xcontext.go 4BJUeiabknHIHNszrg x_amd64/compile
-p e/otlptracehttp//usr/bin/runc -lang=go1.25 x_amd64/compile -o g_.a
2761549/b165/ x_amd64/vet -p hash/fnv -lang=go1.25 x_amd64/vet` (dns
block)
> - Triggering command: `/tmp/go-build1064564734/b001/mcp.test
/tmp/go-build1064564734/b001/mcp.test
-test.testlogfile=/tmp/go-build1064564734/b001/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -uns�� 2761549/b402/_pkg_.a
/tmp/go-build2522761549/b126/vet-ifaceassert .cfg --global g/grpc/mem
64/bin/bash ache/go/1.25.8/x64/pkg/tool/linu-tests -qui��
ppFW/Fi3uUr-n6b91NPffppFW
k/gh-aw-mcpg/gh-aw-mcpg/internal/oidc/provider.gmain x_amd64/link .
-imultiarch x86_64-linux-gnu x_amd64/link` (dns block)
>
> If you need me to access, download, or install something from one of
these locations, you can either:
>
> - Configure [Actions setup
steps](https://gh.io/copilot/actions-setup-steps) to set up my
environment, which run before the firewall is enabled
> - Add the appropriate URLs or hosts to the custom allowlist in this
repository's [Copilot coding agent
settings](https://github.com/github/gh-aw-mcpg/settings/copilot/coding_agent)
(admins only)
>
> </details>SendRequestWithServerID to use a single inbound response logging path (#4054)2 files changed
Lines changed: 77 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
444 | 444 | | |
445 | 445 | | |
446 | 446 | | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
447 | 459 | | |
448 | 460 | | |
449 | 461 | | |
| |||
481 | 493 | | |
482 | 494 | | |
483 | 495 | | |
484 | | - | |
485 | | - | |
486 | | - | |
487 | | - | |
488 | | - | |
489 | | - | |
490 | | - | |
491 | | - | |
| 496 | + | |
492 | 497 | | |
493 | 498 | | |
494 | 499 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
0 commit comments