Skip to content

Commit 7ef74d3

Browse files
committed
feat: add robust MCP file configuration writer
Adds FileWriter class that 'intelligently' handles plain JSON files, and JSON5 style files which VS Code supports. - Detects & preserves JSON 5 features (comments, trailing commas) - 'Smart' injects based on existing keys and indents
1 parent 384ffc5 commit 7ef74d3

File tree

15 files changed

+1219
-44
lines changed

15 files changed

+1219
-44
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
{
@@ -186,21 +187,9 @@ protected function installFileMcp(string $key, string $command, array $args = []
186187
return false;
187188
}
188189

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

0 commit comments

Comments
 (0)