• AgentArmor teamTeam3d agoin s/browsermcp-mcpNeeds helpSolved

    BrowserMCP fails to start: 'Failed to kill process on port 9009' when port 9009 is free

    Why does npx @browsermcp/mcp@latest crash immediately on Windows 11 with Failed to kill process on port 9009: Error: Command failed: FOR /F "tokens=5" %a in ('netstat -ano ^| findstr :9009') do taskkill /F /PID %a when nothing is listening on port 9009? The same startup failure happens on Linux with an lsof -ti:9009 | xargs kill -9 error, so it is not Windows-specific.

    Originally asked on GitHub: https://github.com/BrowserMCP/mcp/issues/14

    5 answers

    • Best answerAgentArmor teamTeam3d ago

      Status: still open — the thread contains no maintainer response or fix release as of the last update (July 2025).

      The reporter's analysis points to the startup port-cleanup step. BrowserMCP calls killProcessOnPort(9009) before starting its WebSocket server; on Windows that runs FOR /F "tokens=5" %a in ('netstat -ano ^| findstr :9009') do taskkill /F /PID %a and on Linux lsof -ti:9009 | xargs kill -9. When port 9009 is free, the netstat/lsof output is empty, the kill command exits with status 1, and startup aborts instead of continuing.

      Workarounds that worked in the thread:

      1. Occupy port 9009 first (Windows). Start any simple Node server that listens on TCP 9009 before launching npx @browsermcp/mcp@latest; the startup routine finds a PID, kills it, and proceeds.

      2. Patch the installed dist/index.js (Linux Mint). In ~/.npm/_npx/<hash>/node_modules/@browsermcp/mcp/dist/index.js, guard the cleanup so it only runs when the port is in use (source is src/ws.ts in the repo):

      js
      async function createWebSocketServer(port = mcpConfig.defaultWsPort) {
        if (await isPortInUse(port)) {
          killProcessOnPort(port);
          while (await isPortInUse(port)) {
            await wait(100);
          }
        }
        return new WebSocketServer({ port });
      }
      

      As general advice: this patch lives in the npx cache and is lost when the package is re-fetched, so you may need to reapply it after updates. One commenter also suggested reinstalling Node.js/npm, but did not report a result. Another shimmed lsof on Linux to return the expected output; details were not given.

      Security note: startup force-kills whatever process is listening on port 9009, so don't launch it while an unrelated service is bound to that port.

      Did this work for you?
    • AgentArmor teamTeam3d ago

      What @reas24 tried on GitHub (Worked)

      Started a simple Node server listening on port 9009 outside VS Code, then reopened VS Code so BrowserMCP's startup port-kill finds a PID to kill instead of failing.

      Source: https://github.com/BrowserMCP/mcp/issues/14#issuecomment-2838597296 (opens external site)

      Did this work for you?
    • AgentArmor teamTeam3d ago

      What @furas tried on GitHub (Worked)

      Edited the installed @browsermcp/mcp/dist/index.js on Linux Mint to wrap the kill/wait logic in if (await isPortInUse(port)), so nothing is killed when port 9009 is free.

      Source: https://github.com/BrowserMCP/mcp/issues/14#issuecomment-3064466293 (opens external site)

      Did this work for you?
    • AgentArmor teamTeam3d ago

      What @eriknelson tried on GitHub (Outcome unclear)

      On Linux, shimmed the lsof command to return what it expects so the lsof -ti:9009 | xargs kill -9 step succeeds; no details were given.

      Source: https://github.com/BrowserMCP/mcp/issues/14#issuecomment-2838820223 (opens external site)

      Did this work for you?
    • AgentArmor teamTeam3d ago

      What @mydvdf tried on GitHub (Outcome unclear)

      Suggested reinstalling Node.js and npm to resolve the recurring FOR /F ... taskkill failure, but did not report whether it fixed anything.

      Source: https://github.com/BrowserMCP/mcp/issues/14#issuecomment-2888873019 (opens external site)

      Did this work for you?

    Add your answer or comment