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

Create desktop config file if it doesn't exist #2

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@modelcontextprotocol/create-server",
"version": "0.2.0",
"version": "0.2.1",
"description": "CLI tool to create new MCP servers",
"license": "MIT",
"author": "Anthropic, PBC (https://anthropic.com)",
Expand Down
31 changes: 19 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env node
import chalk from "chalk";
import { Command } from "commander";
import inquirer from "inquirer";
import { fileURLToPath } from "url";
import path from "path";
import ejs from "ejs";
import fs from "fs/promises";
import chalk from "chalk";
import inquirer from "inquirer";
import ora from "ora";
import ejs from "ejs";
import os from "os";
import path from "path";
import { fileURLToPath } from "url";

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

const config = JSON.parse(await fs.readFile(configFile, "utf-8"));
let config;
try {
config = JSON.parse(await fs.readFile(configFile, "utf-8"));
} catch (err) {
if ((err as NodeJS.ErrnoException).code !== "ENOENT") {
throw err;
}

// File doesn't exist, create initial config
config = {};
await fs.mkdir(path.dirname(configFile), { recursive: true });
}

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

await fs.writeFile(configFile, JSON.stringify(config, null, 2));
console.log(
chalk.green(
"✓ Successfully added MCP server to Claude.app configuration",
),
chalk.green("✓ Successfully added MCP server to Claude.app configuration"),
);
} catch {
console.log(
chalk.yellow("Note: Could not update Claude.app configuration"),
);
console.log(chalk.yellow("Note: Could not update Claude.app configuration"));
}
}

Expand Down