Deduplicate raw TextContent fallback in tool result conversion#5241
Merged
Conversation
Agent-Logs-Url: https://github.com/github/gh-aw-mcpg/sessions/61cee3f2-5c5a-40d7-beed-07afbbe78d18 Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix duplicate code pattern in marshal-to-TextContent fallback
Deduplicate raw TextContent fallback in tool result conversion
May 7, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors internal/mcp/tool_result.go to centralize the “marshal backend value and wrap as a single TextContent” fallback used by ConvertToCallToolResult and convertMapToCallToolResult, keeping fallback behavior consistent while reducing duplication.
Changes:
- Extracts repeated marshal-and-wrap fallback into
marshalValueToTextContentResult. - Replaces four duplicated fallback blocks with the helper.
- Adds a unit test covering the
map[string]interface{}{ "content": nil, ... }fallback case.
Show a summary per file
| File | Description |
|---|---|
| internal/mcp/tool_result.go | Introduces marshalValueToTextContentResult and routes existing fallback branches through it. |
| internal/mcp/tool_result_test.go | Adds coverage for the content: nil map fallback behavior. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
internal/mcp/tool_result.gorepeated the same marshal-to-TextContentfallback in four branches ofConvertToCallToolResult/convertMapToCallToolResult. This change centralizes that behavior so fallback handling stays consistent as the conversion logic evolves.Refactor fallback construction
marshalValueToTextContentResultto own the shared:json.Marshal(...)sdk.CallToolResult{Content: []sdk.Content{&sdk.TextContent{...}}}Behavior preserved across existing fallback paths
[]interface{})nilcontentcontentshapeFocused coverage
content: nilmap case to ensure it still falls back to raw text wrappingWarning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
example.com/tmp/go-build1542213297/b513/launcher.test /tmp/go-build1542213297/b513/launcher.test -test.testlogfile=/tmp/go-build1542213297/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build1542213297/b445/vet.cfg g_.a -I x_amd64/vet --gdwarf-5 ls/insecure -o x_amd64/vet -qui�� .cfg /tmp/go-build418-ifaceassert x_amd64/vet . .io/otel/semconv-atomic x86_64-linux-gnu-bool x_amd64/vet(dns block)/tmp/go-build2637788630/b513/launcher.test /tmp/go-build2637788630/b513/launcher.test -test.testlogfile=/tmp/go-build2637788630/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s .o .o .o .o .o .o f07e34dca1.build--exclude-standard lib/rustlib/x86_--others lib/�� lib/rustlib/x86_64-REDACTED-linux-gnu/lib/libobject-926daa94a00ee327.rlib lib/rustlib/x86_64-REDACTED-linux-gnu/lib/libmemchr-48d5b0db80402653.rlib lib/rustlib/x86_64-REDACTED-linux-gnu/lib/libaddr2line-3367f26bd486b29d.rlib (compatibility issue with Go 1.25.0). Continuing with other checks..."; \ elif command -v golan lib/rustlib/x86_--norc lib/rustlib/x86_--noprofile 05ed-cgu.00.rcgu.o(dns block)invalid-host-that-does-not-exist-12345.com/tmp/go-build1542213297/b495/config.test /tmp/go-build1542213297/b495/config.test -test.testlogfile=/tmp/go-build1542213297/b495/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build1542213297/b393/vet.cfg uf@v1.36.11/protoadapt/convert.go om/tetratelabs/wazero@v1.11.0/internal/fsapi/polgoogle.golang.org/grpc/balancer/pickfirst/intern-atomic x_amd64/vet 4460836/b150/ --64(dns block)nonexistent.local/tmp/go-build1542213297/b513/launcher.test /tmp/go-build1542213297/b513/launcher.test -test.testlogfile=/tmp/go-build1542213297/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build1542213297/b445/vet.cfg g_.a -I x_amd64/vet --gdwarf-5 ls/insecure -o x_amd64/vet -qui�� .cfg /tmp/go-build418-ifaceassert x_amd64/vet . .io/otel/semconv-atomic x86_64-linux-gnu-bool x_amd64/vet(dns block)/tmp/go-build2637788630/b513/launcher.test /tmp/go-build2637788630/b513/launcher.test -test.testlogfile=/tmp/go-build2637788630/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s .o .o .o .o .o .o f07e34dca1.build--exclude-standard lib/rustlib/x86_--others lib/�� lib/rustlib/x86_64-REDACTED-linux-gnu/lib/libobject-926daa94a00ee327.rlib lib/rustlib/x86_64-REDACTED-linux-gnu/lib/libmemchr-48d5b0db80402653.rlib lib/rustlib/x86_64-REDACTED-linux-gnu/lib/libaddr2line-3367f26bd486b29d.rlib (compatibility issue with Go 1.25.0). Continuing with other checks..."; \ elif command -v golan lib/rustlib/x86_--norc lib/rustlib/x86_--noprofile 05ed-cgu.00.rcgu.o(dns block)slow.example.com/tmp/go-build1542213297/b513/launcher.test /tmp/go-build1542213297/b513/launcher.test -test.testlogfile=/tmp/go-build1542213297/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build1542213297/b445/vet.cfg g_.a -I x_amd64/vet --gdwarf-5 ls/insecure -o x_amd64/vet -qui�� .cfg /tmp/go-build418-ifaceassert x_amd64/vet . .io/otel/semconv-atomic x86_64-linux-gnu-bool x_amd64/vet(dns block)/tmp/go-build2637788630/b513/launcher.test /tmp/go-build2637788630/b513/launcher.test -test.testlogfile=/tmp/go-build2637788630/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s .o .o .o .o .o .o f07e34dca1.build--exclude-standard lib/rustlib/x86_--others lib/�� lib/rustlib/x86_64-REDACTED-linux-gnu/lib/libobject-926daa94a00ee327.rlib lib/rustlib/x86_64-REDACTED-linux-gnu/lib/libmemchr-48d5b0db80402653.rlib lib/rustlib/x86_64-REDACTED-linux-gnu/lib/libaddr2line-3367f26bd486b29d.rlib (compatibility issue with Go 1.25.0). Continuing with other checks..."; \ elif command -v golan lib/rustlib/x86_--norc lib/rustlib/x86_--noprofile 05ed-cgu.00.rcgu.o(dns block)this-host-does-not-exist-12345.com/tmp/go-build1542213297/b522/mcp.test /tmp/go-build1542213297/b522/mcp.test -test.testlogfile=/tmp/go-build1542213297/b522/testlog.txt -test.paniconexit0 -test.timeout=10m0s -o .cfg -trimpath x_amd64/vet -p vendor/golang.or/usr/bin/runc -lang=go1.25 x_amd64/vet .cfg�� 4460836/b392/_pkg_.a -I x_amd64/vet --gdwarf-5 g/protobuf/inter-o -o x_amd64/vet(dns block)/tmp/go-build495322174/b001/mcp.test /tmp/go-build495322174/b001/mcp.test -test.testlogfile=/tmp/go-build495322174/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s /home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/guards/github-guard/rust-guard/target/debug/deps/serde_derive-bdc7cd22a58a5141.serde_derive.12123747d8da05ed-cgu.07.rcgu.o /home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/guards/github-guard/rust-guard/target/debug/deps/serde_derive-bdc7cd22a58a5141.serde_derive.12123747d8da05ed-cgu.08.rcgu.o /home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/guards/github-guard/rust-guard/target/debug/deps/serde_derive-bdc7cd22a58a5141.serde_derive.12123747d8da05ed-cgu.09.rcgu.o /home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/guards/github-guard/rust-guard/target/debug/deps/serde_derive-bdc7cd22a58a5141.serde_derive.12123747d8da05ed-cgu.10.rcgu.o /home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/guards/github-guard/rust-guard/target/debug/deps/serde_derive-bdc7cd22a58a5141.serde_derive.12123747d8da05ed-cgu.11.rcgu.o /home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/guards/github-guard/rust-guard/target/debug/�� /home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/guards/github-guard/rust-guard/target/debug/deps/serde_derive-bdc7cd22a58a5141.serde_derive.12123747d8da05ed-cgu.13.rcgu.o /home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/guards/github-guard/rust-guard/target/debug/deps/serde_derive-bdc7cd22a58a5141.serde_derive.12123747d8da05ed-cgu.14.rcgu.o 64-u�� 64-REDACTED-linux-gnu/lib/libminiz_oxide-2b6a8d2f6e1dc71b.rlib 64-REDACTED-linux-gnu/lib/libadler2-39ffdbc27c978ccc.rlib /usr/libexec/doc-Wl,-Bstatic by/405f41b9e5ffacc 42ce6344f8114eba-Wl,--version-script=/home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/guards/github-guard/rust-guard/target/debug/deps/rustcsdpj1U/list -importcfg 0cd/log.json(dns block)If you need me to access, download, or install something from one of these locations, you can either: