From a8a2492f98400647ec81990da436b67e7b82bdb1 Mon Sep 17 00:00:00 2001 From: Steffan Date: Sun, 1 Nov 2026 16:49:30 +0100 Subject: [PATCH 1/4] [Server] Use compact JSON in result formatters --- .../Formatter/PromptResultFormatter.php | 2 +- .../Formatter/ResourceResultFormatter.php | 4 ++-- src/Capability/Formatter/ToolResultFormatter.php | 2 +- .../snapshots/HttpClientCommunicationTest.txt | 12 ++---------- .../snapshots/StdioClientCommunicationTest.txt | 12 ++---------- .../snapshots/StdioDiscoveryCalculatorTest.txt | 5 +---- .../snapshots/StdioElicitationTest-answered.txt | 15 ++------------- .../snapshots/StdioElicitationTest-defaults.txt | 15 ++------------- .../Stdio/snapshots/StdioRootsTest.txt | 15 +-------------- ...ools_call-schedule_event_all_day_reminder.json | 2 +- ...t-tools_call-schedule_event_high_priority.json | 2 +- ...st-tools_call-schedule_event_low_priority.json | 2 +- ...ols_call-schedule_event_meeting_with_time.json | 2 +- ...fileTest-resources_read-read_user_id_list.json | 2 +- ...Test-resources_read-read_user_profile_101.json | 2 +- ...Test-resources_read-read_user_profile_102.json | 2 +- ...ryUserProfileTest-tools_call-send_welcome.json | 2 +- ...eTest-tools_call-test_tool_without_params.json | 2 +- ...maShowcaseTest-tools_call-calculate_range.json | 2 +- ...SchemaShowcaseTest-tools_call-format_text.json | 2 +- ...maShowcaseTest-tools_call-generate_config.json | 2 +- ...SchemaShowcaseTest-tools_call-manage_list.json | 2 +- ...emaShowcaseTest-tools_call-schedule_event.json | 2 +- ...aShowcaseTest-tools_call-validate_profile.json | 2 +- ...ciesTest-resources_read-read_system_stats.json | 2 +- ...ustomDependenciesTest-tools_call-add_task.json | 2 +- ...DependenciesTest-tools_call-complete_task.json | 2 +- ...CalculatorTest-resources_read-read_config.json | 2 +- ...yCalculatorTest-tools_call-update_setting.json | 2 +- ...riablesTest-tools_call-process_data_debug.json | 2 +- ...ablesTest-tools_call-process_data_default.json | 2 +- ...esTest-tools_call-process_data_production.json | 2 +- ...Test-resources_read-read_item_123_details.json | 2 +- ...Test-resources_read-read_item_ABC_details.json | 2 +- 34 files changed, 39 insertions(+), 93 deletions(-) diff --git a/src/Capability/Formatter/PromptResultFormatter.php b/src/Capability/Formatter/PromptResultFormatter.php index 30dc2b1c7..76bd5328c 100644 --- a/src/Capability/Formatter/PromptResultFormatter.php +++ b/src/Capability/Formatter/PromptResultFormatter.php @@ -173,7 +173,7 @@ private function formatContent(mixed $content, ?int $index = null): TextContent| return new TextContent($stringContent); } - $jsonContent = json_encode($content, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE | \JSON_THROW_ON_ERROR); + $jsonContent = json_encode($content, \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE | \JSON_THROW_ON_ERROR); return new TextContent($jsonContent); } diff --git a/src/Capability/Formatter/ResourceResultFormatter.php b/src/Capability/Formatter/ResourceResultFormatter.php index 80d45d267..9167356f2 100644 --- a/src/Capability/Formatter/ResourceResultFormatter.php +++ b/src/Capability/Formatter/ResourceResultFormatter.php @@ -155,7 +155,7 @@ public function format(mixed $readResult, string $uri, ?string $mimeType = null, if ($mimeType && (str_contains(strtolower($mimeType), 'json') || 'application/json' === $mimeType)) { try { - $jsonString = json_encode($readResult, \JSON_THROW_ON_ERROR | \JSON_PRETTY_PRINT); + $jsonString = json_encode($readResult, \JSON_THROW_ON_ERROR); return [new TextResourceContents($uri, $mimeType, $jsonString, $meta)]; } catch (\JsonException $e) { @@ -164,7 +164,7 @@ public function format(mixed $readResult, string $uri, ?string $mimeType = null, } try { - $jsonString = json_encode($readResult, \JSON_THROW_ON_ERROR | \JSON_PRETTY_PRINT); + $jsonString = json_encode($readResult, \JSON_THROW_ON_ERROR); $mimeType = $mimeType ?? 'application/json'; return [new TextResourceContents($uri, $mimeType, $jsonString, $meta)]; diff --git a/src/Capability/Formatter/ToolResultFormatter.php b/src/Capability/Formatter/ToolResultFormatter.php index c2c0a5b06..e8aa92773 100644 --- a/src/Capability/Formatter/ToolResultFormatter.php +++ b/src/Capability/Formatter/ToolResultFormatter.php @@ -97,7 +97,7 @@ public function format(mixed $toolExecutionResult): array $jsonResult = json_encode( $toolExecutionResult, - \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE | \JSON_THROW_ON_ERROR | \JSON_INVALID_UTF8_SUBSTITUTE + \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE | \JSON_THROW_ON_ERROR | \JSON_INVALID_UTF8_SUBSTITUTE ); return [new TextContent($jsonResult)]; diff --git a/tests/Integration/ClientExamples/Http/snapshots/HttpClientCommunicationTest.txt b/tests/Integration/ClientExamples/Http/snapshots/HttpClientCommunicationTest.txt index 41cfb2a82..f8a9ddc6e 100644 --- a/tests/Integration/ClientExamples/Http/snapshots/HttpClientCommunicationTest.txt +++ b/tests/Integration/ClientExamples/Http/snapshots/HttpClientCommunicationTest.txt @@ -15,11 +15,7 @@ Calling 'run_dataset_quality_checks'... [LOG info] Dataset "sales_transactions_q4" passed automated checks. Result: -{ - "dataset": "sales_transactions_q4", - "status": "passed", - "notes": "No significant integrity issues detected during automated checks." -} +{"dataset":"sales_transactions_q4","status":"passed","notes":"No significant integrity issues detected during automated checks."} Calling 'coordinate_incident_response'... @@ -31,8 +27,4 @@ Calling 'coordinate_incident_response'... [LOG info] Incident triage completed for Database connection pool exhausted Result: -{ - "incident": "Database connection pool exhausted", - "recommended_actions": "Based on the incident analysis, I recommend: 1) Activate the on-call team, 2) Isolate affected systems, 3) Begin root cause analysis, 4) Prepare stakeholder communication.", - "model": "mock-gpt-4" -} +{"incident":"Database connection pool exhausted","recommended_actions":"Based on the incident analysis, I recommend: 1) Activate the on-call team, 2) Isolate affected systems, 3) Begin root cause analysis, 4) Prepare stakeholder communication.","model":"mock-gpt-4"} diff --git a/tests/Integration/ClientExamples/Stdio/snapshots/StdioClientCommunicationTest.txt b/tests/Integration/ClientExamples/Stdio/snapshots/StdioClientCommunicationTest.txt index 9ea976212..7cb89221f 100644 --- a/tests/Integration/ClientExamples/Stdio/snapshots/StdioClientCommunicationTest.txt +++ b/tests/Integration/ClientExamples/Stdio/snapshots/StdioClientCommunicationTest.txt @@ -15,11 +15,7 @@ Calling 'run_dataset_quality_checks'... [LOG info] Dataset "customer_orders_2024" passed automated checks. Result: -{ - "dataset": "customer_orders_2024", - "status": "passed", - "notes": "No significant integrity issues detected during automated checks." -} +{"dataset":"customer_orders_2024","status":"passed","notes":"No significant integrity issues detected during automated checks."} Calling 'coordinate_incident_response'... @@ -31,8 +27,4 @@ Calling 'coordinate_incident_response'... [LOG info] Incident triage completed for Database connection pool exhausted Result: -{ - "incident": "Database connection pool exhausted", - "recommended_actions": "Based on the incident analysis, I recommend: 1) Activate the on-call team, 2) Isolate affected systems, 3) Begin root cause analysis, 4) Prepare stakeholder communication.", - "model": "mock-gpt-4" -} +{"incident":"Database connection pool exhausted","recommended_actions":"Based on the incident analysis, I recommend: 1) Activate the on-call team, 2) Isolate affected systems, 3) Begin root cause analysis, 4) Prepare stakeholder communication.","model":"mock-gpt-4"} diff --git a/tests/Integration/ClientExamples/Stdio/snapshots/StdioDiscoveryCalculatorTest.txt b/tests/Integration/ClientExamples/Stdio/snapshots/StdioDiscoveryCalculatorTest.txt index 5760d881e..71483c8fa 100644 --- a/tests/Integration/ClientExamples/Stdio/snapshots/StdioDiscoveryCalculatorTest.txt +++ b/tests/Integration/ClientExamples/Stdio/snapshots/StdioDiscoveryCalculatorTest.txt @@ -19,10 +19,7 @@ Available resources: - config://calculator/settings: calculator_config Reading resource 'config://calculator/settings'... - Content: { - "precision": 2, - "allow_negative": true -} + Content: {"precision":2,"allow_negative":true} Mimetype: application/json Disconnecting... Done. diff --git a/tests/Integration/ClientExamples/Stdio/snapshots/StdioElicitationTest-answered.txt b/tests/Integration/ClientExamples/Stdio/snapshots/StdioElicitationTest-answered.txt index 540c7ea91..f4ab0620e 100644 --- a/tests/Integration/ClientExamples/Stdio/snapshots/StdioElicitationTest-answered.txt +++ b/tests/Integration/ClientExamples/Stdio/snapshots/StdioElicitationTest-answered.txt @@ -6,22 +6,11 @@ Calling 'book_restaurant'... [ELICIT] Please provide your reservation details for The Test Kitchen: Party Size [2]: Reservation Date []: Dietary Restrictions [none]: Result: -{ - "status": "confirmed", - "message": "Reservation confirmed at The Test Kitchen for 4 guests on 2026-12-24.", - "booking": { - "party_size": 4, - "date": "2026-12-24", - "dietary": "vegan" - } -} +{"status":"confirmed","message":"Reservation confirmed at The Test Kitchen for 4 guests on 2026-12-24.","booking":{"party_size":4,"date":"2026-12-24","dietary":"vegan"}} Calling 'confirm_action'... [ELICIT] Are you sure you want to: Delete all temporary files? Confirm [false]: Result: -{ - "status": "confirmed", - "message": "Action confirmed: Delete all temporary files" -} +{"status":"confirmed","message":"Action confirmed: Delete all temporary files"} diff --git a/tests/Integration/ClientExamples/Stdio/snapshots/StdioElicitationTest-defaults.txt b/tests/Integration/ClientExamples/Stdio/snapshots/StdioElicitationTest-defaults.txt index 76f6ec608..e9a67f634 100644 --- a/tests/Integration/ClientExamples/Stdio/snapshots/StdioElicitationTest-defaults.txt +++ b/tests/Integration/ClientExamples/Stdio/snapshots/StdioElicitationTest-defaults.txt @@ -6,22 +6,11 @@ Calling 'book_restaurant'... [ELICIT] Please provide your reservation details for The Test Kitchen: Party Size [2]: Reservation Date []: Dietary Restrictions [none]: Result: -{ - "status": "confirmed", - "message": "Reservation confirmed at The Test Kitchen for 2 guests on 2026-12-24.", - "booking": { - "party_size": 2, - "date": "2026-12-24", - "dietary": "none" - } -} +{"status":"confirmed","message":"Reservation confirmed at The Test Kitchen for 2 guests on 2026-12-24.","booking":{"party_size":2,"date":"2026-12-24","dietary":"none"}} Calling 'confirm_action'... [ELICIT] Are you sure you want to: Delete all temporary files? Confirm [false]: Result: -{ - "status": "not_confirmed", - "message": "User did not check the confirmation box." -} +{"status":"not_confirmed","message":"User did not check the confirmation box."} diff --git a/tests/Integration/ClientExamples/Stdio/snapshots/StdioRootsTest.txt b/tests/Integration/ClientExamples/Stdio/snapshots/StdioRootsTest.txt index a4e540b7d..f3daf70b8 100644 --- a/tests/Integration/ClientExamples/Stdio/snapshots/StdioRootsTest.txt +++ b/tests/Integration/ClientExamples/Stdio/snapshots/StdioRootsTest.txt @@ -5,19 +5,6 @@ Calling 'inspect_workspace_roots'... [ROOTS] Server requested the client's list of roots Result: -{ - "status": "ok", - "message": "Client exposed 2 root(s).", - "roots": [ - { - "uri": "file:///home/user/projects/app", - "name": "Application" - }, - { - "uri": "file:///home/user/projects/library", - "name": "Library" - } - ] -} +{"status":"ok","message":"Client exposed 2 root(s).","roots":[{"uri":"file:///home/user/projects/app","name":"Application"},{"uri":"file:///home/user/projects/library","name":"Library"}]} Notifying the server that the roots list changed... diff --git a/tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_all_day_reminder.json b/tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_all_day_reminder.json index 26888e22a..8e32aef45 100644 --- a/tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_all_day_reminder.json +++ b/tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_all_day_reminder.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\n \"success\": true,\n \"message\": \"Event \\\"Project Deadline\\\" scheduled successfully for \\\"2024-12-15\\\".\",\n \"event_details\": {\n \"title\": \"Project Deadline\",\n \"date\": \"2024-12-15\",\n \"type\": \"reminder\",\n \"time\": \"All day\",\n \"priority\": \"High\",\n \"attendees\": [],\n \"invites_will_be_sent\": false\n }\n}" + "text": "{\"success\":true,\"message\":\"Event \\\"Project Deadline\\\" scheduled successfully for \\\"2024-12-15\\\".\",\"event_details\":{\"title\":\"Project Deadline\",\"date\":\"2024-12-15\",\"type\":\"reminder\",\"time\":\"All day\",\"priority\":\"High\",\"attendees\":[],\"invites_will_be_sent\":false}}" } ], "structuredContent": { diff --git a/tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_high_priority.json b/tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_high_priority.json index 23ee2994f..a053989c3 100644 --- a/tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_high_priority.json +++ b/tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_high_priority.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\n \"success\": true,\n \"message\": \"Event \\\"Client Call\\\" scheduled successfully for \\\"2024-12-02\\\".\",\n \"event_details\": {\n \"title\": \"Client Call\",\n \"date\": \"2024-12-02\",\n \"type\": \"call\",\n \"time\": \"14:30\",\n \"priority\": \"High\",\n \"attendees\": [\n \"client@example.com\"\n ],\n \"invites_will_be_sent\": false\n }\n}" + "text": "{\"success\":true,\"message\":\"Event \\\"Client Call\\\" scheduled successfully for \\\"2024-12-02\\\".\",\"event_details\":{\"title\":\"Client Call\",\"date\":\"2024-12-02\",\"type\":\"call\",\"time\":\"14:30\",\"priority\":\"High\",\"attendees\":[\"client@example.com\"],\"invites_will_be_sent\":false}}" } ], "structuredContent": { diff --git a/tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_low_priority.json b/tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_low_priority.json index 369802773..ec0da7b00 100644 --- a/tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_low_priority.json +++ b/tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_low_priority.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\n \"success\": true,\n \"message\": \"Event \\\"Office Party\\\" scheduled successfully for \\\"2024-12-20\\\".\",\n \"event_details\": {\n \"title\": \"Office Party\",\n \"date\": \"2024-12-20\",\n \"type\": \"other\",\n \"time\": \"18:00\",\n \"priority\": \"Low\",\n \"attendees\": [\n \"team@company.com\"\n ],\n \"invites_will_be_sent\": true\n }\n}" + "text": "{\"success\":true,\"message\":\"Event \\\"Office Party\\\" scheduled successfully for \\\"2024-12-20\\\".\",\"event_details\":{\"title\":\"Office Party\",\"date\":\"2024-12-20\",\"type\":\"other\",\"time\":\"18:00\",\"priority\":\"Low\",\"attendees\":[\"team@company.com\"],\"invites_will_be_sent\":true}}" } ], "structuredContent": { diff --git a/tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_meeting_with_time.json b/tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_meeting_with_time.json index cf9d7b1de..4df0e0992 100644 --- a/tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_meeting_with_time.json +++ b/tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_meeting_with_time.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\n \"success\": true,\n \"message\": \"Event \\\"Team Standup\\\" scheduled successfully for \\\"2024-12-01\\\".\",\n \"event_details\": {\n \"title\": \"Team Standup\",\n \"date\": \"2024-12-01\",\n \"type\": \"meeting\",\n \"time\": \"09:00\",\n \"priority\": \"Normal\",\n \"attendees\": [\n \"alice@example.com\",\n \"bob@example.com\"\n ],\n \"invites_will_be_sent\": true\n }\n}" + "text": "{\"success\":true,\"message\":\"Event \\\"Team Standup\\\" scheduled successfully for \\\"2024-12-01\\\".\",\"event_details\":{\"title\":\"Team Standup\",\"date\":\"2024-12-01\",\"type\":\"meeting\",\"time\":\"09:00\",\"priority\":\"Normal\",\"attendees\":[\"alice@example.com\",\"bob@example.com\"],\"invites_will_be_sent\":true}}" } ], "structuredContent": { diff --git a/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-resources_read-read_user_id_list.json b/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-resources_read-read_user_id_list.json index 04c7ae82e..367918f98 100644 --- a/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-resources_read-read_user_id_list.json +++ b/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-resources_read-read_user_id_list.json @@ -3,7 +3,7 @@ { "uri": "user://list/ids", "mimeType": "application/json", - "text": "[\n 101,\n 102,\n 103\n]" + "text": "[101,102,103]" } ] } diff --git a/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-resources_read-read_user_profile_101.json b/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-resources_read-read_user_profile_101.json index 39931e8cb..93f249530 100644 --- a/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-resources_read-read_user_profile_101.json +++ b/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-resources_read-read_user_profile_101.json @@ -3,7 +3,7 @@ { "uri": "user://101/profile", "mimeType": "application/json", - "text": "{\n \"name\": \"Alice\",\n \"email\": \"alice@example.com\",\n \"role\": \"admin\"\n}" + "text": "{\"name\":\"Alice\",\"email\":\"alice@example.com\",\"role\":\"admin\"}" } ] } diff --git a/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-resources_read-read_user_profile_102.json b/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-resources_read-read_user_profile_102.json index c3e1dcf8b..4874eec8f 100644 --- a/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-resources_read-read_user_profile_102.json +++ b/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-resources_read-read_user_profile_102.json @@ -3,7 +3,7 @@ { "uri": "user://102/profile", "mimeType": "application/json", - "text": "{\n \"name\": \"Bob\",\n \"email\": \"bob@example.com\",\n \"role\": \"user\"\n}" + "text": "{\"name\":\"Bob\",\"email\":\"bob@example.com\",\"role\":\"user\"}" } ] } diff --git a/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-tools_call-send_welcome.json b/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-tools_call-send_welcome.json index 299082631..71369ef6a 100644 --- a/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-tools_call-send_welcome.json +++ b/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-tools_call-send_welcome.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\n \"success\": true,\n \"message_sent\": \"Welcome, Alice! Welcome to our platform!\"\n}" + "text": "{\"success\":true,\"message_sent\":\"Welcome, Alice! Welcome to our platform!\"}" } ], "structuredContent": { diff --git a/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-tools_call-test_tool_without_params.json b/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-tools_call-test_tool_without_params.json index d680ebabf..c38b9a6f7 100644 --- a/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-tools_call-test_tool_without_params.json +++ b/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-tools_call-test_tool_without_params.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\n \"success\": true,\n \"message\": \"Test tool without params\"\n}" + "text": "{\"success\":true,\"message\":\"Test tool without params\"}" } ], "structuredContent": { diff --git a/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-calculate_range.json b/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-calculate_range.json index d21488a0f..8fbd39360 100644 --- a/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-calculate_range.json +++ b/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-calculate_range.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\n \"result\": 50,\n \"operation\": \"10 multiply 5\",\n \"precision\": 2,\n \"within_bounds\": true\n}" + "text": "{\"result\":50,\"operation\":\"10 multiply 5\",\"precision\":2,\"within_bounds\":true}" } ], "structuredContent": { diff --git a/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-format_text.json b/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-format_text.json index c14b72a59..8b32bea20 100644 --- a/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-format_text.json +++ b/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-format_text.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\n \"original\": \"Hello World Test\",\n \"formatted\": \"HELLO WORLD TEST\",\n \"length\": 16,\n \"format_applied\": \"uppercase\"\n}" + "text": "{\"original\":\"Hello World Test\",\"formatted\":\"HELLO WORLD TEST\",\"length\":16,\"format_applied\":\"uppercase\"}" } ], "structuredContent": { diff --git a/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-generate_config.json b/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-generate_config.json index 37b4540af..465e11737 100644 --- a/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-generate_config.json +++ b/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-generate_config.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\n \"success\": true,\n \"config\": {\n \"app\": {\n \"name\": \"TestApp\",\n \"env\": \"development\",\n \"debug\": true,\n \"url\": \"https://example.com\",\n \"port\": 8080\n },\n \"generated_at\": \"2025-01-01T00:00:00+00:00\",\n \"version\": \"1.0.0\",\n \"features\": {\n \"logging\": true,\n \"caching\": false,\n \"analytics\": false,\n \"rate_limiting\": false\n }\n },\n \"validation\": {\n \"app_name_valid\": true,\n \"url_valid\": true,\n \"port_in_range\": true\n }\n}" + "text": "{\"success\":true,\"config\":{\"app\":{\"name\":\"TestApp\",\"env\":\"development\",\"debug\":true,\"url\":\"https://example.com\",\"port\":8080},\"generated_at\":\"2025-01-01T00:00:00+00:00\",\"version\":\"1.0.0\",\"features\":{\"logging\":true,\"caching\":false,\"analytics\":false,\"rate_limiting\":false}},\"validation\":{\"app_name_valid\":true,\"url_valid\":true,\"port_in_range\":true}}" } ], "structuredContent": { diff --git a/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-manage_list.json b/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-manage_list.json index 18c414ec1..a3fb23524 100644 --- a/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-manage_list.json +++ b/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-manage_list.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\n \"original_count\": 4,\n \"processed_count\": 4,\n \"action\": \"sort\",\n \"original\": [\n \"apple\",\n \"banana\",\n \"cherry\",\n \"date\"\n ],\n \"processed\": [\n \"apple\",\n \"banana\",\n \"cherry\",\n \"date\"\n ],\n \"stats\": {\n \"average_length\": 5.25,\n \"shortest\": 4,\n \"longest\": 6\n }\n}" + "text": "{\"original_count\":4,\"processed_count\":4,\"action\":\"sort\",\"original\":[\"apple\",\"banana\",\"cherry\",\"date\"],\"processed\":[\"apple\",\"banana\",\"cherry\",\"date\"],\"stats\":{\"average_length\":5.25,\"shortest\":4,\"longest\":6}}" } ], "structuredContent": { diff --git a/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-schedule_event.json b/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-schedule_event.json index f597105df..100d0bbad 100644 --- a/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-schedule_event.json +++ b/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-schedule_event.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\n \"success\": true,\n \"event\": {\n \"id\": \"event_test123456789\",\n \"title\": \"Team Meeting\",\n \"start_time\": \"2025-01-01T00:00:00+00:00\",\n \"end_time\": \"2025-01-01T00:00:00+00:00\",\n \"duration_hours\": 1.5,\n \"priority\": \"high\",\n \"attendees\": [\n \"alice@example.com\",\n \"bob@example.com\"\n ],\n \"created_at\": \"2025-01-01T00:00:00+00:00\"\n },\n \"info\": {\n \"attendee_count\": 2,\n \"is_all_day\": false,\n \"is_future\": false,\n \"timezone_note\": \"Times are in UTC\"\n }\n}" + "text": "{\"success\":true,\"event\":{\"id\":\"event_test123456789\",\"title\":\"Team Meeting\",\"start_time\":\"2025-01-01T00:00:00+00:00\",\"end_time\":\"2025-01-01T00:00:00+00:00\",\"duration_hours\":1.5,\"priority\":\"high\",\"attendees\":[\"alice@example.com\",\"bob@example.com\"],\"created_at\":\"2025-01-01T00:00:00+00:00\"},\"info\":{\"attendee_count\":2,\"is_all_day\":false,\"is_future\":false,\"timezone_note\":\"Times are in UTC\"}}" } ], "structuredContent": { diff --git a/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-validate_profile.json b/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-validate_profile.json index e87f6cbef..fa01ad4bf 100644 --- a/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-validate_profile.json +++ b/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-validate_profile.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\n \"valid\": true,\n \"profile\": {\n \"name\": \"John Doe\",\n \"email\": \"john@example.com\",\n \"age\": 30,\n \"role\": \"user\"\n },\n \"errors\": [],\n \"warnings\": [],\n \"processed_at\": \"2025-01-01 00:00:00\"\n}" + "text": "{\"valid\":true,\"profile\":{\"name\":\"John Doe\",\"email\":\"john@example.com\",\"age\":30,\"role\":\"user\"},\"errors\":[],\"warnings\":[],\"processed_at\":\"2025-01-01 00:00:00\"}" } ], "structuredContent": { diff --git a/tests/Interop/Server/Stdio/snapshots/StdioCustomDependenciesTest-resources_read-read_system_stats.json b/tests/Interop/Server/Stdio/snapshots/StdioCustomDependenciesTest-resources_read-read_system_stats.json index bdea849a0..3773869ca 100644 --- a/tests/Interop/Server/Stdio/snapshots/StdioCustomDependenciesTest-resources_read-read_system_stats.json +++ b/tests/Interop/Server/Stdio/snapshots/StdioCustomDependenciesTest-resources_read-read_system_stats.json @@ -3,7 +3,7 @@ { "uri": "stats://system/overview", "mimeType": "application/json", - "text": "{\n \"total_tasks\": 3,\n \"completed_tasks\": 0,\n \"pending_tasks\": 3,\n \"server_uptime_seconds\": 12345\n}" + "text": "{\"total_tasks\":3,\"completed_tasks\":0,\"pending_tasks\":3,\"server_uptime_seconds\":12345}" } ] } diff --git a/tests/Interop/Server/Stdio/snapshots/StdioCustomDependenciesTest-tools_call-add_task.json b/tests/Interop/Server/Stdio/snapshots/StdioCustomDependenciesTest-tools_call-add_task.json index 193d8b8e6..3a20a4dcd 100644 --- a/tests/Interop/Server/Stdio/snapshots/StdioCustomDependenciesTest-tools_call-add_task.json +++ b/tests/Interop/Server/Stdio/snapshots/StdioCustomDependenciesTest-tools_call-add_task.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\n \"id\": 4,\n \"userId\": \"alice\",\n \"description\": \"Complete the project documentation\",\n \"completed\": false,\n \"createdAt\": \"2025-01-01T00:00:00+00:00\"\n}" + "text": "{\"id\":4,\"userId\":\"alice\",\"description\":\"Complete the project documentation\",\"completed\":false,\"createdAt\":\"2025-01-01T00:00:00+00:00\"}" } ], "structuredContent": { diff --git a/tests/Interop/Server/Stdio/snapshots/StdioCustomDependenciesTest-tools_call-complete_task.json b/tests/Interop/Server/Stdio/snapshots/StdioCustomDependenciesTest-tools_call-complete_task.json index 3e17038bf..13210e82e 100644 --- a/tests/Interop/Server/Stdio/snapshots/StdioCustomDependenciesTest-tools_call-complete_task.json +++ b/tests/Interop/Server/Stdio/snapshots/StdioCustomDependenciesTest-tools_call-complete_task.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\n \"success\": true,\n \"message\": \"Task 1 completed.\"\n}" + "text": "{\"success\":true,\"message\":\"Task 1 completed.\"}" } ], "structuredContent": { diff --git a/tests/Interop/Server/Stdio/snapshots/StdioDiscoveryCalculatorTest-resources_read-read_config.json b/tests/Interop/Server/Stdio/snapshots/StdioDiscoveryCalculatorTest-resources_read-read_config.json index c15d9a8e8..ea4966fb3 100644 --- a/tests/Interop/Server/Stdio/snapshots/StdioDiscoveryCalculatorTest-resources_read-read_config.json +++ b/tests/Interop/Server/Stdio/snapshots/StdioDiscoveryCalculatorTest-resources_read-read_config.json @@ -3,7 +3,7 @@ { "uri": "config://calculator/settings", "mimeType": "application/json", - "text": "{\n \"precision\": 2,\n \"allow_negative\": true\n}" + "text": "{\"precision\":2,\"allow_negative\":true}" } ] } diff --git a/tests/Interop/Server/Stdio/snapshots/StdioDiscoveryCalculatorTest-tools_call-update_setting.json b/tests/Interop/Server/Stdio/snapshots/StdioDiscoveryCalculatorTest-tools_call-update_setting.json index 517865238..e4086f022 100644 --- a/tests/Interop/Server/Stdio/snapshots/StdioDiscoveryCalculatorTest-tools_call-update_setting.json +++ b/tests/Interop/Server/Stdio/snapshots/StdioDiscoveryCalculatorTest-tools_call-update_setting.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\n \"success\": true,\n \"message\": \"Precision updated to 3.\"\n}" + "text": "{\"success\":true,\"message\":\"Precision updated to 3.\"}" } ], "structuredContent": { diff --git a/tests/Interop/Server/Stdio/snapshots/StdioEnvVariablesTest-tools_call-process_data_debug.json b/tests/Interop/Server/Stdio/snapshots/StdioEnvVariablesTest-tools_call-process_data_debug.json index b046832eb..e1756f427 100644 --- a/tests/Interop/Server/Stdio/snapshots/StdioEnvVariablesTest-tools_call-process_data_debug.json +++ b/tests/Interop/Server/Stdio/snapshots/StdioEnvVariablesTest-tools_call-process_data_debug.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\n \"mode\": \"debug\",\n \"processed_input\": \"DEBUG TEST\",\n \"message\": \"Processed in DEBUG mode.\"\n}" + "text": "{\"mode\":\"debug\",\"processed_input\":\"DEBUG TEST\",\"message\":\"Processed in DEBUG mode.\"}" } ], "isError": false, diff --git a/tests/Interop/Server/Stdio/snapshots/StdioEnvVariablesTest-tools_call-process_data_default.json b/tests/Interop/Server/Stdio/snapshots/StdioEnvVariablesTest-tools_call-process_data_default.json index af00a82b6..6d3daf6a3 100644 --- a/tests/Interop/Server/Stdio/snapshots/StdioEnvVariablesTest-tools_call-process_data_default.json +++ b/tests/Interop/Server/Stdio/snapshots/StdioEnvVariablesTest-tools_call-process_data_default.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\n \"mode\": \"default\",\n \"original_input\": \"test data\",\n \"message\": \"Processed in default mode (APP_MODE not recognized or not set).\"\n}" + "text": "{\"mode\":\"default\",\"original_input\":\"test data\",\"message\":\"Processed in default mode (APP_MODE not recognized or not set).\"}" } ], "isError": false, diff --git a/tests/Interop/Server/Stdio/snapshots/StdioEnvVariablesTest-tools_call-process_data_production.json b/tests/Interop/Server/Stdio/snapshots/StdioEnvVariablesTest-tools_call-process_data_production.json index 4f30f8a04..9b14db364 100644 --- a/tests/Interop/Server/Stdio/snapshots/StdioEnvVariablesTest-tools_call-process_data_production.json +++ b/tests/Interop/Server/Stdio/snapshots/StdioEnvVariablesTest-tools_call-process_data_production.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\n \"mode\": \"production\",\n \"processed_input_length\": 15,\n \"message\": \"Processed in PRODUCTION mode (summary only).\"\n}" + "text": "{\"mode\":\"production\",\"processed_input_length\":15,\"message\":\"Processed in PRODUCTION mode (summary only).\"}" } ], "isError": false, diff --git a/tests/Interop/Server/Stdio/snapshots/StdioExplicitRegistrationTest-resources_read-read_item_123_details.json b/tests/Interop/Server/Stdio/snapshots/StdioExplicitRegistrationTest-resources_read-read_item_123_details.json index d3eca519e..f970f9c89 100644 --- a/tests/Interop/Server/Stdio/snapshots/StdioExplicitRegistrationTest-resources_read-read_item_123_details.json +++ b/tests/Interop/Server/Stdio/snapshots/StdioExplicitRegistrationTest-resources_read-read_item_123_details.json @@ -3,7 +3,7 @@ { "uri": "item://123/details", "mimeType": "application/json", - "text": "{\n \"id\": \"123\",\n \"name\": \"Item 123\",\n \"description\": \"Details for item 123 from manual template.\"\n}" + "text": "{\"id\":\"123\",\"name\":\"Item 123\",\"description\":\"Details for item 123 from manual template.\"}" } ] } diff --git a/tests/Interop/Server/Stdio/snapshots/StdioExplicitRegistrationTest-resources_read-read_item_ABC_details.json b/tests/Interop/Server/Stdio/snapshots/StdioExplicitRegistrationTest-resources_read-read_item_ABC_details.json index 6a2dd65fb..239112395 100644 --- a/tests/Interop/Server/Stdio/snapshots/StdioExplicitRegistrationTest-resources_read-read_item_ABC_details.json +++ b/tests/Interop/Server/Stdio/snapshots/StdioExplicitRegistrationTest-resources_read-read_item_ABC_details.json @@ -3,7 +3,7 @@ { "uri": "item://ABC/details", "mimeType": "application/json", - "text": "{\n \"id\": \"ABC\",\n \"name\": \"Item ABC\",\n \"description\": \"Details for item ABC from manual template.\"\n}" + "text": "{\"id\":\"ABC\",\"name\":\"Item ABC\",\"description\":\"Details for item ABC from manual template.\"}" } ] } From cfd22d5e8dc3d45f331e0255498acc433c45b26e Mon Sep 17 00:00:00 2001 From: Christopher Hertel Date: Mon, 2 Nov 2026 23:58:09 +0100 Subject: [PATCH 2/4] [Server] Use compact JSON in TextContent and pin the format in tests --- CHANGELOG.md | 1 + src/Schema/Content/TextContent.php | 2 +- .../snapshots/HttpClientCommunicationTest.txt | 12 ++++++-- .../StdioClientCommunicationTest.txt | 12 ++++++-- .../StdioDiscoveryCalculatorTest.txt | 5 +++- .../StdioElicitationTest-answered.txt | 15 ++++++++-- .../StdioElicitationTest-defaults.txt | 15 ++++++++-- .../Stdio/snapshots/StdioRootsTest.txt | 15 +++++++++- ..._call-schedule_event_all_day_reminder.json | 2 +- ...ols_call-schedule_event_high_priority.json | 2 +- ...ools_call-schedule_event_low_priority.json | 2 +- ...call-schedule_event_meeting_with_time.json | 2 +- ...Test-resources_read-read_user_id_list.json | 2 +- ...-resources_read-read_user_profile_101.json | 2 +- ...-resources_read-read_user_profile_102.json | 2 +- ...erProfileTest-tools_call-send_welcome.json | 2 +- ...t-tools_call-test_tool_without_params.json | 2 +- ...owcaseTest-tools_call-calculate_range.json | 2 +- ...maShowcaseTest-tools_call-format_text.json | 2 +- ...owcaseTest-tools_call-generate_config.json | 2 +- ...maShowcaseTest-tools_call-manage_list.json | 2 +- ...howcaseTest-tools_call-schedule_event.json | 2 +- ...wcaseTest-tools_call-validate_profile.json | 2 +- ...Test-resources_read-read_system_stats.json | 2 +- ...mDependenciesTest-tools_call-add_task.json | 2 +- ...ndenciesTest-tools_call-complete_task.json | 2 +- ...ulatorTest-resources_read-read_config.json | 2 +- ...culatorTest-tools_call-update_setting.json | 2 +- ...lesTest-tools_call-process_data_debug.json | 2 +- ...sTest-tools_call-process_data_default.json | 2 +- ...st-tools_call-process_data_production.json | 2 +- ...-resources_read-read_item_123_details.json | 2 +- ...-resources_read-read_item_ABC_details.json | 2 +- .../Formatter/PromptResultFormatterTest.php | 7 +++++ .../Formatter/ResourceResultFormatterTest.php | 11 ++++++++ .../Formatter/ToolResultFormatterTest.php | 2 +- tests/Unit/Schema/Content/TextContentTest.php | 28 +++++++++++++++++++ 37 files changed, 138 insertions(+), 37 deletions(-) create mode 100644 tests/Unit/Schema/Content/TextContentTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index c3302570e..5b472b7f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ All notable changes to `mcp/sdk` will be documented in this file. * Fix `Session::save()` wiping the other keys of a session that the store failed to read, e.g. when `Psr16SessionStore` hits a cache error: it now returns `false` instead of writing the changed keys alone. * Fix `EnumCompletionProvider` and `ListCompletionProvider` offering all values for the prefix `"0"` instead of only the values that start with it. * Fix tools, prompts and resources sending `content`, `messages` and `contents` as a JSON object instead of an array when the handler returned a non-list array, e.g. the result of `array_filter()`. Named keys in nested results of mixed arrays no longer overwrite each other. +* Tool, prompt and resource results and `TextContent` encode arrays and objects as compact JSON instead of pretty-printed JSON. * Add `Psr6SessionStore` and `Psr6NotificationBus`, which work like `Psr16SessionStore` and `Psr16NotificationBus` over a PSR-6 cache pool. `Builder::setDiscovery()` also accepts a PSR-6 pool as `$cache`. ### Client diff --git a/src/Schema/Content/TextContent.php b/src/Schema/Content/TextContent.php index 54b1cde2a..73a83b415 100644 --- a/src/Schema/Content/TextContent.php +++ b/src/Schema/Content/TextContent.php @@ -40,7 +40,7 @@ public function __construct( public readonly ?Annotations $annotations = null, ) { $this->text = (\is_array($text) || \is_object($text)) - ? json_encode($text, \JSON_PRETTY_PRINT) : (string) $text; + ? json_encode($text) : (string) $text; parent::__construct('text'); } diff --git a/tests/Integration/ClientExamples/Http/snapshots/HttpClientCommunicationTest.txt b/tests/Integration/ClientExamples/Http/snapshots/HttpClientCommunicationTest.txt index f8a9ddc6e..41cfb2a82 100644 --- a/tests/Integration/ClientExamples/Http/snapshots/HttpClientCommunicationTest.txt +++ b/tests/Integration/ClientExamples/Http/snapshots/HttpClientCommunicationTest.txt @@ -15,7 +15,11 @@ Calling 'run_dataset_quality_checks'... [LOG info] Dataset "sales_transactions_q4" passed automated checks. Result: -{"dataset":"sales_transactions_q4","status":"passed","notes":"No significant integrity issues detected during automated checks."} +{ + "dataset": "sales_transactions_q4", + "status": "passed", + "notes": "No significant integrity issues detected during automated checks." +} Calling 'coordinate_incident_response'... @@ -27,4 +31,8 @@ Calling 'coordinate_incident_response'... [LOG info] Incident triage completed for Database connection pool exhausted Result: -{"incident":"Database connection pool exhausted","recommended_actions":"Based on the incident analysis, I recommend: 1) Activate the on-call team, 2) Isolate affected systems, 3) Begin root cause analysis, 4) Prepare stakeholder communication.","model":"mock-gpt-4"} +{ + "incident": "Database connection pool exhausted", + "recommended_actions": "Based on the incident analysis, I recommend: 1) Activate the on-call team, 2) Isolate affected systems, 3) Begin root cause analysis, 4) Prepare stakeholder communication.", + "model": "mock-gpt-4" +} diff --git a/tests/Integration/ClientExamples/Stdio/snapshots/StdioClientCommunicationTest.txt b/tests/Integration/ClientExamples/Stdio/snapshots/StdioClientCommunicationTest.txt index 7cb89221f..9ea976212 100644 --- a/tests/Integration/ClientExamples/Stdio/snapshots/StdioClientCommunicationTest.txt +++ b/tests/Integration/ClientExamples/Stdio/snapshots/StdioClientCommunicationTest.txt @@ -15,7 +15,11 @@ Calling 'run_dataset_quality_checks'... [LOG info] Dataset "customer_orders_2024" passed automated checks. Result: -{"dataset":"customer_orders_2024","status":"passed","notes":"No significant integrity issues detected during automated checks."} +{ + "dataset": "customer_orders_2024", + "status": "passed", + "notes": "No significant integrity issues detected during automated checks." +} Calling 'coordinate_incident_response'... @@ -27,4 +31,8 @@ Calling 'coordinate_incident_response'... [LOG info] Incident triage completed for Database connection pool exhausted Result: -{"incident":"Database connection pool exhausted","recommended_actions":"Based on the incident analysis, I recommend: 1) Activate the on-call team, 2) Isolate affected systems, 3) Begin root cause analysis, 4) Prepare stakeholder communication.","model":"mock-gpt-4"} +{ + "incident": "Database connection pool exhausted", + "recommended_actions": "Based on the incident analysis, I recommend: 1) Activate the on-call team, 2) Isolate affected systems, 3) Begin root cause analysis, 4) Prepare stakeholder communication.", + "model": "mock-gpt-4" +} diff --git a/tests/Integration/ClientExamples/Stdio/snapshots/StdioDiscoveryCalculatorTest.txt b/tests/Integration/ClientExamples/Stdio/snapshots/StdioDiscoveryCalculatorTest.txt index 71483c8fa..5760d881e 100644 --- a/tests/Integration/ClientExamples/Stdio/snapshots/StdioDiscoveryCalculatorTest.txt +++ b/tests/Integration/ClientExamples/Stdio/snapshots/StdioDiscoveryCalculatorTest.txt @@ -19,7 +19,10 @@ Available resources: - config://calculator/settings: calculator_config Reading resource 'config://calculator/settings'... - Content: {"precision":2,"allow_negative":true} + Content: { + "precision": 2, + "allow_negative": true +} Mimetype: application/json Disconnecting... Done. diff --git a/tests/Integration/ClientExamples/Stdio/snapshots/StdioElicitationTest-answered.txt b/tests/Integration/ClientExamples/Stdio/snapshots/StdioElicitationTest-answered.txt index f4ab0620e..540c7ea91 100644 --- a/tests/Integration/ClientExamples/Stdio/snapshots/StdioElicitationTest-answered.txt +++ b/tests/Integration/ClientExamples/Stdio/snapshots/StdioElicitationTest-answered.txt @@ -6,11 +6,22 @@ Calling 'book_restaurant'... [ELICIT] Please provide your reservation details for The Test Kitchen: Party Size [2]: Reservation Date []: Dietary Restrictions [none]: Result: -{"status":"confirmed","message":"Reservation confirmed at The Test Kitchen for 4 guests on 2026-12-24.","booking":{"party_size":4,"date":"2026-12-24","dietary":"vegan"}} +{ + "status": "confirmed", + "message": "Reservation confirmed at The Test Kitchen for 4 guests on 2026-12-24.", + "booking": { + "party_size": 4, + "date": "2026-12-24", + "dietary": "vegan" + } +} Calling 'confirm_action'... [ELICIT] Are you sure you want to: Delete all temporary files? Confirm [false]: Result: -{"status":"confirmed","message":"Action confirmed: Delete all temporary files"} +{ + "status": "confirmed", + "message": "Action confirmed: Delete all temporary files" +} diff --git a/tests/Integration/ClientExamples/Stdio/snapshots/StdioElicitationTest-defaults.txt b/tests/Integration/ClientExamples/Stdio/snapshots/StdioElicitationTest-defaults.txt index e9a67f634..76f6ec608 100644 --- a/tests/Integration/ClientExamples/Stdio/snapshots/StdioElicitationTest-defaults.txt +++ b/tests/Integration/ClientExamples/Stdio/snapshots/StdioElicitationTest-defaults.txt @@ -6,11 +6,22 @@ Calling 'book_restaurant'... [ELICIT] Please provide your reservation details for The Test Kitchen: Party Size [2]: Reservation Date []: Dietary Restrictions [none]: Result: -{"status":"confirmed","message":"Reservation confirmed at The Test Kitchen for 2 guests on 2026-12-24.","booking":{"party_size":2,"date":"2026-12-24","dietary":"none"}} +{ + "status": "confirmed", + "message": "Reservation confirmed at The Test Kitchen for 2 guests on 2026-12-24.", + "booking": { + "party_size": 2, + "date": "2026-12-24", + "dietary": "none" + } +} Calling 'confirm_action'... [ELICIT] Are you sure you want to: Delete all temporary files? Confirm [false]: Result: -{"status":"not_confirmed","message":"User did not check the confirmation box."} +{ + "status": "not_confirmed", + "message": "User did not check the confirmation box." +} diff --git a/tests/Integration/ClientExamples/Stdio/snapshots/StdioRootsTest.txt b/tests/Integration/ClientExamples/Stdio/snapshots/StdioRootsTest.txt index f3daf70b8..a4e540b7d 100644 --- a/tests/Integration/ClientExamples/Stdio/snapshots/StdioRootsTest.txt +++ b/tests/Integration/ClientExamples/Stdio/snapshots/StdioRootsTest.txt @@ -5,6 +5,19 @@ Calling 'inspect_workspace_roots'... [ROOTS] Server requested the client's list of roots Result: -{"status":"ok","message":"Client exposed 2 root(s).","roots":[{"uri":"file:///home/user/projects/app","name":"Application"},{"uri":"file:///home/user/projects/library","name":"Library"}]} +{ + "status": "ok", + "message": "Client exposed 2 root(s).", + "roots": [ + { + "uri": "file:///home/user/projects/app", + "name": "Application" + }, + { + "uri": "file:///home/user/projects/library", + "name": "Library" + } + ] +} Notifying the server that the roots list changed... diff --git a/tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_all_day_reminder.json b/tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_all_day_reminder.json index 8e32aef45..26888e22a 100644 --- a/tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_all_day_reminder.json +++ b/tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_all_day_reminder.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\"success\":true,\"message\":\"Event \\\"Project Deadline\\\" scheduled successfully for \\\"2024-12-15\\\".\",\"event_details\":{\"title\":\"Project Deadline\",\"date\":\"2024-12-15\",\"type\":\"reminder\",\"time\":\"All day\",\"priority\":\"High\",\"attendees\":[],\"invites_will_be_sent\":false}}" + "text": "{\n \"success\": true,\n \"message\": \"Event \\\"Project Deadline\\\" scheduled successfully for \\\"2024-12-15\\\".\",\n \"event_details\": {\n \"title\": \"Project Deadline\",\n \"date\": \"2024-12-15\",\n \"type\": \"reminder\",\n \"time\": \"All day\",\n \"priority\": \"High\",\n \"attendees\": [],\n \"invites_will_be_sent\": false\n }\n}" } ], "structuredContent": { diff --git a/tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_high_priority.json b/tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_high_priority.json index a053989c3..23ee2994f 100644 --- a/tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_high_priority.json +++ b/tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_high_priority.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\"success\":true,\"message\":\"Event \\\"Client Call\\\" scheduled successfully for \\\"2024-12-02\\\".\",\"event_details\":{\"title\":\"Client Call\",\"date\":\"2024-12-02\",\"type\":\"call\",\"time\":\"14:30\",\"priority\":\"High\",\"attendees\":[\"client@example.com\"],\"invites_will_be_sent\":false}}" + "text": "{\n \"success\": true,\n \"message\": \"Event \\\"Client Call\\\" scheduled successfully for \\\"2024-12-02\\\".\",\n \"event_details\": {\n \"title\": \"Client Call\",\n \"date\": \"2024-12-02\",\n \"type\": \"call\",\n \"time\": \"14:30\",\n \"priority\": \"High\",\n \"attendees\": [\n \"client@example.com\"\n ],\n \"invites_will_be_sent\": false\n }\n}" } ], "structuredContent": { diff --git a/tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_low_priority.json b/tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_low_priority.json index ec0da7b00..369802773 100644 --- a/tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_low_priority.json +++ b/tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_low_priority.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\"success\":true,\"message\":\"Event \\\"Office Party\\\" scheduled successfully for \\\"2024-12-20\\\".\",\"event_details\":{\"title\":\"Office Party\",\"date\":\"2024-12-20\",\"type\":\"other\",\"time\":\"18:00\",\"priority\":\"Low\",\"attendees\":[\"team@company.com\"],\"invites_will_be_sent\":true}}" + "text": "{\n \"success\": true,\n \"message\": \"Event \\\"Office Party\\\" scheduled successfully for \\\"2024-12-20\\\".\",\n \"event_details\": {\n \"title\": \"Office Party\",\n \"date\": \"2024-12-20\",\n \"type\": \"other\",\n \"time\": \"18:00\",\n \"priority\": \"Low\",\n \"attendees\": [\n \"team@company.com\"\n ],\n \"invites_will_be_sent\": true\n }\n}" } ], "structuredContent": { diff --git a/tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_meeting_with_time.json b/tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_meeting_with_time.json index 4df0e0992..cf9d7b1de 100644 --- a/tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_meeting_with_time.json +++ b/tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_meeting_with_time.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\"success\":true,\"message\":\"Event \\\"Team Standup\\\" scheduled successfully for \\\"2024-12-01\\\".\",\"event_details\":{\"title\":\"Team Standup\",\"date\":\"2024-12-01\",\"type\":\"meeting\",\"time\":\"09:00\",\"priority\":\"Normal\",\"attendees\":[\"alice@example.com\",\"bob@example.com\"],\"invites_will_be_sent\":true}}" + "text": "{\n \"success\": true,\n \"message\": \"Event \\\"Team Standup\\\" scheduled successfully for \\\"2024-12-01\\\".\",\n \"event_details\": {\n \"title\": \"Team Standup\",\n \"date\": \"2024-12-01\",\n \"type\": \"meeting\",\n \"time\": \"09:00\",\n \"priority\": \"Normal\",\n \"attendees\": [\n \"alice@example.com\",\n \"bob@example.com\"\n ],\n \"invites_will_be_sent\": true\n }\n}" } ], "structuredContent": { diff --git a/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-resources_read-read_user_id_list.json b/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-resources_read-read_user_id_list.json index 367918f98..04c7ae82e 100644 --- a/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-resources_read-read_user_id_list.json +++ b/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-resources_read-read_user_id_list.json @@ -3,7 +3,7 @@ { "uri": "user://list/ids", "mimeType": "application/json", - "text": "[101,102,103]" + "text": "[\n 101,\n 102,\n 103\n]" } ] } diff --git a/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-resources_read-read_user_profile_101.json b/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-resources_read-read_user_profile_101.json index 93f249530..39931e8cb 100644 --- a/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-resources_read-read_user_profile_101.json +++ b/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-resources_read-read_user_profile_101.json @@ -3,7 +3,7 @@ { "uri": "user://101/profile", "mimeType": "application/json", - "text": "{\"name\":\"Alice\",\"email\":\"alice@example.com\",\"role\":\"admin\"}" + "text": "{\n \"name\": \"Alice\",\n \"email\": \"alice@example.com\",\n \"role\": \"admin\"\n}" } ] } diff --git a/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-resources_read-read_user_profile_102.json b/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-resources_read-read_user_profile_102.json index 4874eec8f..c3e1dcf8b 100644 --- a/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-resources_read-read_user_profile_102.json +++ b/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-resources_read-read_user_profile_102.json @@ -3,7 +3,7 @@ { "uri": "user://102/profile", "mimeType": "application/json", - "text": "{\"name\":\"Bob\",\"email\":\"bob@example.com\",\"role\":\"user\"}" + "text": "{\n \"name\": \"Bob\",\n \"email\": \"bob@example.com\",\n \"role\": \"user\"\n}" } ] } diff --git a/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-tools_call-send_welcome.json b/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-tools_call-send_welcome.json index 71369ef6a..299082631 100644 --- a/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-tools_call-send_welcome.json +++ b/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-tools_call-send_welcome.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\"success\":true,\"message_sent\":\"Welcome, Alice! Welcome to our platform!\"}" + "text": "{\n \"success\": true,\n \"message_sent\": \"Welcome, Alice! Welcome to our platform!\"\n}" } ], "structuredContent": { diff --git a/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-tools_call-test_tool_without_params.json b/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-tools_call-test_tool_without_params.json index c38b9a6f7..d680ebabf 100644 --- a/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-tools_call-test_tool_without_params.json +++ b/tests/Interop/Server/Http/snapshots/HttpDiscoveryUserProfileTest-tools_call-test_tool_without_params.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\"success\":true,\"message\":\"Test tool without params\"}" + "text": "{\n \"success\": true,\n \"message\": \"Test tool without params\"\n}" } ], "structuredContent": { diff --git a/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-calculate_range.json b/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-calculate_range.json index 8fbd39360..d21488a0f 100644 --- a/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-calculate_range.json +++ b/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-calculate_range.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\"result\":50,\"operation\":\"10 multiply 5\",\"precision\":2,\"within_bounds\":true}" + "text": "{\n \"result\": 50,\n \"operation\": \"10 multiply 5\",\n \"precision\": 2,\n \"within_bounds\": true\n}" } ], "structuredContent": { diff --git a/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-format_text.json b/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-format_text.json index 8b32bea20..c14b72a59 100644 --- a/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-format_text.json +++ b/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-format_text.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\"original\":\"Hello World Test\",\"formatted\":\"HELLO WORLD TEST\",\"length\":16,\"format_applied\":\"uppercase\"}" + "text": "{\n \"original\": \"Hello World Test\",\n \"formatted\": \"HELLO WORLD TEST\",\n \"length\": 16,\n \"format_applied\": \"uppercase\"\n}" } ], "structuredContent": { diff --git a/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-generate_config.json b/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-generate_config.json index 465e11737..37b4540af 100644 --- a/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-generate_config.json +++ b/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-generate_config.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\"success\":true,\"config\":{\"app\":{\"name\":\"TestApp\",\"env\":\"development\",\"debug\":true,\"url\":\"https://example.com\",\"port\":8080},\"generated_at\":\"2025-01-01T00:00:00+00:00\",\"version\":\"1.0.0\",\"features\":{\"logging\":true,\"caching\":false,\"analytics\":false,\"rate_limiting\":false}},\"validation\":{\"app_name_valid\":true,\"url_valid\":true,\"port_in_range\":true}}" + "text": "{\n \"success\": true,\n \"config\": {\n \"app\": {\n \"name\": \"TestApp\",\n \"env\": \"development\",\n \"debug\": true,\n \"url\": \"https://example.com\",\n \"port\": 8080\n },\n \"generated_at\": \"2025-01-01T00:00:00+00:00\",\n \"version\": \"1.0.0\",\n \"features\": {\n \"logging\": true,\n \"caching\": false,\n \"analytics\": false,\n \"rate_limiting\": false\n }\n },\n \"validation\": {\n \"app_name_valid\": true,\n \"url_valid\": true,\n \"port_in_range\": true\n }\n}" } ], "structuredContent": { diff --git a/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-manage_list.json b/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-manage_list.json index a3fb23524..18c414ec1 100644 --- a/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-manage_list.json +++ b/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-manage_list.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\"original_count\":4,\"processed_count\":4,\"action\":\"sort\",\"original\":[\"apple\",\"banana\",\"cherry\",\"date\"],\"processed\":[\"apple\",\"banana\",\"cherry\",\"date\"],\"stats\":{\"average_length\":5.25,\"shortest\":4,\"longest\":6}}" + "text": "{\n \"original_count\": 4,\n \"processed_count\": 4,\n \"action\": \"sort\",\n \"original\": [\n \"apple\",\n \"banana\",\n \"cherry\",\n \"date\"\n ],\n \"processed\": [\n \"apple\",\n \"banana\",\n \"cherry\",\n \"date\"\n ],\n \"stats\": {\n \"average_length\": 5.25,\n \"shortest\": 4,\n \"longest\": 6\n }\n}" } ], "structuredContent": { diff --git a/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-schedule_event.json b/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-schedule_event.json index 100d0bbad..f597105df 100644 --- a/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-schedule_event.json +++ b/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-schedule_event.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\"success\":true,\"event\":{\"id\":\"event_test123456789\",\"title\":\"Team Meeting\",\"start_time\":\"2025-01-01T00:00:00+00:00\",\"end_time\":\"2025-01-01T00:00:00+00:00\",\"duration_hours\":1.5,\"priority\":\"high\",\"attendees\":[\"alice@example.com\",\"bob@example.com\"],\"created_at\":\"2025-01-01T00:00:00+00:00\"},\"info\":{\"attendee_count\":2,\"is_all_day\":false,\"is_future\":false,\"timezone_note\":\"Times are in UTC\"}}" + "text": "{\n \"success\": true,\n \"event\": {\n \"id\": \"event_test123456789\",\n \"title\": \"Team Meeting\",\n \"start_time\": \"2025-01-01T00:00:00+00:00\",\n \"end_time\": \"2025-01-01T00:00:00+00:00\",\n \"duration_hours\": 1.5,\n \"priority\": \"high\",\n \"attendees\": [\n \"alice@example.com\",\n \"bob@example.com\"\n ],\n \"created_at\": \"2025-01-01T00:00:00+00:00\"\n },\n \"info\": {\n \"attendee_count\": 2,\n \"is_all_day\": false,\n \"is_future\": false,\n \"timezone_note\": \"Times are in UTC\"\n }\n}" } ], "structuredContent": { diff --git a/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-validate_profile.json b/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-validate_profile.json index fa01ad4bf..e87f6cbef 100644 --- a/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-validate_profile.json +++ b/tests/Interop/Server/Http/snapshots/HttpSchemaShowcaseTest-tools_call-validate_profile.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\"valid\":true,\"profile\":{\"name\":\"John Doe\",\"email\":\"john@example.com\",\"age\":30,\"role\":\"user\"},\"errors\":[],\"warnings\":[],\"processed_at\":\"2025-01-01 00:00:00\"}" + "text": "{\n \"valid\": true,\n \"profile\": {\n \"name\": \"John Doe\",\n \"email\": \"john@example.com\",\n \"age\": 30,\n \"role\": \"user\"\n },\n \"errors\": [],\n \"warnings\": [],\n \"processed_at\": \"2025-01-01 00:00:00\"\n}" } ], "structuredContent": { diff --git a/tests/Interop/Server/Stdio/snapshots/StdioCustomDependenciesTest-resources_read-read_system_stats.json b/tests/Interop/Server/Stdio/snapshots/StdioCustomDependenciesTest-resources_read-read_system_stats.json index 3773869ca..bdea849a0 100644 --- a/tests/Interop/Server/Stdio/snapshots/StdioCustomDependenciesTest-resources_read-read_system_stats.json +++ b/tests/Interop/Server/Stdio/snapshots/StdioCustomDependenciesTest-resources_read-read_system_stats.json @@ -3,7 +3,7 @@ { "uri": "stats://system/overview", "mimeType": "application/json", - "text": "{\"total_tasks\":3,\"completed_tasks\":0,\"pending_tasks\":3,\"server_uptime_seconds\":12345}" + "text": "{\n \"total_tasks\": 3,\n \"completed_tasks\": 0,\n \"pending_tasks\": 3,\n \"server_uptime_seconds\": 12345\n}" } ] } diff --git a/tests/Interop/Server/Stdio/snapshots/StdioCustomDependenciesTest-tools_call-add_task.json b/tests/Interop/Server/Stdio/snapshots/StdioCustomDependenciesTest-tools_call-add_task.json index 3a20a4dcd..193d8b8e6 100644 --- a/tests/Interop/Server/Stdio/snapshots/StdioCustomDependenciesTest-tools_call-add_task.json +++ b/tests/Interop/Server/Stdio/snapshots/StdioCustomDependenciesTest-tools_call-add_task.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\"id\":4,\"userId\":\"alice\",\"description\":\"Complete the project documentation\",\"completed\":false,\"createdAt\":\"2025-01-01T00:00:00+00:00\"}" + "text": "{\n \"id\": 4,\n \"userId\": \"alice\",\n \"description\": \"Complete the project documentation\",\n \"completed\": false,\n \"createdAt\": \"2025-01-01T00:00:00+00:00\"\n}" } ], "structuredContent": { diff --git a/tests/Interop/Server/Stdio/snapshots/StdioCustomDependenciesTest-tools_call-complete_task.json b/tests/Interop/Server/Stdio/snapshots/StdioCustomDependenciesTest-tools_call-complete_task.json index 13210e82e..3e17038bf 100644 --- a/tests/Interop/Server/Stdio/snapshots/StdioCustomDependenciesTest-tools_call-complete_task.json +++ b/tests/Interop/Server/Stdio/snapshots/StdioCustomDependenciesTest-tools_call-complete_task.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\"success\":true,\"message\":\"Task 1 completed.\"}" + "text": "{\n \"success\": true,\n \"message\": \"Task 1 completed.\"\n}" } ], "structuredContent": { diff --git a/tests/Interop/Server/Stdio/snapshots/StdioDiscoveryCalculatorTest-resources_read-read_config.json b/tests/Interop/Server/Stdio/snapshots/StdioDiscoveryCalculatorTest-resources_read-read_config.json index ea4966fb3..c15d9a8e8 100644 --- a/tests/Interop/Server/Stdio/snapshots/StdioDiscoveryCalculatorTest-resources_read-read_config.json +++ b/tests/Interop/Server/Stdio/snapshots/StdioDiscoveryCalculatorTest-resources_read-read_config.json @@ -3,7 +3,7 @@ { "uri": "config://calculator/settings", "mimeType": "application/json", - "text": "{\"precision\":2,\"allow_negative\":true}" + "text": "{\n \"precision\": 2,\n \"allow_negative\": true\n}" } ] } diff --git a/tests/Interop/Server/Stdio/snapshots/StdioDiscoveryCalculatorTest-tools_call-update_setting.json b/tests/Interop/Server/Stdio/snapshots/StdioDiscoveryCalculatorTest-tools_call-update_setting.json index e4086f022..517865238 100644 --- a/tests/Interop/Server/Stdio/snapshots/StdioDiscoveryCalculatorTest-tools_call-update_setting.json +++ b/tests/Interop/Server/Stdio/snapshots/StdioDiscoveryCalculatorTest-tools_call-update_setting.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\"success\":true,\"message\":\"Precision updated to 3.\"}" + "text": "{\n \"success\": true,\n \"message\": \"Precision updated to 3.\"\n}" } ], "structuredContent": { diff --git a/tests/Interop/Server/Stdio/snapshots/StdioEnvVariablesTest-tools_call-process_data_debug.json b/tests/Interop/Server/Stdio/snapshots/StdioEnvVariablesTest-tools_call-process_data_debug.json index e1756f427..b046832eb 100644 --- a/tests/Interop/Server/Stdio/snapshots/StdioEnvVariablesTest-tools_call-process_data_debug.json +++ b/tests/Interop/Server/Stdio/snapshots/StdioEnvVariablesTest-tools_call-process_data_debug.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\"mode\":\"debug\",\"processed_input\":\"DEBUG TEST\",\"message\":\"Processed in DEBUG mode.\"}" + "text": "{\n \"mode\": \"debug\",\n \"processed_input\": \"DEBUG TEST\",\n \"message\": \"Processed in DEBUG mode.\"\n}" } ], "isError": false, diff --git a/tests/Interop/Server/Stdio/snapshots/StdioEnvVariablesTest-tools_call-process_data_default.json b/tests/Interop/Server/Stdio/snapshots/StdioEnvVariablesTest-tools_call-process_data_default.json index 6d3daf6a3..af00a82b6 100644 --- a/tests/Interop/Server/Stdio/snapshots/StdioEnvVariablesTest-tools_call-process_data_default.json +++ b/tests/Interop/Server/Stdio/snapshots/StdioEnvVariablesTest-tools_call-process_data_default.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\"mode\":\"default\",\"original_input\":\"test data\",\"message\":\"Processed in default mode (APP_MODE not recognized or not set).\"}" + "text": "{\n \"mode\": \"default\",\n \"original_input\": \"test data\",\n \"message\": \"Processed in default mode (APP_MODE not recognized or not set).\"\n}" } ], "isError": false, diff --git a/tests/Interop/Server/Stdio/snapshots/StdioEnvVariablesTest-tools_call-process_data_production.json b/tests/Interop/Server/Stdio/snapshots/StdioEnvVariablesTest-tools_call-process_data_production.json index 9b14db364..4f30f8a04 100644 --- a/tests/Interop/Server/Stdio/snapshots/StdioEnvVariablesTest-tools_call-process_data_production.json +++ b/tests/Interop/Server/Stdio/snapshots/StdioEnvVariablesTest-tools_call-process_data_production.json @@ -2,7 +2,7 @@ "content": [ { "type": "text", - "text": "{\"mode\":\"production\",\"processed_input_length\":15,\"message\":\"Processed in PRODUCTION mode (summary only).\"}" + "text": "{\n \"mode\": \"production\",\n \"processed_input_length\": 15,\n \"message\": \"Processed in PRODUCTION mode (summary only).\"\n}" } ], "isError": false, diff --git a/tests/Interop/Server/Stdio/snapshots/StdioExplicitRegistrationTest-resources_read-read_item_123_details.json b/tests/Interop/Server/Stdio/snapshots/StdioExplicitRegistrationTest-resources_read-read_item_123_details.json index f970f9c89..d3eca519e 100644 --- a/tests/Interop/Server/Stdio/snapshots/StdioExplicitRegistrationTest-resources_read-read_item_123_details.json +++ b/tests/Interop/Server/Stdio/snapshots/StdioExplicitRegistrationTest-resources_read-read_item_123_details.json @@ -3,7 +3,7 @@ { "uri": "item://123/details", "mimeType": "application/json", - "text": "{\"id\":\"123\",\"name\":\"Item 123\",\"description\":\"Details for item 123 from manual template.\"}" + "text": "{\n \"id\": \"123\",\n \"name\": \"Item 123\",\n \"description\": \"Details for item 123 from manual template.\"\n}" } ] } diff --git a/tests/Interop/Server/Stdio/snapshots/StdioExplicitRegistrationTest-resources_read-read_item_ABC_details.json b/tests/Interop/Server/Stdio/snapshots/StdioExplicitRegistrationTest-resources_read-read_item_ABC_details.json index 239112395..6a2dd65fb 100644 --- a/tests/Interop/Server/Stdio/snapshots/StdioExplicitRegistrationTest-resources_read-read_item_ABC_details.json +++ b/tests/Interop/Server/Stdio/snapshots/StdioExplicitRegistrationTest-resources_read-read_item_ABC_details.json @@ -3,7 +3,7 @@ { "uri": "item://ABC/details", "mimeType": "application/json", - "text": "{\"id\":\"ABC\",\"name\":\"Item ABC\",\"description\":\"Details for item ABC from manual template.\"}" + "text": "{\n \"id\": \"ABC\",\n \"name\": \"Item ABC\",\n \"description\": \"Details for item ABC from manual template.\"\n}" } ] } diff --git a/tests/Unit/Capability/Formatter/PromptResultFormatterTest.php b/tests/Unit/Capability/Formatter/PromptResultFormatterTest.php index 875147809..b89c5eaea 100644 --- a/tests/Unit/Capability/Formatter/PromptResultFormatterTest.php +++ b/tests/Unit/Capability/Formatter/PromptResultFormatterTest.php @@ -123,6 +123,13 @@ public function testFormatRoleContentArray(): void $this->assertSame(Role::User, $result[0]->role); } + public function testFormatArrayContentAsCompactJson(): void + { + $result = (new PromptResultFormatter())->format(['role' => 'user', 'content' => ['key' => ['nested' => 1]]]); + $this->assertInstanceOf(TextContent::class, $result[0]->content); + $this->assertSame('{"key":{"nested":1}}', $result[0]->content->text); + } + public function testFormatTypedTextContentPreservesAnnotations(): void { $result = (new PromptResultFormatter())->format([ diff --git a/tests/Unit/Capability/Formatter/ResourceResultFormatterTest.php b/tests/Unit/Capability/Formatter/ResourceResultFormatterTest.php index 172eff439..7a8847d8e 100644 --- a/tests/Unit/Capability/Formatter/ResourceResultFormatterTest.php +++ b/tests/Unit/Capability/Formatter/ResourceResultFormatterTest.php @@ -46,6 +46,17 @@ public function testFormatResourceContents(): void $this->assertSame([$contents], $result); } + public function testFormatArrayResultAsCompactJson(): void + { + $result = (new ResourceResultFormatter())->format(['key' => ['nested' => 1]], 'test://uri', 'application/json'); + $this->assertInstanceOf(TextResourceContents::class, $result[0]); + $this->assertSame('{"key":{"nested":1}}', $result[0]->text); + + $result = (new ResourceResultFormatter())->format(['key' => ['nested' => 1]], 'test://uri'); + $this->assertInstanceOf(TextResourceContents::class, $result[0]); + $this->assertSame('{"key":{"nested":1}}', $result[0]->text); + } + public function testFormatWithMimeType(): void { $result = (new ResourceResultFormatter())->format('content', 'file://test', 'text/html'); diff --git a/tests/Unit/Capability/Formatter/ToolResultFormatterTest.php b/tests/Unit/Capability/Formatter/ToolResultFormatterTest.php index 8b1c445b2..5efac21cc 100644 --- a/tests/Unit/Capability/Formatter/ToolResultFormatterTest.php +++ b/tests/Unit/Capability/Formatter/ToolResultFormatterTest.php @@ -52,7 +52,7 @@ public function testFormatArrayResult(): void $result = (new ToolResultFormatter())->format(['key' => 'value']); $this->assertCount(1, $result); $this->assertInstanceOf(TextContent::class, $result[0]); - $this->assertStringContainsString('value', $result[0]->text); + $this->assertSame('{"key":"value"}', $result[0]->text); } public function testFormatNullResult(): void diff --git a/tests/Unit/Schema/Content/TextContentTest.php b/tests/Unit/Schema/Content/TextContentTest.php new file mode 100644 index 000000000..8dd74df35 --- /dev/null +++ b/tests/Unit/Schema/Content/TextContentTest.php @@ -0,0 +1,28 @@ +assertSame('{"key":{"nested":1}}', (new TextContent(['key' => ['nested' => 1]]))->text); + } + + public function testObjectIsEncodedAsCompactJson(): void + { + $this->assertSame('{"key":"value"}', (new TextContent((object) ['key' => 'value']))->text); + } +} From a32d0ae0f3a236c2b1a8bb7cbd927843df5d890f Mon Sep 17 00:00:00 2001 From: Christopher Hertel Date: Mon, 2 Nov 2026 23:58:14 +0100 Subject: [PATCH 3/4] [Tests] Keep JSON in snapshots pretty-printed --- .../ClientExamples/ClientExampleTestCase.php | 12 +++++++++++- .../Server/InspectorSnapshotTestCase.php | 18 +++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/tests/Integration/ClientExamples/ClientExampleTestCase.php b/tests/Integration/ClientExamples/ClientExampleTestCase.php index 28432b35d..c70a9e1de 100644 --- a/tests/Integration/ClientExamples/ClientExampleTestCase.php +++ b/tests/Integration/ClientExamples/ClientExampleTestCase.php @@ -66,7 +66,7 @@ public function testOutputMatchesSnapshot(string $input): void $process->getErrorOutput(), )); - $this->assertMatchesSnapshot($this->normalizeOutput($process->getOutput())); + $this->assertMatchesSnapshot($this->normalizeOutput($this->prettyPrintJson($process->getOutput()))); } /** @@ -82,6 +82,16 @@ protected function normalizeOutput(string $output): string return $output; } + // Keeps JSON results readable in snapshots; formatter tests pin the compact wire format. + private function prettyPrintJson(string $output): string + { + return preg_replace_callback('/^(\s*(?:Content: )?)(\{.*\})$/m', static function (array $match): string { + $decoded = json_decode($match[2]); + + return null === $decoded ? $match[0] : $match[1].json_encode($decoded, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE); + }, $output) ?? $output; + } + private function assertMatchesSnapshot(string $output): void { $className = substr(static::class, strrpos(static::class, '\\') + 1); diff --git a/tests/Interop/Server/InspectorSnapshotTestCase.php b/tests/Interop/Server/InspectorSnapshotTestCase.php index a4261fc3b..36bd2275c 100644 --- a/tests/Interop/Server/InspectorSnapshotTestCase.php +++ b/tests/Interop/Server/InspectorSnapshotTestCase.php @@ -97,7 +97,7 @@ public function testOutputMatchesSnapshot( $snapshotFile = $this->getSnapshotFilePath($method, $testName); - $normalizedOutput = $this->normalizeTestOutput($output, $testName); + $normalizedOutput = $this->normalizeTestOutput($this->prettyPrintTextFields($output), $testName); if (!file_exists($snapshotFile)) { file_put_contents($snapshotFile, $normalizedOutput.\PHP_EOL); @@ -116,6 +116,22 @@ protected function normalizeTestOutput(string $output, ?string $testName = null) return $output; } + // Keeps JSON inside `text` readable in snapshots; formatter tests pin the compact wire format. + private function prettyPrintTextFields(string $output): string + { + return preg_replace_callback('/"text": ("(?:[^"\\\\]++|\\\\.)*+")/', static function (array $match): string { + $decoded = json_decode((string) json_decode($match[1])); + + if (!\is_array($decoded) && !\is_object($decoded)) { + return $match[0]; + } + + $pretty = json_encode($decoded, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE); + + return '"text": '.json_encode($pretty, \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE); + }, $output) ?? $output; + } + public static function provideMethods(): array { return [ From edbc65d7a559dec97df993013188c5ecc4683434 Mon Sep 17 00:00:00 2001 From: Christopher Hertel Date: Tue, 3 Nov 2026 00:12:07 +0100 Subject: [PATCH 4/4] [Tests] Share snapshot pretty-printing in PrettyJson helper --- .../ClientExamples/ClientExampleTestCase.php | 12 ++++----- .../Server/InspectorSnapshotTestCase.php | 16 +++++------ tests/Support/PrettyJson.php | 27 +++++++++++++++++++ 3 files changed, 40 insertions(+), 15 deletions(-) create mode 100644 tests/Support/PrettyJson.php diff --git a/tests/Integration/ClientExamples/ClientExampleTestCase.php b/tests/Integration/ClientExamples/ClientExampleTestCase.php index c70a9e1de..3a26e2d06 100644 --- a/tests/Integration/ClientExamples/ClientExampleTestCase.php +++ b/tests/Integration/ClientExamples/ClientExampleTestCase.php @@ -11,6 +11,7 @@ namespace Mcp\Tests\Integration\ClientExamples; +use Mcp\Tests\Support\PrettyJson; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\Process\Process; @@ -82,14 +83,13 @@ protected function normalizeOutput(string $output): string return $output; } - // Keeps JSON results readable in snapshots; formatter tests pin the compact wire format. private function prettyPrintJson(string $output): string { - return preg_replace_callback('/^(\s*(?:Content: )?)(\{.*\})$/m', static function (array $match): string { - $decoded = json_decode($match[2]); - - return null === $decoded ? $match[0] : $match[1].json_encode($decoded, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE); - }, $output) ?? $output; + return preg_replace_callback( + '/^(\s*(?:Content: )?)(\{.*\})$/m', + static fn (array $match): string => $match[1].PrettyJson::format($match[2]), + $output, + ) ?? $output; } private function assertMatchesSnapshot(string $output): void diff --git a/tests/Interop/Server/InspectorSnapshotTestCase.php b/tests/Interop/Server/InspectorSnapshotTestCase.php index 36bd2275c..9595dadbc 100644 --- a/tests/Interop/Server/InspectorSnapshotTestCase.php +++ b/tests/Interop/Server/InspectorSnapshotTestCase.php @@ -13,6 +13,7 @@ use Mcp\Schema\Enum\LoggingLevel; use Mcp\Tests\Interop\NodeTool; +use Mcp\Tests\Support\PrettyJson; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\Process\Process; @@ -116,20 +117,17 @@ protected function normalizeTestOutput(string $output, ?string $testName = null) return $output; } - // Keeps JSON inside `text` readable in snapshots; formatter tests pin the compact wire format. private function prettyPrintTextFields(string $output): string { - return preg_replace_callback('/"text": ("(?:[^"\\\\]++|\\\\.)*+")/', static function (array $match): string { - $decoded = json_decode((string) json_decode($match[1])); + $result = json_decode($output); - if (!\is_array($decoded) && !\is_object($decoded)) { - return $match[0]; + foreach ([...$result->content ?? [], ...$result->contents ?? []] as $item) { + if (isset($item->text)) { + $item->text = PrettyJson::format($item->text); } + } - $pretty = json_encode($decoded, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE); - - return '"text": '.json_encode($pretty, \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE); - }, $output) ?? $output; + return json_encode($result, \JSON_THROW_ON_ERROR); } public static function provideMethods(): array diff --git a/tests/Support/PrettyJson.php b/tests/Support/PrettyJson.php new file mode 100644 index 000000000..2b9bf2a81 --- /dev/null +++ b/tests/Support/PrettyJson.php @@ -0,0 +1,27 @@ +