registerMcpServer

tcmts.cli.mcp.registerMcpServer · #o7rhxkty · term · runs on the server

uses node:fs

Say this process is an MCP server on the codebase (on branch, for client); undone when it exits.

import { serverRecord, writeServerRecord } from "#codebase/tcmts/cli/mcp";
import fs from "node:fs";

export function registerMcpServer(root: string, branch: string | undefined, client?: string) {
  writeServerRecord(root, {
    pid: process.pid,
    ...(branch ? { branch } : {}),
    ...(client ? { client } : {}),
  });
  const gone = () => fs.rmSync(serverRecord(root, process.pid), { force: true });
  process.on("exit", gone);
  for (const s of ["SIGINT", "SIGTERM", "SIGHUP"] as const) process.on(s, () => process.exit(0));
}

uses

used by