Skip to content

refactor: document strict vs. lenient content-item semantics in convertMapToCallToolResult#7571

Merged
lpcox merged 2 commits into
mainfrom
copilot/refactor-semantic-function-clustering
Jun 15, 2026
Merged

refactor: document strict vs. lenient content-item semantics in convertMapToCallToolResult#7571
lpcox merged 2 commits into
mainfrom
copilot/refactor-semantic-function-clustering

Conversation

Copilot AI commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

From a semantic function clustering analysis, two refactoring items were identified for MCP content normalization. This PR addresses them.

Changes

  • Documentation (mcp/tool_result.go) — Added a // Note: comment block in convertMapToCallToolResult explaining why the inline []interface{} switch must not be replaced with mcpresult.NormalizeContentItems:

    // Note: This switch intentionally returns an error when a non-map item is encountered
    // (strict semantics), unlike mcpresult.NormalizeContentItems which silently skips
    // non-map items (lenient semantics). The strict behavior here is required because this
    // function produces SDK-valid CallToolResult values...
    // Do NOT replace this switch with a call to mcpresult.NormalizeContentItems — the
    // two have deliberately different error-handling semantics.
  • Structural refactor (not done — blocked) — Import graph audit confirmed mcp already imports difc, and difc is a caller of mcpresult. Merging mcpresult into mcp would introduce the cycle mcp → difc → mcp. Consolidation is deferred until the dependency is broken.

GitHub Advanced Security started work on behalf of lpcox June 15, 2026 13:39 View session
GitHub Advanced Security finished work on behalf of lpcox June 15, 2026 13:40
Adds a Note comment explaining why convertMapToCallToolResult uses strict
error-on-invalid-type semantics (returning an error with index context) rather
than calling mcpresult.NormalizeContentItems, which silently skips non-map items
for lenient callers (rate-limit detection, path labelling).

This prevents future contributors from inadvertently collapsing the two code paths
and changing the strict-vs-lenient contract.

The import-graph audit confirms consolidating mcpresult into mcp is NOT safe:
mcp already imports difc, so moving mcpresult there would create the cycle
mcp → difc → mcp.

Closes #7543
Copilot AI changed the title [WIP] Refactor semantic function clustering analysis code refactor: document strict vs. lenient content-item semantics in convertMapToCallToolResult Jun 15, 2026
Copilot finished work on behalf of lpcox June 15, 2026 13:44
Copilot AI requested a review from lpcox June 15, 2026 13:44
@lpcox lpcox marked this pull request as ready for review June 15, 2026 13:45
Copilot AI review requested due to automatic review settings June 15, 2026 13:45

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.

Pull request overview

This PR clarifies (in-code) the intentional semantic difference between strict and lenient MCP content-item normalization in convertMapToCallToolResult, preventing an incorrect future refactor to mcpresult.NormalizeContentItems that would change error-handling behavior.

Changes:

  • Added an explicit // Note: comment documenting why convertMapToCallToolResult must remain strict (error on non-map items) rather than using the lenient NormalizeContentItems helper (skips non-map items).
Show a summary per file
File Description
internal/mcp/tool_result.go Documents strict vs. lenient handling of malformed content items to preserve SDK-valid CallToolResult behavior.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 1/1 changed files
  • Comments generated: 0

GitHub Advanced Security started work on behalf of lpcox June 15, 2026 13:47 View session
GitHub Advanced Security finished work on behalf of lpcox June 15, 2026 13:49
@lpcox lpcox merged commit b369530 into main Jun 15, 2026
40 checks passed
@lpcox lpcox deleted the copilot/refactor-semantic-function-clustering branch June 15, 2026 14:33
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.

3 participants