Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add optional skip install param #54

Merged
merged 1 commit into from
Mar 29, 2025
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
1 change: 1 addition & 0 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ program
.option("--http", "use HTTP transport instead of default stdio")
.option("--cors", "enable CORS with wildcard (*) access")
.option("--port <number>", "specify HTTP port (only valid with --http)", (val) => parseInt(val, 10))
.option("--no-install", "skip npm install and build steps")
.action(createProject);

program
Expand Down
73 changes: 44 additions & 29 deletions src/cli/project/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down Expand Up @@ -166,47 +168,60 @@ 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:
1. cd ${projectName}
2. Add more tools using:
mcp add tool <n>
`);
} 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 <n>
`);
}
} catch (error) {
console.error("Error creating project:", error);
process.exit(1);
Expand Down