Repository navigation
[Server] Filter list completions in one pass - #649
Merged
chr-hertel merged 1 commit intoNov 2, 2026
Merged
chr-hertel merged 1 commit into
chr-hertel merged 1 commit into
Conversation
andreybolonin
requested review from
CodeWithKyrian,
Nyholm,
chr-hertel and
soyuka
as code owners
November 2, 2026 06:58
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The by-value loop breaks references in nested content arrays, causing stale objects to be returned if a later JsonSerializable item reassigns them.
1 open issue
What changed in this PR
This PR reduces intermediate array allocations in the PHP MCP SDK’s tool-result formatting and prefix completion paths.
Changes:
- Replaces repeated content-array merges with direct appends and keyed assignments.
- Builds prefix completion results in a single pass.
- Adds tests for nested content keys, object identity, completion order, duplicates, and edge cases.
| File | Description |
|---|---|
| tests/Unit/Capability/Formatter/ToolResultFormatterTest.php | Tests mixed nested content, key handling, and object identity. |
| tests/Unit/Capability/Completion/ListCompletionProviderTest.php | Tests prefix matches, duplicates, missing matches, and zero-prefix behavior. |
| src/Capability/Formatter/ToolResultFormatter.php | Replaces repeated merges with direct insertion. |
| src/Capability/Completion/ListCompletionProvider.php | Replaces filtering and reindexing with one-pass collection. |
Review effort: Balanced
chr-hertel
force-pushed
the
perf/reduce-formatter-completion-allocations
branch
from
November 2, 2026 22:30
1085001 to
839d40b
Compare
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.

Same as #652 for
ListCompletionProvider. The tool formatting part is gone, #656 made that change onmain.