Skip to content

[Server] Fix result lists being sent as JSON objects - #656

Merged
chr-hertel merged 1 commit into
modelcontextprotocol:mainfrom
chr-hertel:fix/read-resource-contents-list
Nov 2, 2026
Merged

chr-hertel merged 1 commit into
modelcontextprotocol:mainfrom
chr-hertel:fix/read-resource-contents-list

Conversation

@chr-hertel

@chr-hertel chr-hertel commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Spotted while reviewing #650 & #651, but not caused by them.

  • A tool, prompt or resource handler returning a non-list array, e.g. the result of array_filter(), sent content, messages or contents as a JSON object instead of an array - now re-indexed in jsonSerialize(), like the other list results
  • Named keys in nested results of mixed arrays overwrote each other and lost content - now always appended

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 active review issues remain for the resource-read serialization changes.

No open issues 🎉

What changed in this PR

Fixes resource-read serialization in the PHP MCP SDK so non-list arrays produce JSON arrays and repeated named keys in nested mixed results no longer cause content loss.

Changes:

  • Reindexes contents during serialization and appends nested resource contents in order.
  • Adds regression coverage for non-list keys and updates nested-result assertions.
  • Corrects the serialization return annotation, removes its PHPStan baseline entry, and documents the fixes.
File Description
tests/​Unit/​Schema/​Result/​ReadResourceResultTest.php Tests list serialization for named and sparse numeric keys.
tests/​Unit/​Capability/​Formatter/​ResourceResultFormatterTest.php Verifies flattening preserves all contents and their order.
src/​Schema/​Result/​ReadResourceResult.php Reindexes serialized contents and corrects the return annotation.
src/​Capability/​Formatter/​ResourceResultFormatter.php Appends nested contents without replacing matching named keys.
phpstan-baseline.neon Removes the resolved return-type suppression.
CHANGELOG.md Documents both resource-read fixes.

Review effort: Balanced

Non-list handler results of tools, prompts and resources now serialize as an
array, and named keys in mixed results no longer overwrite each other.
@chr-hertel
chr-hertel force-pushed the fix/read-resource-contents-list branch from 3a33dd8 to 8082a5d Compare November 2, 2026 22:14
@chr-hertel chr-hertel changed the title [Server] Fix contents of a resource read being sent as a JSON object [Server] Fix result lists being sent as JSON objects Nov 2, 2026
@chr-hertel
chr-hertel requested a balanced review from Copilot November 2, 2026 22:16

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 active review issues block the result-serialization and nested-entry preservation fixes.

No open issues 🎉

Review effort: Balanced

@chr-hertel
chr-hertel merged commit 17161fc into modelcontextprotocol:main Nov 2, 2026
28 checks passed
@chr-hertel
chr-hertel deleted the fix/read-resource-contents-list branch November 2, 2026 22:23
@chr-hertel chr-hertel added the Server Issues & PRs related to the Server component label Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Server Issues & PRs related to the Server component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants