Skip to content

Centralize single-text MCP response envelopes - #16750

Merged
lpcox merged 3 commits into
mainfrom
copilot/duplicate-code-single-text-mcp
Nov 18, 2026
Merged

lpcox merged 3 commits into
mainfrom
copilot/duplicate-code-single-text-mcp

Conversation

@lpcox

@lpcox lpcox commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Three sites constructed the same MCP text envelope, with DIFC using a different slice representation.

  • Shared builder: Add mcpresult.NewTextResponse(text); retain mcp.BuildMCPTextResponse as a delegating compatibility wrapper.
  • Call sites: Replace collaborator-permission and DIFC literals. DIFC uses the supported []map[string]any representation while preserving envelope metadata and synchronized filtered text/structured content.
  • Coverage: Add table-driven shape and text round-trip tests; extend DIFC coverage for normalized content and re-unwrapping.

@lpcox lpcox changed the title [WIP] Refactor duplicate single-text MCP content envelope literal Centralize single-text MCP response envelopes Nov 18, 2026
@lpcox
lpcox marked this pull request as ready for review November 18, 2026 15:32
Copilot AI adaptive review requested due to automatic review settings November 18, 2026 15:32
@github-actions

This comment has been minimized.

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

The shared MCP text-response refactor has no active review issues.

No open issues 🎉

What changed in this PR

Centralizes single-text MCP response construction in internal/mcpresult, addressing the duplication described in #16651 while retaining the existing compatibility helper.

Changes:

  • Adds NewTextResponse and delegates BuildMCPTextResponse to it.
  • Reuses the builder for collaborator-permission and DIFC responses, preserving envelope metadata.
  • Adds shape and text round-trip tests, plus DIFC normalization and re-unwrapping coverage.
File Description
internal/​mcpresult/​text_response_test.go Tests envelope shape, normalization, and text round-trips.
internal/​mcpresult/​mcpresult.go Adds the shared single-text response builder.
internal/​mcp/​tool_result.go Retains the compatibility helper as a delegating wrapper.
internal/​githubhttp/​collaborator.go Uses the shared builder for permission responses.
internal/​difc/​path_collections.go Uses the builder to replace filtered envelope content.
internal/​difc/​path_collections_test.go Checks normalized content and re-unwrapping of filtered responses.

Review effort: Balanced (adaptive)

@lpcox

lpcox commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

Copilot AI commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

@copilot fix failing ci linting check https://github.com/github/gh-aw-mcpg/actions/runs/44331611149/job/134915816562?pr=16750

Fixed in c2dede5. The linked lint job passed; CI was failing in the Rust-guard job because two tests assumed the filtered content field was []any. They now use the shared normalization helpers. The full proxy guard test command and make agent-finished pass.

@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 (add_issue_comment/star_repository/issue_write/create_branch/create_or_update_file/create_pull_request) all 6 tools absent from catalog (23 read-only tools only) BLOCKED ⚠️
C CLI reads (same github CLI proxy as Part A) data returned ALLOWED ✅
D CLI REST writes (reaction/star/issue/comment) gh not authenticated — no GH_TOKEN in env BLOCKED ⚠️
E CLI GraphQL mutations (addReaction/addStar/createIssue) gh not authenticated — same gap as D BLOCKED ⚠️

Overall: INCONCLUSIVE
(⚠️ Part B: all 6 targeted write tools were absent from the exposed catalog, so only backend GITHUB_READ_ONLY=1 config was confirmed, not mcpg's own gateway-level DIFC/guard refusal. Part D/E: gh CLI had no authenticated session in this environment — writes failed with "set the GH_TOKEN environment variable", not a GitHub API 403/404/422 — so the token-scope boundary could not be exercised. No write leaked on any surface attempted.)

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

@lpcox
lpcox merged commit 35466ea into main Nov 18, 2026
30 checks passed
@lpcox
lpcox deleted the copilot/duplicate-code-single-text-mcp branch November 18, 2026 16:04
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: single-text MCP content envelope literal

3 participants