@kya-os/cli
Version:
CLI for MCP-I setup and management
77 lines ⢠3.3 kB
JavaScript
import chalk from "chalk";
import { existsSync, readFileSync } from "fs";
import { join } from "path";
import { showError, showInfo } from "../utils/prompts.js";
/**
* Start development server with hot reloading
*/
export async function dev() {
console.log(chalk.cyan("\nš Starting Development Server\n"));
// Check if we're in a valid XMCP-I project
const packageJsonPath = join(process.cwd(), "package.json");
if (!existsSync(packageJsonPath)) {
showError("No package.json found. Are you in a valid project directory?");
process.exit(1);
}
// Check for mcpi dependency
try {
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
const hasmcpi = packageJson.dependencies?.mcpi ||
packageJson.devDependencies?.mcpi ||
packageJson.dependencies?.["@kya-os/mcp-i"] ||
packageJson.devDependencies?.["@kya-os/mcp-i"] ||
packageJson.dependencies?.["@kya-os/mcpi"] ||
packageJson.devDependencies?.["@kya-os/mcpi"];
if (!hasmcpi) {
showError("This doesn't appear to be an XMCP-I project. Missing mcpi dependency.");
console.log(`\n${chalk.gray("To create a new XMCP-I project:")}`);
console.log(`${chalk.cyan("npx @kya-os/create-mcpi-app my-agent")}`);
process.exit(1);
}
}
catch (error) {
showError("Failed to read package.json");
process.exit(1);
}
// Check for identity
const identityPath = join(process.cwd(), ".mcpi", "identity.json");
if (!existsSync(identityPath)) {
showInfo("No identity found. Run 'mcpi init' to set up identity first.");
console.log(`\n${chalk.gray("Setting up identity...")}`);
// Import and run init command
const { init } = await import("./init.js");
await init({});
console.log(`\n${chalk.gray("Continuing with development server...")}`);
}
// Import and run the compiler from @kya-os/mcp-i
try {
const { compile } = await import("@kya-os/mcp-i");
console.log(`${chalk.gray("Starting MCP-I compiler in watch mode...")}\n`);
// Set NODE_ENV to development to enable watch mode
process.env.NODE_ENV = "development";
// Run compiler (will use watch mode based on NODE_ENV)
await compile();
}
catch (error) {
// If @kya-os/mcp-i is not installed or compiler import fails
if (error.code === "MODULE_NOT_FOUND") {
showError("@kya-os/mcp-i not found. This doesn't appear to be a valid MCP-I project.");
console.log(`\n${chalk.gray("To create a new MCP-I project:")}`);
console.log(`${chalk.cyan("npx @kya-os/create-mcpi-app my-agent")}`);
process.exit(1);
}
console.error(chalk.red("\nā Failed to start development server\n"));
console.error(error?.message || error);
process.exit(1);
}
// Note: The compiler's watch mode will keep running
// Handle process termination
process.on("SIGINT", () => {
console.log(chalk.yellow("\n\nš Stopping development server..."));
process.exit(0);
});
process.on("SIGTERM", () => {
process.exit(0);
});
}
//# sourceMappingURL=dev.js.map