Skip to content

Commit 2177d3e

Browse files
committed
fix: tsc during project creation bug
1 parent f281451 commit 2177d3e

File tree

5 files changed

+39
-35
lines changed

5 files changed

+39
-35
lines changed

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mcp-framework",
3-
"version": "0.1.20",
3+
"version": "0.1.21",
44
"description": "Framework for building Model Context Protocol (MCP) servers in Typescript",
55
"type": "module",
66
"author": "Alex Andru <[email protected]>",

src/cli/framework/build.ts

+16-26
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,26 @@ export async function buildFramework() {
1111
const startDir = process.cwd();
1212
process.stderr.write(`Starting search from: ${startDir}\n`);
1313

14-
let projectRoot: string | null = null;
14+
if (process.argv.includes('create')) {
15+
process.stderr.write(`Skipping build for create command\n`);
16+
return;
17+
}
18+
1519
try {
1620
const pkgPath = join(startDir, 'package.json');
17-
const tsConfigPath = join(startDir, 'tsconfig.json');
18-
19-
process.stderr.write(`Checking for package.json at: ${pkgPath}\n`);
20-
const [pkgContent, _tsConfigContent] = await Promise.all([
21-
readFile(pkgPath, 'utf8'),
22-
readFile(tsConfigPath, 'utf8')
23-
]);
24-
21+
const pkgContent = await readFile(pkgPath, 'utf8');
2522
const pkg = JSON.parse(pkgContent);
26-
if (pkg.dependencies?.["mcp-framework"]) {
27-
projectRoot = startDir;
28-
process.stderr.write(`Found MCP project at current directory: ${projectRoot}\n`);
23+
24+
if (!pkg.dependencies?.["mcp-framework"]) {
25+
throw new Error("This directory is not an MCP project (mcp-framework not found in dependencies)");
2926
}
30-
} catch (error) {
31-
process.stderr.write(`Error checking current directory: ${error instanceof Error ? error.message : String(error)}\n`);
32-
}
33-
34-
if (!projectRoot) {
35-
process.stderr.write("Error: Current directory is not an MCP project\n");
36-
throw new Error('Current directory must be an MCP project with mcp-framework as a dependency');
37-
}
38-
39-
try {
40-
process.stderr.write(`Running tsc in ${projectRoot}\n`);
27+
28+
process.stderr.write(`Running tsc in ${startDir}\n`);
4129

4230
const tscCommand = process.platform === 'win32' ? ['npx.cmd', 'tsc'] : ['npx', 'tsc'];
4331

4432
await execa(tscCommand[0], [tscCommand[1]], {
45-
cwd: projectRoot,
33+
cwd: startDir,
4634
stdio: "inherit",
4735
env: {
4836
...process.env,
@@ -51,7 +39,7 @@ export async function buildFramework() {
5139
}
5240
});
5341

54-
const distPath = join(projectRoot, "dist");
42+
const distPath = join(startDir, "dist");
5543
const projectIndexPath = join(distPath, "index.js");
5644
const shebang = "#!/usr/bin/env node\n";
5745

@@ -68,7 +56,7 @@ export async function buildFramework() {
6856

6957
process.stderr.write("Build completed successfully!\n");
7058
} catch (error) {
71-
process.stderr.write(`Build error: ${error instanceof Error ? error.message : String(error)}\n`);
59+
process.stderr.write(`Error: ${error instanceof Error ? error.message : String(error)}\n`);
7260
process.exit(1);
7361
}
7462
}
@@ -80,3 +68,5 @@ if (import.meta.url.startsWith('file:')) {
8068
process.exit(1);
8169
});
8270
}
71+
72+
export default buildFramework;

src/cli/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const program = new Command();
1111
program
1212
.name("mcp")
1313
.description("CLI for managing MCP server projects")
14-
.version("0.1.20");
14+
.version("0.1.21");
1515

1616
program
1717
.command("build")

src/cli/project/create.ts

+19-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { mkdir, writeFile } from "fs/promises";
33
import { join } from "path";
44
import prompts from "prompts";
55
import { generateReadme } from "../templates/readme.js";
6+
import { execa } from "execa";
67

78
export async function createProject(name?: string) {
89
let projectName: string;
@@ -148,15 +149,28 @@ export default ExampleTool;`;
148149
throw new Error("Failed to install dependencies");
149150
}
150151

151-
console.log("Building project...");
152-
const npmBuild = spawnSync("npm", ["run", "build"], {
152+
console.log("Building TypeScript...");
153+
const tscBuild = await execa('npx', ['tsc'], {
154+
cwd: projectDir,
155+
stdio: "inherit",
156+
});
157+
158+
if (tscBuild.exitCode !== 0) {
159+
throw new Error("Failed to build TypeScript");
160+
}
161+
162+
console.log("Adding shebang...");
163+
const mcpBuild = spawnSync("npm", ["run", "build"], {
153164
stdio: "inherit",
154165
shell: true,
155-
env: process.env
166+
env: {
167+
...process.env,
168+
FORCE_COLOR: "1"
169+
}
156170
});
157171

158-
if (npmBuild.status !== 0) {
159-
throw new Error("Failed to build project");
172+
if (mcpBuild.status !== 0) {
173+
throw new Error("Failed to add shebang");
160174
}
161175

162176
console.log(`

0 commit comments

Comments
 (0)