Repository navigation
[Server] Use compact JSON in result formatters - #647
Merged
chr-hertel merged 4 commits intoNov 2, 2026
Merged
Conversation
steffans
requested review from
CodeWithKyrian,
Nyholm,
chr-hertel and
soyuka
as code owners
November 1, 2026 15:57
steffans
force-pushed
the
compact-formatter-json
branch
from
November 1, 2026 16:13
395cc7d to
0c9d664
Compare
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The JSON fallback lacks a regression test asserting exact compact output for untyped array or object content, so restoring pretty-printed JSON would go undetected.
1 open issue
What changed in this PR
This PR makes the server’s tool, prompt, and resource result formatters emit compact JSON, reducing whitespace in content sent to models while preserving the encoded data.
Changes:
- Remove
JSON_PRETTY_PRINTfrom the three result formatters, retaining other encoding options. - Update HTTP and stdio interoperability snapshots to expect compact JSON.
- Update client-example snapshots to match the new output formatting.
| File | Description |
|---|---|
tests/Interop/Server/Stdio/snapshots/StdioExplicitRegistrationTest-resources_read-read_item_ABC_details.json |
Expect compact item ABC details. |
tests/Interop/Server/Stdio/snapshots/StdioExplicitRegistrationTest-resources_read-read_item_123_details.json |
Expect compact item 123 details. |
tests/Interop/Server/Stdio/snapshots/StdioEnvVariablesTest-tools_call-process_data_production.json |
Expect compact production-mode output. |
tests/Interop/Server/Stdio/snapshots/StdioEnvVariablesTest-tools_call-process_data_default.json |
Expect compact default-mode output. |
tests/Interop/Server/Stdio/snapshots/StdioEnvVariablesTest-tools_call-process_data_debug.json |
Expect compact debug-mode output. |
tests/Interop/Server/Stdio/snapshots/StdioDiscoveryCalculatorTest-tools_call-update_setting.json |
Expect compact setting-update output. |
tests/Interop/Server/Stdio/snapshots/StdioDiscoveryCalculatorTest-resources_read-read_config.json |
Expect compact calculator configuration. |
tests/Interop/Server/Stdio/snapshots/StdioCustomDependenciesTest-tools_call-complete_task.json |
Expect compact task-completion output. |
tests/Interop/Server/Stdio/snapshots/StdioCustomDependenciesTest-tools_call-add_task.json |
Expect compact task-creation output. |
tests/Interop/Server/Stdio/snapshots/StdioCustomDependenciesTest-resources_read-read_system_stats.json |
Expect compact system statistics. |
tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-validate_profile.json |
Expect compact profile-validation output. |
tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-schedule_event.json |
Expect compact event-scheduling output. |
tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-manage_list.json |
Expect compact list-processing output. |
tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-generate_config.json |
Expect compact generated configuration. |
tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-format_text.json |
Expect compact text-formatting output. |
tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-calculate_range.json |
Expect compact calculation output. |
tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-tools_call-test_tool_without_params.json |
Expect compact parameterless-tool output. |
tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-tools_call-send_welcome.json |
Expect compact welcome-message output. |
tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-resources_read-read_user_profile_102.json |
Expect compact user 102 profile. |
tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-resources_read-read_user_profile_101.json |
Expect compact user 101 profile. |
tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-resources_read-read_user_id_list.json |
Expect compact user ID array. |
tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_meeting_with_time.json |
Expect compact timed-meeting output. |
tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_low_priority.json |
Expect compact low-priority event output. |
tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_high_priority.json |
Expect compact high-priority event output. |
tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_all_day_reminder.json |
Expect compact all-day reminder output. |
tests/Integration/ClientExamples/Stdio/snapshots/StdioRootsTest.txt |
Expect compact workspace-roots output. |
tests/Integration/ClientExamples/Stdio/snapshots/StdioElicitationTest-defaults.txt |
Expect compact default elicitation results. |
tests/Integration/ClientExamples/Stdio/snapshots/StdioElicitationTest-answered.txt |
Expect compact answered elicitation results. |
tests/Integration/ClientExamples/Stdio/snapshots/StdioDiscoveryCalculatorTest.txt |
Expect compact displayed calculator configuration. |
tests/Integration/ClientExamples/Stdio/snapshots/StdioClientCommunicationTest.txt |
Expect compact stdio communication results. |
tests/Integration/ClientExamples/Http/snapshots/HttpClientCommunicationTest.txt |
Expect compact HTTP communication results. |
src/Capability/Formatter/ToolResultFormatter.php |
Remove pretty-printing from tool JSON output. |
src/Capability/Formatter/ResourceResultFormatter.php |
Remove pretty-printing from both resource JSON branches. |
src/Capability/Formatter/PromptResultFormatter.php |
Remove pretty-printing from the prompt JSON fallback. |
Review effort: Balanced
chr-hertel
previously approved these changes
Nov 2, 2026
chr-hertel
force-pushed
the
compact-formatter-json
branch
from
November 2, 2026 23:22
bc82670 to
edbc65d
Compare
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The new classes in tests/Support/PrettyJson.php and tests/Unit/Schema/Content/TextContentTest.php are missing the class-level @author tags required by AGENTS.md.
1 open issue
1 resolved since last review
Review effort: Balanced
| /** | ||
| * Keeps JSON readable in snapshots; formatter tests pin the compact wire format. | ||
| */ | ||
| final class PrettyJson |
chr-hertel
approved these changes
Nov 2, 2026
chr-hertel
left a comment
Member
There was a problem hiding this comment.
Thanks @steffans - kept the pretty print for snapshots in tests for readability
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.

Use compact JSON instead of pretty-printed JSON from tool, prompt, and resource result formatters, reducing whitespace in content that may be sent to models. Optionally the TextContent class could also be changed to not use pretty-printed JSON.
Motivation and Context
Compact JSON preserves the same data while reducing its size.
How Has This Been Tested?
Breaking Changes
Types of changes
Checklist