Skip to content

Conversation

@Michaelzag
Copy link

@Michaelzag Michaelzag commented Dec 5, 2025

Summary

This PR fixes Issue #9862 - MCP settings UI removes JSON formatting on save.

Problem

The safeWriteJson() utility was using stream-json's Stringer class which only outputs compact/minified JSON, making configuration files like .roo/mcp.json difficult to read and manually edit after being modified through the UI.

Solution

  • Replaced stream-json with json-stream-stringify library which supports streaming pretty-printing via its spaces parameter
  • Added a prettyPrint option to the safeWriteJson() function
  • Updated all MCP configuration write calls to use { prettyPrint: true }
  • Properly handles undefined values by converting them to null for valid JSON serialization (matching the original behavior)

Why json-stream-stringify instead of JSON.stringify?

JSON.stringify() would load the entire object into memory before streaming, defeating the purpose of streaming for large files. json-stream-stringify handles 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 option
  • src/services/mcp/McpHub.ts: Updated all config writes to use { prettyPrint: true }
  • src/core/webview/webviewMessageHandler.ts: Updated project MCP settings to use pretty-printing
  • src/package.json: Added json-stream-stringify dependency

Testing

  • All existing safeWriteJson tests pass
  • Manually verified MCP config files maintain formatting after UI modifications

Fixes #9862


Important

Switches to json-stream-stringify for streaming pretty-printing of MCP config files, enhancing readability.

  • Behavior:
    • Replaces stream-json with json-stream-stringify in safeWriteJson() to support streaming pretty-printing.
    • Adds prettyPrint option to safeWriteJson() for JSON formatting.
    • Updates all MCP config writes in McpHub.ts and webviewMessageHandler.ts to use { prettyPrint: true }.
  • Dependencies:
    • Adds json-stream-stringify to package.json dependencies.
  • Testing:
    • All existing safeWriteJson tests pass.
    • Manually verified MCP config files maintain formatting after UI modifications.

This description was created by Ellipsis for 61eedcf. You can customize this summary. It will automatically update as commits are pushed.

roomote and others added 2 commits December 5, 2025 16:45
- Replace stream-json with json-stream-stringify for true streaming pretty-print
- Add prettyPrint option to safeWriteJson function
- Update all MCP config write calls to use pretty-printing
- Maintains memory efficiency by streaming during formatting

Fixes RooCodeInc#9862
Convert undefined root values to null for valid JSON serialization,
matching the original stream-json implementation's behavior.
@Michaelzag Michaelzag requested review from cte, jr and mrubens as code owners December 5, 2025 16:59
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Dec 5, 2025
@roomote
Copy link
Contributor

roomote bot commented Dec 5, 2025

Rooviewer Clock   See task on Roo Cloud

Review completed - no issues found. The implementation correctly replaces stream-json with json-stream-stringify to enable pretty-printing while maintaining true streaming efficiency and all existing safety guarantees.

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Dec 5, 2025
@hannesrudolph hannesrudolph moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Dec 5, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Dec 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working PR - Needs Preliminary Review size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Status: PR [Needs Prelim Review]

Development

Successfully merging this pull request may close these issues.

[BUG] MCP Settings UI removes JSON formatting on save

3 participants