25 lines
678 B
TypeScript
25 lines
678 B
TypeScript
import { spawn } from "child_process";
|
|
import { join } from "path";
|
|
import type { CliParsedArgs, CliResult, CliRunOptions } from "../types.js";
|
|
|
|
export async function handleMcpCommand(
|
|
parsed: CliParsedArgs,
|
|
options: CliRunOptions
|
|
): Promise<CliResult> {
|
|
const appRoot = options.appRoot || process.cwd();
|
|
const serverPath = join(appRoot, "src", "server.ts");
|
|
|
|
console.error("启动 MCP Server on stdio...");
|
|
const child = spawn("bun", ["run", serverPath], {
|
|
stdio: "inherit",
|
|
cwd: appRoot,
|
|
env: process.env,
|
|
});
|
|
|
|
await new Promise<void>((resolve) => {
|
|
child.on("exit", () => resolve());
|
|
});
|
|
|
|
return { stdout: "", stderr: "", exitCode: 0 };
|
|
}
|