diff --git a/src/index.ts b/src/index.ts index 8cc1ef9..ec171ac 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,9 +7,57 @@ import fs from "fs/promises"; import chalk from "chalk"; import ora from "ora"; import ejs from "ejs"; +import os from "os"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); +async function updateClaudeConfig(directory: string, name: string) { + let configDir; + switch (os.platform()) { + case "darwin": + configDir = path.join( + os.homedir(), + "Library", + "Application Support", + "Claude", + ); + break; + case "win32": + configDir = path.join(process.env.APPDATA || "", "Claude"); + break; + default: + return; + } + + const configFile = path.join(configDir, "claude_desktop_config.json"); + + try { + const config = JSON.parse(await fs.readFile(configFile, "utf-8")); + + if (!config.mcpServers) { + config.mcpServers = {}; + } + + if (!config.mcpServers[name]) { + config.mcpServers[name] = { + command: "node", + args: ["index.js"], + }; + } + + await fs.writeFile(configFile, JSON.stringify(config, null, 2)); + console.log( + chalk.green( + "✓ Successfully added MCP server to Claude.app configuration", + ), + ); + } catch { + console.log( + chalk.yellow("Note: Could not update Claude.app configuration"), + ); + } +} + async function createServer(directory: string, options: any = {}) { const questions = [ { @@ -26,6 +74,13 @@ async function createServer(directory: string, options: any = {}) { default: "A Model Context Protocol server", when: !options.description, }, + { + type: "confirm", + name: "installForClaude", + message: "Would you like to install this server for Claude.app?", + default: true, + when: os.platform() === "darwin" || os.platform() === "win32", + }, ]; const answers = await inquirer.prompt(questions); @@ -80,6 +135,10 @@ async function createServer(directory: string, options: any = {}) { spinner.succeed(chalk.green("MCP server created successfully!")); + if (answers.installForClaude) { + await updateClaudeConfig(directory, config.name); + } + // Print next steps console.log("\nNext steps:"); console.log(chalk.cyan(` cd ${directory}`));