|
1 | 1 | #!/usr/bin/env node
|
| 2 | +import chalk from "chalk"; |
2 | 3 | import { Command } from "commander";
|
3 |
| -import inquirer from "inquirer"; |
4 |
| -import { fileURLToPath } from "url"; |
5 |
| -import path from "path"; |
| 4 | +import ejs from "ejs"; |
6 | 5 | import fs from "fs/promises";
|
7 |
| -import chalk from "chalk"; |
| 6 | +import inquirer from "inquirer"; |
8 | 7 | import ora from "ora";
|
9 |
| -import ejs from "ejs"; |
10 | 8 | import os from "os";
|
| 9 | +import path from "path"; |
| 10 | +import { fileURLToPath } from "url"; |
11 | 11 |
|
12 | 12 | const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
13 | 13 | function getClaudeConfigDir(): string {
|
@@ -38,7 +38,18 @@ async function updateClaudeConfig(name: string, directory: string) {
|
38 | 38 | "claude_desktop_config.json",
|
39 | 39 | );
|
40 | 40 |
|
41 |
| - const config = JSON.parse(await fs.readFile(configFile, "utf-8")); |
| 41 | + let config; |
| 42 | + try { |
| 43 | + config = JSON.parse(await fs.readFile(configFile, "utf-8")); |
| 44 | + } catch (err) { |
| 45 | + if ((err as NodeJS.ErrnoException).code !== "ENOENT") { |
| 46 | + throw err; |
| 47 | + } |
| 48 | + |
| 49 | + // File doesn't exist, create initial config |
| 50 | + config = {}; |
| 51 | + await fs.mkdir(path.dirname(configFile), { recursive: true }); |
| 52 | + } |
42 | 53 |
|
43 | 54 | if (!config.mcpServers) {
|
44 | 55 | config.mcpServers = {};
|
@@ -69,14 +80,10 @@ async function updateClaudeConfig(name: string, directory: string) {
|
69 | 80 |
|
70 | 81 | await fs.writeFile(configFile, JSON.stringify(config, null, 2));
|
71 | 82 | console.log(
|
72 |
| - chalk.green( |
73 |
| - "✓ Successfully added MCP server to Claude.app configuration", |
74 |
| - ), |
| 83 | + chalk.green("✓ Successfully added MCP server to Claude.app configuration"), |
75 | 84 | );
|
76 | 85 | } catch {
|
77 |
| - console.log( |
78 |
| - chalk.yellow("Note: Could not update Claude.app configuration"), |
79 |
| - ); |
| 86 | + console.log(chalk.yellow("Note: Could not update Claude.app configuration")); |
80 | 87 | }
|
81 | 88 | }
|
82 | 89 |
|
|
0 commit comments