Skip to content

Commit 2415160

Browse files
authored
Merge pull request #204 from laravel/dont-overwrite-invalid-json
feat: add robust MCP file configuration writer
2 parents 516c7b9 + 1f899a8 commit 2415160

17 files changed

+1292
-49
lines changed

src/Install/CodeEnvironment/CodeEnvironment.php

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Laravel\Boost\Install\Detection\DetectionStrategyFactory;
1313
use Laravel\Boost\Install\Enums\McpInstallationStrategy;
1414
use Laravel\Boost\Install\Enums\Platform;
15+
use Laravel\Boost\Install\Mcp\FileWriter;
1516

1617
abstract class CodeEnvironment
1718
{
@@ -185,21 +186,9 @@ protected function installFileMcp(string $key, string $command, array $args = []
185186
return false;
186187
}
187188

188-
File::ensureDirectoryExists(dirname($path));
189-
190-
$config = File::exists($path)
191-
? json_decode(File::get($path), true) ?: []
192-
: [];
193-
194-
$mcpKey = $this->mcpConfigKey();
195-
data_set($config, "{$mcpKey}.{$key}", collect([
196-
'command' => $command,
197-
'args' => $args,
198-
'env' => $env,
199-
])->filter()->toArray());
200-
201-
$json = json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
202-
203-
return $json && File::put($path, $json);
189+
return (new FileWriter($path))
190+
->configKey($this->mcpConfigKey())
191+
->addServer($key, $command, $args, $env)
192+
->save();
204193
}
205194
}

0 commit comments

Comments
 (0)