Refactor DIFC tool classification placement and extract middleware content-rewrite helpers#7992
Merged
Merged
Conversation
Copilot
AI
changed the title
[WIP] Refactor semantic function clustering analysis
Refactor DIFC tool classification placement and extract middleware content-rewrite helpers
Jun 23, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors DIFC- and middleware-related helpers into more cohesive locations to keep tool registration and jq/schema middleware logic focused, without intended behavior changes.
Changes:
- Moved
isSingularReadToolfrominternal/server/tool_registry.gointointernal/server/difc_log.goalongside other DIFC response/error shaping helpers. - Extracted content-rewrite helpers (
rewriteFilteredTextPayload,rewriteEnvelopeTextPayload,rewriteFirstContentItem,rewriteContentItemText) out ofinternal/middleware/jqschema.gointo a newinternal/middleware/content_rewrite.go. - Kept existing signatures and call sites intact to preserve behavior.
Show a summary per file
| File | Description |
|---|---|
| internal/server/tool_registry.go | Removes DIFC-specific helper to keep tool registration focused. |
| internal/server/difc_log.go | Co-locates DIFC helper (isSingularReadTool) with DIFC logging/error shaping logic. |
| internal/middleware/jqschema.go | Removes extracted content-rewrite helper block to narrow file focus to jq/schema middleware flow. |
| internal/middleware/content_rewrite.go | New file containing the extracted content-rewrite helper functions. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 4/4 changed files
- Comments generated: 1
Comment on lines
+1
to
+12
| package middleware | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
|
|
||
| "github.com/github/gh-aw-mcpg/internal/logger" | ||
| sdk "github.com/modelcontextprotocol/go-sdk/mcp" | ||
| ) | ||
|
|
||
| func rewriteFilteredTextPayload(result *sdk.CallToolResult, data any, filteredText string) (*sdk.CallToolResult, any) { | ||
| logMiddleware.Printf("rewriteFilteredTextPayload: rewriting first text content item, filteredLen=%d", len(filteredText)) | ||
| rewrittenContent := make([]sdk.Content, 0, len(result.Content)) |
Add a small delay after initializeDone before closing the SSE stream. Under -race, goroutine scheduling jitter can cause the SDK to observe the SSE stream close and propagate the 'exceeded 0 retries' error back to Connect before the initialize response is fully processed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Jun 24, 2026
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.
Semantic clustering flagged two structural outliers:
isSingularReadToollived in tool registration code despite being DIFC-only, andjqschema.gostill contained a cohesive content-rewrite helper block better separated from jq/schema logic. This PR performs those refactors without changing behavior.DIFC helper co-location
isSingularReadTool(toolName string) boolfrominternal/server/tool_registry.gotointernal/server/difc_log.go.buildDIFCSingleItemFilteredError, notices, logging) in one place and removes DIFC-specific logic from tool registration.Middleware rewrite-cluster extraction
internal/middleware/content_rewrite.go.internal/middleware/jqschema.go:rewriteFilteredTextPayloadrewriteEnvelopeTextPayloadrewriteFirstContentItemrewriteContentItemTextjqschema.gofocused on jq filter compilation/execution and middleware flow.Behavior-preserving refactor