Skip to content

Deduplicate single-text MCP tool result construction - #16616

Merged
lpcox merged 2 commits into
mainfrom
copilot/duplicate-code-fix
Nov 15, 2026
Merged

lpcox merged 2 commits into
mainfrom
copilot/duplicate-code-fix

Conversation

@lpcox

@lpcox lpcox commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Seven call sites repeat single-text CallToolResult construction, including error results and middleware rewrites.

  • Shared constructors: Add NewTextCallToolResult and NewErrorTextCallToolResult; replace the repeated literals.
  • Preserved semantics: Keep metadata propagation explicit, retain error flags and trailing content, and preserve existing error-return contracts.
transformedResult := mcp.NewTextCallToolResult(string(rewrittenJSON), result.IsError)
transformedResult.Meta = result.Meta

@lpcox lpcox changed the title [WIP] Refactor repeated CallToolResult construction Deduplicate single-text MCP tool result construction Nov 15, 2026
@lpcox
lpcox marked this pull request as ready for review November 15, 2026 20:18
Copilot AI adaptive review requested due to automatic review settings November 15, 2026 20:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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)

@github-actions

Copy link
Copy Markdown
Contributor

🔒 mcpg Read-Only Stress — default

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: default AWF (normal container isolation)

Part Surface Op Result Expected Status
A MCP reads (list_issues, list_pull_requests, get_file_contents, list_commits) data returned ALLOWED ✅
B MCP writes (reaction/star/issue/comment/branch/file/PR) tool catalog contains only 23 read-only tools; all 7 write targets absent BLOCKED ⚠️
C CLI reads (list_issues, get_file_contents via github CLI proxy) data returned ALLOWED ✅
D CLI REST writes (reaction/star/issue/comment/file) gh unauthenticated (no GH_TOKEN) - commands rejected before reaching GitHub API BLOCKED ⚠️
E CLI GraphQL mutations (addReaction/addStar/createIssue) gh unauthenticated, same as Part D BLOCKED ⚠️

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.

🔒 mcpg read-only stress (default AWF runtime) by Read-Only Stress: default runtime

@lpcox
lpcox merged commit e6a4d6b into main Nov 15, 2026
37 checks passed
@lpcox
lpcox deleted the copilot/duplicate-code-fix branch November 15, 2026 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[duplicate-code] Duplicate Code Pattern: Repeated single-text CallToolResult construction

3 participants