Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.

Commit 837a5c8

Browse files
Merge pull request #2 from modelcontextprotocol/justin/create-config
Create desktop config file if it doesn't exist
2 parents 2f723ba + b35fc4b commit 837a5c8

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@modelcontextprotocol/create-server",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"description": "CLI tool to create new MCP servers",
55
"license": "MIT",
66
"author": "Anthropic, PBC (https://anthropic.com)",

src/index.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/usr/bin/env node
2+
import chalk from "chalk";
23
import { Command } from "commander";
3-
import inquirer from "inquirer";
4-
import { fileURLToPath } from "url";
5-
import path from "path";
4+
import ejs from "ejs";
65
import fs from "fs/promises";
7-
import chalk from "chalk";
6+
import inquirer from "inquirer";
87
import ora from "ora";
9-
import ejs from "ejs";
108
import os from "os";
9+
import path from "path";
10+
import { fileURLToPath } from "url";
1111

1212
const __dirname = path.dirname(fileURLToPath(import.meta.url));
1313
function getClaudeConfigDir(): string {
@@ -38,7 +38,18 @@ async function updateClaudeConfig(name: string, directory: string) {
3838
"claude_desktop_config.json",
3939
);
4040

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+
}
4253

4354
if (!config.mcpServers) {
4455
config.mcpServers = {};
@@ -69,14 +80,10 @@ async function updateClaudeConfig(name: string, directory: string) {
6980

7081
await fs.writeFile(configFile, JSON.stringify(config, null, 2));
7182
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"),
7584
);
7685
} 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"));
8087
}
8188
}
8289

0 commit comments

Comments
 (0)