Skip to main content
Glama
qckfx

Node.js Debugger MCP Server

by qckfx

start_node_process

Start a Node.js process with debugging enabled to run scripts and manage execution for debugging purposes.

Instructions

Start a Node.js process with debugging enabled

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scriptYesPath to the Node.js script to run
argsNoArguments to pass to the script
cwdNoWorking directory (optional)

Implementation Reference

  • The primary handler function that implements the 'start_node_process' tool. Validates the script path, finds an available debug port, spawns a Node.js process using 'spawn' with --inspect-brk, registers it in managedProcesses, sets up exit cleanup, and returns a success or error message.
    private async startNodeProcess(args: { script: string; args?: string[]; cwd?: string }) {
      const workingDir = args.cwd || process.cwd();
      const scriptPath = resolve(workingDir, args.script);
      
      // Validate script exists
      if (!existsSync(scriptPath)) {
        return {
          content: [{
            type: "text",
            text: `Script not found: ${scriptPath}`,
          }],
          isError: true,
        };
      }
      
      // Find available port
      const port = await this.findAvailablePort();
      const nodeArgs = [`--inspect-brk=${port}`, args.script, ...(args.args || [])];
      
      try {
        const child = spawn("node", nodeArgs, {
          cwd: args.cwd || process.cwd(),
          stdio: ["pipe", "pipe", "pipe"],
          detached: false,
        });
    
        if (!child.pid) {
          throw new Error("Failed to start process");
        }
    
        const managedProcess: ManagedProcess = {
          pid: child.pid,
          port,
          command: "node",
          args: nodeArgs,
          process: child,
          startTime: new Date(),
          scriptPath,
        };
        
        this.usedPorts.add(port);
    
        this.managedProcesses.set(child.pid, managedProcess);
    
        child.on("exit", (code) => {
          if (child.pid) {
            const process = this.managedProcesses.get(child.pid);
            if (process) {
              this.usedPorts.delete(process.port);
              this.managedProcesses.delete(child.pid);
              // Clean up debug session if it was connected to this process
              if (this.debugSession.port === process.port) {
                this.debugSession = { connected: false };
              }
            }
          }
        });
    
        return {
          content: [
            {
              type: "text",
              text: `Started Node.js process with PID ${child.pid} on debug port ${port}`,
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `Error starting process: ${error}`,
            },
          ],
          isError: true,
        };
      }
    }
  • The input schema for the 'start_node_process' tool, defining the expected parameters: 'script' (required string), 'args' (optional string array), 'cwd' (optional string).
    inputSchema: {
      type: "object",
      properties: {
        script: { type: "string", description: "Path to the Node.js script to run" },
        args: { type: "array", items: { type: "string" }, description: "Arguments to pass to the script" },
        cwd: { type: "string", description: "Working directory (optional)" }
      },
      required: ["script"],
    },
  • src/index.ts:144-156 (registration)
    Registration of the 'start_node_process' tool in the ListToolsRequestSchema response, including name, description, and input schema.
    {
      name: "start_node_process",
      description: "Start a Node.js process with debugging enabled",
      inputSchema: {
        type: "object",
        properties: {
          script: { type: "string", description: "Path to the Node.js script to run" },
          args: { type: "array", items: { type: "string" }, description: "Arguments to pass to the script" },
          cwd: { type: "string", description: "Working directory (optional)" }
        },
        required: ["script"],
      },
    },
  • src/index.ts:244-245 (registration)
    Dispatch case in the CallToolRequestSchema handler that routes calls to the startNodeProcess handler.
    case "start_node_process":
      return await this.startNodeProcess(args as { script: string; args?: string[]; cwd?: string });
  • Helper method used by startNodeProcess to dynamically find an available debug port starting from 9229.
    private async findAvailablePort(): Promise<number> {
      let port = this.nextPort;
      while (this.usedPorts.has(port) || !(await this.isPortAvailable(port))) {
        port++;
      }
      this.nextPort = port + 1;
      return port;
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/qckfx/node-debugger-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server