Skip to content
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mcp-framework",
"version": "0.1.20",
"version": "0.1.21",
"description": "Framework for building Model Context Protocol (MCP) servers in Typescript",
"type": "module",
"author": "Alex Andru <[email protected]>",
Expand Down
42 changes: 16 additions & 26 deletions src/cli/framework/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,26 @@ export async function buildFramework() {
const startDir = process.cwd();
process.stderr.write(`Starting search from: ${startDir}\n`);

let projectRoot: string | null = null;
if (process.argv.includes('create')) {
process.stderr.write(`Skipping build for create command\n`);
return;
}

try {
const pkgPath = join(startDir, 'package.json');
const tsConfigPath = join(startDir, 'tsconfig.json');

process.stderr.write(`Checking for package.json at: ${pkgPath}\n`);
const [pkgContent, _tsConfigContent] = await Promise.all([
readFile(pkgPath, 'utf8'),
readFile(tsConfigPath, 'utf8')
]);

const pkgContent = await readFile(pkgPath, 'utf8');
const pkg = JSON.parse(pkgContent);
if (pkg.dependencies?.["mcp-framework"]) {
projectRoot = startDir;
process.stderr.write(`Found MCP project at current directory: ${projectRoot}\n`);

if (!pkg.dependencies?.["mcp-framework"]) {
throw new Error("This directory is not an MCP project (mcp-framework not found in dependencies)");
}
} catch (error) {
process.stderr.write(`Error checking current directory: ${error instanceof Error ? error.message : String(error)}\n`);
}

if (!projectRoot) {
process.stderr.write("Error: Current directory is not an MCP project\n");
throw new Error('Current directory must be an MCP project with mcp-framework as a dependency');
}

try {
process.stderr.write(`Running tsc in ${projectRoot}\n`);

process.stderr.write(`Running tsc in ${startDir}\n`);

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

await execa(tscCommand[0], [tscCommand[1]], {
cwd: projectRoot,
cwd: startDir,
stdio: "inherit",
env: {
...process.env,
Expand All @@ -51,7 +39,7 @@ export async function buildFramework() {
}
});

const distPath = join(projectRoot, "dist");
const distPath = join(startDir, "dist");
const projectIndexPath = join(distPath, "index.js");
const shebang = "#!/usr/bin/env node\n";

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

process.stderr.write("Build completed successfully!\n");
} catch (error) {
process.stderr.write(`Build error: ${error instanceof Error ? error.message : String(error)}\n`);
process.stderr.write(`Error: ${error instanceof Error ? error.message : String(error)}\n`);
process.exit(1);
}
}
Expand All @@ -80,3 +68,5 @@ if (import.meta.url.startsWith('file:')) {
process.exit(1);
});
}

export default buildFramework;
2 changes: 1 addition & 1 deletion src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const program = new Command();
program
.name("mcp")
.description("CLI for managing MCP server projects")
.version("0.1.20");
.version("0.1.21");

program
.command("build")
Expand Down
24 changes: 19 additions & 5 deletions src/cli/project/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { mkdir, writeFile } from "fs/promises";
import { join } from "path";
import prompts from "prompts";
import { generateReadme } from "../templates/readme.js";
import { execa } from "execa";

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

console.log("Building project...");
const npmBuild = spawnSync("npm", ["run", "build"], {
console.log("Building TypeScript...");
const tscBuild = await execa('npx', ['tsc'], {
cwd: projectDir,
stdio: "inherit",
});

if (tscBuild.exitCode !== 0) {
throw new Error("Failed to build TypeScript");
}

console.log("Adding shebang...");
const mcpBuild = spawnSync("npm", ["run", "build"], {
stdio: "inherit",
shell: true,
env: process.env
env: {
...process.env,
FORCE_COLOR: "1"
}
});

if (npmBuild.status !== 0) {
throw new Error("Failed to build project");
if (mcpBuild.status !== 0) {
throw new Error("Failed to add shebang");
}

console.log(`
Expand Down