Refactor MCP text-result parsing and remove responseWriter StatusCode shadowing#7041
Conversation
StatusCode shadowing
There was a problem hiding this comment.
Pull request overview
This PR consolidates MCP raw-result text extraction into a shared helper and removes responseWriter.StatusCode() to avoid method/field shadowing, updating server-side logging and tests accordingly.
Changes:
- Introduces
internal/mcpresult.ExtractTextContentand wiresinternal/mcp.ExtractTextContentFromResultto it for shared MCP text extraction. - Refactors rate-limit detection and DIFC MCP-response unwrapping to reuse the shared text extractor.
- Removes
responseWriter.StatusCode()and updates logging/tests to use the embeddedBaseResponseWriter.StatusCodefield directly.
Show a summary per file
| File | Description |
|---|---|
| internal/server/transport_test.go | Updates tests to assert StatusCode field instead of removed accessor method. |
| internal/server/response_writer.go | Removes StatusCode() method to eliminate method/field shadowing. |
| internal/server/rate_limit.go | Replaces bespoke MCP content/text traversal with shared MCP text extraction helper. |
| internal/server/middleware.go | Updates SDK logging to use lw.StatusCode field directly. |
| internal/server/http_helpers.go | Updates response logging to use lw.StatusCode field directly. |
| internal/server/circuit_breaker_test.go | Adds regression coverage for rate-limit text extraction using BuildMCPTextResponse. |
| internal/mcpresult/text_content.go | Adds shared implementation for extracting concatenated text from raw MCP tool result maps. |
| internal/mcp/tool_result.go | Adds ExtractTextContentFromResult wrapper to expose shared extraction via internal/mcp. |
| internal/mcp/tool_result_test.go | Adds focused tests for ExtractTextContentFromResult across supported shapes and malformed entries. |
| internal/difc/path_labels.go | Updates MCP response unwrapping to use shared text extractor before JSON unmarshal. |
| internal/difc/path_labels_test.go | Adds coverage for unwrapping []map[string]interface{}-shaped MCP responses. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 11/11 changed files
- Comments generated: 1
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
@copilot fix the failing ci check https://github.com/github/gh-aw-mcpg/actions/runs/27022607362/job/79754235458?pr=7041 |
Fixed in commit I investigated the linked run and addressed the merge-ref lint failure ( |
|
@copilot resolve the merge conflicts in this pull request |
Resolved by merging |
|
@copilot resolve the merge conflicts in this pull request |
Resolved by merging |
The codebase had the same MCP
content/textparsing logic duplicated acrossmcp,server, anddifc, plus aresponseWriter.StatusCode()method that shadowed the promotedBaseResponseWriter.StatusCodefield. This change consolidates MCP text extraction into one shared path and makes server-side status handling consistent with the base writer pattern used elsewhere.Shared MCP text-content extraction
[]interface{}content and[]map[string]interface{}content produced by MCP response builders.internal/mcpas the package-facing entrypoint while moving the shared implementation into a cycle-free helper package.Server rate-limit detection
contenttraversal ininternal/server/rate_limit.gowith the shared extractor.DIFC MCP response unwrapping
unwrapMCPResponseininternal/difc/path_labels.goto reuse the same text extraction path before JSON unwrapping.[]map[string]interface{}without duplicating traversal logic.Response writer status handling
responseWriter.StatusCode()frominternal/server/response_writer.go.BaseResponseWriter.StatusCodefield directly, eliminating the method/field shadowing ambiguity.Focused test coverage
Example of the status-code cleanup: