@@ -7,9 +7,57 @@ import fs from "fs/promises";
77import chalk from "chalk" ;
88import ora from "ora" ;
99import ejs from "ejs" ;
10+ import os from "os" ;
1011
1112const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
1213
14+ async function updateClaudeConfig ( directory : string , name : string ) {
15+ let configDir ;
16+ switch ( os . platform ( ) ) {
17+ case "darwin" :
18+ configDir = path . join (
19+ os . homedir ( ) ,
20+ "Library" ,
21+ "Application Support" ,
22+ "Claude" ,
23+ ) ;
24+ break ;
25+ case "win32" :
26+ configDir = path . join ( process . env . APPDATA || "" , "Claude" ) ;
27+ break ;
28+ default :
29+ return ;
30+ }
31+
32+ const configFile = path . join ( configDir , "claude_desktop_config.json" ) ;
33+
34+ try {
35+ const config = JSON . parse ( await fs . readFile ( configFile , "utf-8" ) ) ;
36+
37+ if ( ! config . mcpServers ) {
38+ config . mcpServers = { } ;
39+ }
40+
41+ if ( ! config . mcpServers [ name ] ) {
42+ config . mcpServers [ name ] = {
43+ command : "node" ,
44+ args : [ "index.js" ] ,
45+ } ;
46+ }
47+
48+ await fs . writeFile ( configFile , JSON . stringify ( config , null , 2 ) ) ;
49+ console . log (
50+ chalk . green (
51+ "✓ Successfully added MCP server to Claude.app configuration" ,
52+ ) ,
53+ ) ;
54+ } catch {
55+ console . log (
56+ chalk . yellow ( "Note: Could not update Claude.app configuration" ) ,
57+ ) ;
58+ }
59+ }
60+
1361async function createServer ( directory : string , options : any = { } ) {
1462 const questions = [
1563 {
@@ -26,6 +74,13 @@ async function createServer(directory: string, options: any = {}) {
2674 default : "A Model Context Protocol server" ,
2775 when : ! options . description ,
2876 } ,
77+ {
78+ type : "confirm" ,
79+ name : "installForClaude" ,
80+ message : "Would you like to install this server for Claude.app?" ,
81+ default : true ,
82+ when : os . platform ( ) === "darwin" || os . platform ( ) === "win32" ,
83+ } ,
2984 ] ;
3085
3186 const answers = await inquirer . prompt ( questions ) ;
@@ -80,6 +135,10 @@ async function createServer(directory: string, options: any = {}) {
80135
81136 spinner . succeed ( chalk . green ( "MCP server created successfully!" ) ) ;
82137
138+ if ( answers . installForClaude ) {
139+ await updateClaudeConfig ( directory , config . name ) ;
140+ }
141+
83142 // Print next steps
84143 console . log ( "\nNext steps:" ) ;
85144 console . log ( chalk . cyan ( ` cd ${ directory } ` ) ) ;
0 commit comments