| 410 | } |
| 411 | |
| 412 | async function addMcpToConfig(name: string, mcpConfig: ConfigMCPV1.Info, configPath: string) { |
| 413 | let text = "{}" |
| 414 | if (await Filesystem.exists(configPath)) { |
| 415 | text = await Filesystem.readText(configPath) |
| 416 | } |
| 417 | |
| 418 | // Use jsonc-parser to modify while preserving comments |
| 419 | const edits = modify(text, ["mcp", name], mcpConfig, { |
| 420 | formattingOptions: { tabSize: 2, insertSpaces: true }, |
| 421 | }) |
| 422 | const result = applyEdits(text, edits) |
| 423 | |
| 424 | await Filesystem.write(configPath, result) |
| 425 | |
| 426 | return configPath |
| 427 | } |
| 428 | |
| 429 | export const McpAddCommand = effectCmd({ |
| 430 | command: "add [name]", |