fix: use json-stream-stringify for pretty-printing MCP config files #9864
+48
−50
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.
Summary
This PR fixes Issue #9862 - MCP settings UI removes JSON formatting on save.
Problem
The
safeWriteJson()utility was usingstream-json'sStringerclass which only outputs compact/minified JSON, making configuration files like.roo/mcp.jsondifficult to read and manually edit after being modified through the UI.Solution
stream-jsonwithjson-stream-stringifylibrary which supports streaming pretty-printing via itsspacesparameterprettyPrintoption to thesafeWriteJson()function{ prettyPrint: true }undefinedvalues by converting them tonullfor valid JSON serialization (matching the original behavior)Why
json-stream-stringifyinstead ofJSON.stringify?JSON.stringify()would load the entire object into memory before streaming, defeating the purpose of streaming for large files.json-stream-stringifyhandles indentation during the streaming process itself, maintaining true O(1) memory usage regardless of file size.Changes
src/utils/safeWriteJson.ts: Replaced stream-json with json-stream-stringify, added prettyPrint optionsrc/services/mcp/McpHub.ts: Updated all config writes to use{ prettyPrint: true }src/core/webview/webviewMessageHandler.ts: Updated project MCP settings to use pretty-printingsrc/package.json: Addedjson-stream-stringifydependencyTesting
safeWriteJsontests passFixes #9862
Important
Switches to
json-stream-stringifyfor streaming pretty-printing of MCP config files, enhancing readability.stream-jsonwithjson-stream-stringifyinsafeWriteJson()to support streaming pretty-printing.prettyPrintoption tosafeWriteJson()for JSON formatting.McpHub.tsandwebviewMessageHandler.tsto use{ prettyPrint: true }.json-stream-stringifytopackage.jsondependencies.safeWriteJsontests pass.This description was created by
for 61eedcf. You can customize this summary. It will automatically update as commits are pushed.