Preserve empty objects in MCP JSON config files#793
Conversation
|
Thanks for submitting a PR! Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface. Pull requests that are abandoned in draft may be closed due to inactivity. |
|
Simplification suggestion: The --- a/src/Install/Mcp/FileWriter.php
+++ b/src/Install/Mcp/FileWriter.php
@@ -406,18 +406,14 @@ protected function hasSingleQuotedStrings(string $content): bool
protected function createNewFile(): bool
{
- $config = $this->baseConfig;
+ $config = (object) $this->baseConfig;
$this->addServersToConfig($config);
return $this->writeJsonConfig($config);
}
- protected function addServersToConfig(array|object &$config): void
+ protected function addServersToConfig(object &$config): void
{
- if (is_array($config)) {
- $config = (object) $config;
- }
-
if (! isset($config->{$this->configKey}) || ! is_object($config->{$this->configKey})) {
$config->{$this->configKey} = new stdClass;
}Verification: All 48 Posted by a Claude Code routine on behalf of @pushpak1300. Generated by Claude Code |
Summary
This fixes plain JSON MCP config updates so existing empty objects are preserved when Boost adds a server entry.
Previously, updating an existing
opencode.jsonthat contained an empty object such as"oauth": {}would rewrite it as"oauth": []. OpenCode validates its config schema on startup, so this prevented OpenCode from loading the config after Boost installed its MCP server entry.The change keeps decoded plain JSON objects as objects while still supporting the existing array-based path used for new config creation.
Benefit to End Users
Users with an existing OpenCode MCP config can install Boost without making their OpenCode configuration invalid. Empty object fields such as
oauthremain valid objects, allowing OpenCode to continue loading normally.Backwards Compatibility
This should not break existing behavior because
json_encodesupports both arrays and decoded objects. New file creation still uses the existing array-based config path, and existing plain JSON files now retain their original object/array shapes more accurately.