diff --git a/src/cli/index.ts b/src/cli/index.ts index c74c0c2..5167dd6 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -25,6 +25,7 @@ program .option("--http", "use HTTP transport instead of default stdio") .option("--cors", "enable CORS with wildcard (*) access") .option("--port ", "specify HTTP port (only valid with --http)", (val) => parseInt(val, 10)) + .option("--no-install", "skip npm install and build steps") .action(createProject); program diff --git a/src/cli/project/create.ts b/src/cli/project/create.ts index 8ea56e1..61df68f 100644 --- a/src/cli/project/create.ts +++ b/src/cli/project/create.ts @@ -5,8 +5,10 @@ import prompts from "prompts"; import { generateReadme } from "../templates/readme.js"; import { execa } from "execa"; -export async function createProject(name?: string, options?: { http?: boolean, cors?: boolean, port?: number }) { +export async function createProject(name?: string, options?: { http?: boolean, cors?: boolean, port?: number, install?: boolean }) { let projectName: string; + // Default install to true if not specified + const shouldInstall = options?.install !== false; if (!name) { const response = await prompts([ @@ -166,40 +168,41 @@ export default ExampleTool;`; throw new Error("Failed to initialize git repository"); } - console.log("Installing dependencies..."); - const npmInstall = spawnSync("npm", ["install"], { - stdio: "inherit", - shell: true - }); + if (shouldInstall) { + console.log("Installing dependencies..."); + const npmInstall = spawnSync("npm", ["install"], { + stdio: "inherit", + shell: true + }); - if (npmInstall.status !== 0) { - throw new Error("Failed to install dependencies"); - } - - console.log("Building project..."); - const tscBuild = await execa('npx', ['tsc'], { - cwd: projectDir, - stdio: "inherit", - }); + if (npmInstall.status !== 0) { + throw new Error("Failed to install dependencies"); + } - if (tscBuild.exitCode !== 0) { - throw new Error("Failed to build TypeScript"); - } + console.log("Building project..."); + const tscBuild = await execa('npx', ['tsc'], { + cwd: projectDir, + stdio: "inherit", + }); - const mcpBuild = await execa('npx', ['mcp-build'], { - cwd: projectDir, - stdio: "inherit", - env: { - ...process.env, - MCP_SKIP_VALIDATION: "true" + if (tscBuild.exitCode !== 0) { + throw new Error("Failed to build TypeScript"); } - }); - if (mcpBuild.exitCode !== 0) { - throw new Error("Failed to run mcp-build"); - } + const mcpBuild = await execa('npx', ['mcp-build'], { + cwd: projectDir, + stdio: "inherit", + env: { + ...process.env, + MCP_SKIP_VALIDATION: "true" + } + }); + + if (mcpBuild.exitCode !== 0) { + throw new Error("Failed to run mcp-build"); + } - console.log(` + console.log(` Project ${projectName} created and built successfully! You can now: @@ -207,6 +210,18 @@ You can now: 2. Add more tools using: mcp add tool `); + } else { + console.log(` +Project ${projectName} created successfully (without dependencies)! + +You can now: +1. cd ${projectName} +2. Run 'npm install' to install dependencies +3. Run 'npm run build' to build the project +4. Add more tools using: + mcp add tool + `); + } } catch (error) { console.error("Error creating project:", error); process.exit(1);