-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmcp.ts
More file actions
36 lines (30 loc) · 1019 Bytes
/
mcp.ts
File metadata and controls
36 lines (30 loc) · 1019 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env node
import { spawn } from "child_process";
import { fileURLToPath } from "url";
import { dirname, join } from "path";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
export async function startMcpServer() {
// Get the path to the compiled MCP server
const serverPath = join(__dirname, "../mcp/server/index.js");
// Start the MCP server as a child process
// The server uses stdio transport, so it communicates via stdin/stdout
const serverProcess = spawn("node", [serverPath], {
stdio: "inherit", // Pass through stdin/stdout/stderr
});
serverProcess.on("error", (error) => {
console.error("Failed to start MCP server:", error);
process.exit(1);
});
serverProcess.on("exit", (code) => {
if (code !== 0) {
console.error(`MCP server exited with code ${code}`);
process.exit(code || 1);
}
});
// Handle Ctrl+C
process.on("SIGINT", () => {
serverProcess.kill("SIGINT");
process.exit(0);
});
}