11import { createRequire } from 'module' ;
22import { spawnSync } from 'child_process' ;
3- import { mkdir , writeFile } from 'fs/promises' ;
4- import { join } from 'path' ;
3+ import { mkdir , readdir , writeFile } from 'fs/promises' ;
4+ import { basename , join } from 'path' ;
55import prompts from 'prompts' ;
66import { generateReadme } from '../templates/readme.js' ;
77import { execa } from 'execa' ;
@@ -49,17 +49,46 @@ export async function createProject(
4949 projectName = name ;
5050 }
5151
52+ const isCurrentDir = name === '.' ;
53+
54+ if ( isCurrentDir ) {
55+ // Derive project name from current directory name
56+ projectName = basename ( process . cwd ( ) )
57+ . toLowerCase ( )
58+ . replace ( / [ ^ a - z 0 - 9 - ] / g, '-' )
59+ . replace ( / ^ - + | - + $ / g, '' )
60+ . replace ( / - { 2 , } / g, '-' ) ;
61+
62+ if ( ! projectName ) {
63+ console . error ( '❌ Error: Could not derive a valid project name from the current directory name' ) ;
64+ console . error ( ' Please rename the directory or specify a project name: mcp create <name>' ) ;
65+ process . exit ( 1 ) ;
66+ }
67+ }
68+
5269 if ( ! projectName ) {
5370 throw new Error ( 'Project name is required' ) ;
5471 }
5572
56- const projectDir = join ( process . cwd ( ) , projectName ) ;
73+ const projectDir = isCurrentDir ? process . cwd ( ) : join ( process . cwd ( ) , projectName ) ;
5774 const srcDir = join ( projectDir , 'src' ) ;
5875 const toolsDir = join ( srcDir , 'tools' ) ;
5976
6077 try {
78+ if ( isCurrentDir ) {
79+ const entries = await readdir ( projectDir ) ;
80+ const conflicts = [ 'package.json' , 'tsconfig.json' , 'src' ] . filter ( f => entries . includes ( f ) ) ;
81+ if ( conflicts . length > 0 ) {
82+ console . error ( `❌ Error: Current directory already contains: ${ conflicts . join ( ', ' ) } ` ) ;
83+ console . error ( ' Please use an empty directory or specify a project name: mcp create <name>' ) ;
84+ process . exit ( 1 ) ;
85+ }
86+ }
87+
6188 console . log ( 'Creating project structure...' ) ;
62- await mkdir ( projectDir ) ;
89+ if ( ! isCurrentDir ) {
90+ await mkdir ( projectDir ) ;
91+ }
6392 await mkdir ( srcDir ) ;
6493 await mkdir ( toolsDir ) ;
6594
@@ -370,10 +399,12 @@ OAUTH_ISSUER=https://auth.example.com
370399✅ Project ${ projectName } created and built successfully with OAuth 2.1!
371400
372401🔐 OAuth Setup Required:
373- 1. cd ${ projectName }
402+ ${ isCurrentDir ? `1. Copy .env.example to .env
403+ 2. Configure your OAuth provider settings in .env
404+ 3. See docs/OAUTH.md for provider-specific setup guides` : `1. cd ${ projectName }
3744052. Copy .env.example to .env
3754063. Configure your OAuth provider settings in .env
376- 4. See docs/OAUTH.md for provider-specific setup guides
407+ 4. See docs/OAUTH.md for provider-specific setup guides` }
377408
378409📖 OAuth Resources:
379410 - Framework docs: https://github.com/QuantGeekDev/mcp-framework/blob/main/docs/OAUTH.md
@@ -385,11 +416,13 @@ OAUTH_ISSUER=https://auth.example.com
385416 } else {
386417 console . log ( `
387418Project ${ projectName } created and built successfully!
388-
419+ ${ isCurrentDir ? `
420+ Add more tools using:
421+ mcp add tool <n>` : `
389422You can now:
3904231. cd ${ projectName }
3914242. Add more tools using:
392- mcp add tool <n>
425+ mcp add tool <n>` }
393426 ` ) ;
394427 }
395428 } else {
@@ -398,26 +431,35 @@ You can now:
398431✅ Project ${ projectName } created successfully with OAuth 2.1 (without dependencies)!
399432
400433Next steps:
401- 1. cd ${ projectName }
434+ ${ isCurrentDir ? `1. Copy .env.example to .env
435+ 2. Configure your OAuth provider settings in .env
436+ 3. Run 'npm install' to install dependencies
437+ 4. Run 'npm run build' to build the project
438+ 5. See docs/OAUTH.md for OAuth setup guides` : `1. cd ${ projectName }
4024392. Copy .env.example to .env
4034403. Configure your OAuth provider settings in .env
4044414. Run 'npm install' to install dependencies
4054425. Run 'npm run build' to build the project
406- 6. See docs/OAUTH.md for OAuth setup guides
443+ 6. See docs/OAUTH.md for OAuth setup guides` }
407444
408445🛠️ Add more tools:
409446 mcp add tool <tool-name>
410447 ` ) ;
411448 } else {
412449 console . log ( `
413450Project ${ projectName } created successfully (without dependencies)!
414-
451+ ${ isCurrentDir ? `
452+ Next steps:
453+ 1. Run 'npm install' to install dependencies
454+ 2. Run 'npm run build' to build the project
455+ 3. Add more tools using:
456+ mcp add tool <n>` : `
415457You can now:
4164581. cd ${ projectName }
4174592. Run 'npm install' to install dependencies
4184603. Run 'npm run build' to build the project
4194614. Add more tools using:
420- mcp add tool <n>
462+ mcp add tool <n>` }
421463 ` ) ;
422464 }
423465 }
0 commit comments