Commit a4700bd
authored
Refactor duplicated marshal/log paths and unify sanitized sys tool response logging (#4106)
Recent `SendRequestWithServerID` cleanup left three duplication/safety
gaps: repeated marshal-for-debug blocks, duplicated sys tool handler
skeletons, and unsanitized `sys_list_servers` result logging. This PR
consolidates those paths and closes the sanitization gap.
- **Consolidate marshal-for-debug logic**
- Added `logger.LogMarshaledForDebug(...)` in
`internal/logger/marshal_debug.go`.
- Replaced repeated marshal+error/success logging blocks in:
- `internal/guard/wasm.go`
- `internal/server/guard_init.go`
- Result: one shared marshaling pattern for debug logging across
guard/server paths.
- **Unify sys tool call/error/log skeleton**
- Added `callAndLogSysTool(...)` in `internal/server/tool_registry.go`.
- `sysInitHandler` and `sysListHandler` now share one call path (call
sys server → handle error → marshal/log result → return).
- **Fix sanitization gap in `sys_list_servers` logging**
- Added shared `marshalAndSanitizeForLog(...)` in `tool_registry.go`.
- `sys_list_servers` response logs now use
`sanitize.SanitizeString(...)`, matching `sys_init` and backend tool
logging behavior.
- **Focused test coverage**
- Added helper tests for marshal debug utility:
- `internal/logger/marshal_debug_test.go`
- Added server tests for log sanitization/error behavior:
- `internal/server/tool_registry_test.go`
```go
func (us *UnifiedServer) callAndLogSysTool(sessionID, operationName, sysToolName string) (*sdk.CallToolResult, interface{}, error) {
result, err := us.callSysServer(sysToolName)
if err != nil {
logger.LogError("client", "MCP %s call failed, session=%s, error=%v", operationName, sessionID, err)
return mcp.NewErrorCallToolResult(err)
}
logger.LogInfo("client", "MCP %s response, session=%s, result=%s", operationName, sessionID, marshalAndSanitizeForLog(result))
return nil, result, nil
}
```
> [!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-build1793350213/b510/launcher.test
/tmp/go-build1793350213/b510/launcher.test
-test.testlogfile=/tmp/go-build1793350213/b510/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -test.v=true
3350213/b184/_pk-errorsas 64/src/log/slog/-ifaceassert bin/as -p
zevo/backend/isa-atomic -lang=go1.25 /opt/hostedtoolc-buildtags -o
s/attributes.go idRS/k9xnSFeesAm-ifaceassert x_amd64/compile -p
crypto/internal/info -lang=go1.25 x_amd64/compile` (dns block)
> - Triggering command: `/tmp/go-build3990767025/b514/launcher.test
/tmp/go-build3990767025/b514/launcher.test
-test.testlogfile=/tmp/go-build3990767025/b514/testlog.txt
-test.paniconexit0 -test.timeout=10m0s
/tmp/go-build3990767025/b495/vet.cfg ry=1 -trimpath x_amd64/vet -p
github.com/githupush -lang=go1.25 x_amd64/vet -ato�� .cfg -buildtags
64/pkg/tool/linux_amd64/vet -errorsas -ifaceassert -nilfunc
64/pkg/tool/linu-trimpath` (dns block)
> - Triggering command: `/tmp/go-build848674421/b514/launcher.test
/tmp/go-build848674421/b514/launcher.test
-test.testlogfile=/tmp/go-build848674421/b514/testlog.txt
-test.paniconexit0 -test.timeout=10m0s know��
l/server/tool_registry_test.go
known-linux-gnu/lib/rustlib/x86_--format=format:%H %ct %D
stable-x86_64-REDACTED-linux-gnu/--end-of-options 6e1dc71b.rlib ccc.rlib
--systemd-cgroup-bool` (dns block)
> - `invalid-host-that-does-not-exist-12345.com`
> - Triggering command: `/tmp/go-build1793350213/b492/config.test
/tmp/go-build1793350213/b492/config.test
-test.testlogfile=/tmp/go-build1793350213/b492/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -test.v=true 3350213/b151/_pk-p o
x_amd64/compile` (dns block)
> - Triggering command: `/tmp/go-build3990767025/b496/config.test
/tmp/go-build3990767025/b496/config.test
-test.testlogfile=/tmp/go-build3990767025/b496/testlog.txt
-test.paniconexit0 -test.timeout=10m0s n-me�� g_.a
pkg/mod/go.opentelemetry.io/otel/exporters/otlp/otlptrace/[email protected]/doc.go
x_amd64/vet -p github.com/segme--norc -lang=go1.17 x_amd64/vet -ato��
MQJZCSQ0B -buildtags x_amd64/vet -errorsas -ifaceassert -nilfunc
ks..."; \
elif c--revs` (dns block)
> - Triggering command: `/tmp/go-build848674421/b496/config.test
/tmp/go-build848674421/b496/config.test
-test.testlogfile=/tmp/go-build848674421/b496/testlog.txt
-test.paniconexit0 -test.timeout=10m0s 05ed�� 05ed-cgu.10.rcgu-errorsas
05ed-cgu.11.rcgu-ifaceassert 05ed-cgu.12.rcgu-nilfunc
05ed-cgu.13.rcgugit 05ed-cgu.14.rcguls-files
pt_build-842ae9a--exclude-standard pt_build-842ae9a--others /usr��
--root .rlib 6b2b26a06.rlib 327.rlib 653.rlib 86b29d.rlib
ive.12123747d8da05ed-cgu.00.rcgu.o` (dns block)
> - `nonexistent.local`
> - Triggering command: `/tmp/go-build1793350213/b510/launcher.test
/tmp/go-build1793350213/b510/launcher.test
-test.testlogfile=/tmp/go-build1793350213/b510/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -test.v=true
3350213/b184/_pk-errorsas 64/src/log/slog/-ifaceassert bin/as -p
zevo/backend/isa-atomic -lang=go1.25 /opt/hostedtoolc-buildtags -o
s/attributes.go idRS/k9xnSFeesAm-ifaceassert x_amd64/compile -p
crypto/internal/info -lang=go1.25 x_amd64/compile` (dns block)
> - Triggering command: `/tmp/go-build3990767025/b514/launcher.test
/tmp/go-build3990767025/b514/launcher.test
-test.testlogfile=/tmp/go-build3990767025/b514/testlog.txt
-test.paniconexit0 -test.timeout=10m0s
/tmp/go-build3990767025/b495/vet.cfg ry=1 -trimpath x_amd64/vet -p
github.com/githupush -lang=go1.25 x_amd64/vet -ato�� .cfg -buildtags
64/pkg/tool/linux_amd64/vet -errorsas -ifaceassert -nilfunc
64/pkg/tool/linu-trimpath` (dns block)
> - Triggering command: `/tmp/go-build848674421/b514/launcher.test
/tmp/go-build848674421/b514/launcher.test
-test.testlogfile=/tmp/go-build848674421/b514/testlog.txt
-test.paniconexit0 -test.timeout=10m0s know��
l/server/tool_registry_test.go
known-linux-gnu/lib/rustlib/x86_--format=format:%H %ct %D
stable-x86_64-REDACTED-linux-gnu/--end-of-options 6e1dc71b.rlib ccc.rlib
--systemd-cgroup-bool` (dns block)
> - `slow.example.com`
> - Triggering command: `/tmp/go-build1793350213/b510/launcher.test
/tmp/go-build1793350213/b510/launcher.test
-test.testlogfile=/tmp/go-build1793350213/b510/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -test.v=true
3350213/b184/_pk-errorsas 64/src/log/slog/-ifaceassert bin/as -p
zevo/backend/isa-atomic -lang=go1.25 /opt/hostedtoolc-buildtags -o
s/attributes.go idRS/k9xnSFeesAm-ifaceassert x_amd64/compile -p
crypto/internal/info -lang=go1.25 x_amd64/compile` (dns block)
> - Triggering command: `/tmp/go-build3990767025/b514/launcher.test
/tmp/go-build3990767025/b514/launcher.test
-test.testlogfile=/tmp/go-build3990767025/b514/testlog.txt
-test.paniconexit0 -test.timeout=10m0s
/tmp/go-build3990767025/b495/vet.cfg ry=1 -trimpath x_amd64/vet -p
github.com/githupush -lang=go1.25 x_amd64/vet -ato�� .cfg -buildtags
64/pkg/tool/linux_amd64/vet -errorsas -ifaceassert -nilfunc
64/pkg/tool/linu-trimpath` (dns block)
> - Triggering command: `/tmp/go-build848674421/b514/launcher.test
/tmp/go-build848674421/b514/launcher.test
-test.testlogfile=/tmp/go-build848674421/b514/testlog.txt
-test.paniconexit0 -test.timeout=10m0s know��
l/server/tool_registry_test.go
known-linux-gnu/lib/rustlib/x86_--format=format:%H %ct %D
stable-x86_64-REDACTED-linux-gnu/--end-of-options 6e1dc71b.rlib ccc.rlib
--systemd-cgroup-bool` (dns block)
> - `this-host-does-not-exist-12345.com`
> - Triggering command: `/tmp/go-build1793350213/b519/mcp.test
/tmp/go-build1793350213/b519/mcp.test
-test.testlogfile=/tmp/go-build1793350213/b519/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -test.v=true
transport/bdp_estimator.go transport/client_stream.go x_amd64/compile
-pthread e/otlptracehttp/--version -fmessage-length=0 x_amd64/compile
3350�� g_.a 3350213/b165/ x_amd64/vet --gdwarf-5 mcpgodebug -o
x_amd64/vet` (dns block)
> - Triggering command: `/tmp/go-build3990767025/b523/mcp.test
/tmp/go-build3990767025/b523/mcp.test
-test.testlogfile=/tmp/go-build3990767025/b523/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -ato�� .cfg -buildtags
0278e5566a20dc05-d -errorsas -ifaceassert -nilfunc
64/pkg/tool/linu-buildtags --ve�� .cfg -tests 64/pkg/tool/linu-nilfunc
1024825-9d38bb40/usr/bin/runc.original [email protected]/depr--version
x_amd64/compile 64/pkg/tool/linu-tests` (dns block)
> - Triggering command: `/tmp/go-build848674421/b523/mcp.test
/tmp/go-build848674421/b523/mcp.test
-test.testlogfile=/tmp/go-build848674421/b523/testlog.txt
-test.paniconexit0 -test.timeout=10m0s ogpt�� q7jvxzdnkys32nfz-errorsas
0ok7l9sshaaz07e8-ifaceassert hw1mmy6a1aekmmsh-nilfunc
4p2kq4dabhq5b2kedocker wmuqycv01jbjtq95inspect ntained/cc
stable-x86_64-un{{.Config.OpenStdin}} stab��
stable-x86_64-REDACTED-linux-gnu/lib/rustlib/x86_64-REDACTED-linux-gnu/lib/libobject-926daa94a00ee/usr/libexec/docker/docker-init
stable-x86_64-REDACTED-linux-gnu/lib/rustlib/x86_64-REDACTED-linux-gnu/lib/libmemchr-48d5b0db80402--version
.1/x64/codeql/tools/linux64/java/lib/jspawnhelper
stable-x86_64-un/usr/libexec/docker/cli-plugins/docker-compose
7a5585.0r6f2y9pmdocker-cli-plugin-metadata
7a5585.0y8i0suihruczucboywd9kbz6/tmp/go-build985941549/b001/_pkg_.a
.1/x64/codeql/tools/linux64/java-trimpath` (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>6 files changed
Lines changed: 145 additions & 40 deletions
File tree
- internal
- guard
- logger
- server
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
695 | 695 | | |
696 | 696 | | |
697 | 697 | | |
698 | | - | |
699 | | - | |
700 | | - | |
701 | | - | |
702 | | - | |
703 | | - | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
704 | 707 | | |
705 | 708 | | |
706 | 709 | | |
| |||
727 | 730 | | |
728 | 731 | | |
729 | 732 | | |
730 | | - | |
731 | | - | |
732 | | - | |
733 | | - | |
734 | | - | |
735 | | - | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
736 | 742 | | |
737 | 743 | | |
738 | 744 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
351 | 351 | | |
352 | 352 | | |
353 | 353 | | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
360 | 363 | | |
361 | 364 | | |
362 | 365 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
285 | 285 | | |
286 | 286 | | |
287 | 287 | | |
288 | | - | |
289 | | - | |
290 | | - | |
| 288 | + | |
291 | 289 | | |
292 | 290 | | |
293 | 291 | | |
| |||
351 | 349 | | |
352 | 350 | | |
353 | 351 | | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
354 | 368 | | |
355 | 369 | | |
356 | 370 | | |
| |||
392 | 406 | | |
393 | 407 | | |
394 | 408 | | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
| 409 | + | |
405 | 410 | | |
406 | 411 | | |
407 | 412 | | |
| |||
431 | 436 | | |
432 | 437 | | |
433 | 438 | | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
442 | | - | |
| 439 | + | |
443 | 440 | | |
444 | 441 | | |
445 | 442 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
496 | 496 | | |
497 | 497 | | |
498 | 498 | | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
499 | 530 | | |
500 | 531 | | |
501 | 532 | | |
| |||
0 commit comments