Repository navigation
Deduplicate single-text MCP tool result construction - #16616
Conversation
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
There was a problem hiding this comment.
🟢 Approval recommended
No unresolved issues are identified, and the shared result constructors have targeted coverage for error state, metadata, content preservation, and original-result isolation.
No open issues 🎉
What changed in this PR
This PR centralizes construction of single-text MCP CallToolResult values, reducing duplication while preserving error flags, metadata, trailing content, and existing error-return behavior.
Changes:
- Added shared success and error text-result constructors.
- Replaced repeated result construction across middleware, backend handling, and test utilities.
- Added constructor tests and regression coverage for metadata, error state, and content preservation.
| File | Description |
|---|---|
| internal/testutil/mcptest/server.go | Uses the shared error-result constructor for test-server tool failures. |
| internal/server/backend_call.go | Uses the shared error-result constructor for rate-limit responses. |
| internal/middleware/jqschema.go | Uses the shared constructor for transformed results while preserving metadata and error state. |
| internal/middleware/jqschema_gap_coverage_test.go | Verifies transformed results preserve metadata and do not mutate the original result. |
| internal/middleware/filter_rewrite_test.go | Verifies rewritten results preserve trailing content, metadata, error state, and original-result isolation. |
| internal/middleware/content_rewrite.go | Rebuilds rewritten results with the shared constructor while retaining metadata and trailing content. |
| internal/mcp/tool_result.go | Defines shared text and error-result constructors and applies them to existing helpers. |
| internal/mcp/tool_result_test.go | Tests constructor behavior for success, error, empty, and special-text cases. |
Review effort: Lite (dynamic)
🔒 mcpg Read-Only Stress — defaultSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: INCONCLUSIVE No write leaked through mcpg on any surface. Part B is INCONCLUSIVE because the GitHub MCP tool catalog exposed by this workflow (tools.github: with GITHUB_READ_ONLY=1) contains zero write tools (add_issue_comment, star_repository, issue_write, create_branch, create_or_update_file, create_pull_request are all absent) - this confirms gh-aw's backend-level read-only mode but cannot independently exercise mcpg's own gateway-level DIFC/guard write-blocking layer. Parts D/E are INCONCLUSIVE because gh was not authenticated in this environment (no GH_TOKEN), so REST/GraphQL write attempts failed locally before reaching the GitHub API, rather than being refused by mcpg or GitHub permissions. Parts A and C (reads) fully passed on both the MCP and proxied-CLI surfaces.
|
Seven call sites repeat single-text
CallToolResultconstruction, including error results and middleware rewrites.NewTextCallToolResultandNewErrorTextCallToolResult; replace the repeated literals.