#!/usr/bin/env node import { spawn } from "node:child_process"; import fs from "node:fs"; import path from "node:path"; function resolveWorkspaceDir() { const workspaceDir = process.env.COPILOT_MCP_FILESYSTEM_ROOT ? path.resolve(process.env.COPILOT_MCP_FILESYSTEM_ROOT) : process.cwd(); if (!fs.existsSync(workspaceDir)) { throw new Error(`Filesystem MCP workspace does not exist: ${workspaceDir}`); } if (!fs.statSync(workspaceDir).isDirectory()) { throw new Error(`Filesystem MCP workspace is not a directory: ${workspaceDir}`); } return workspaceDir; } function main() { const workspaceDir = resolveWorkspaceDir(); const dockerArgs = [ "run", "-i", "--rm", "--mount", `type=bind,src=${workspaceDir},dst=/projects/workspace`, "mcp/filesystem", "/projects/workspace", ]; const child = spawn("docker", dockerArgs, { stdio: "inherit", windowsHide: true, }); child.on("error", (error) => { console.error(`Failed to start Docker for the filesystem MCP server: ${error.message}`); process.exit(1); }); for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"]) { process.on(signal, () => { if (!child.killed) { child.kill(signal); } }); } child.on("exit", (code, signal) => { if (signal) { console.error(`Filesystem MCP server exited with signal ${signal}`); process.exit(1); } process.exit(code ?? 0); }); } main();