mcp icon indicating copy to clipboard operation
mcp copied to clipboard

@browsermcp/mcp Fails to Start on Windows Due to Port Check Command Failure When Port 9009 is Free

Open Ltbltbltbltb opened this issue 1 year ago • 10 comments

I tried to create a Client MCP to use the Browser MCP (windows 11)

Problem Description: When attempting to start the @browsermcp/mcp server using npx @browsermcp/mcp@latest on Windows, the process fails immediately if TCP port 9009 is not currently in use. This prevents the server from starting under normal conditions where the required port is already available. Steps to Reproduce: Ensure no process is listening on TCP port 9009 on a Windows machine. This can be verified by running netstat -ano | findstr ":9009" in CMD or PowerShell, which should return no output. Open a terminal (CMD or PowerShell). Running as a regular user or as Administrator produces the same error. Run the command: npx @browsermcp/mcp@latest Expected Behavior: The server should successfully initialize or at least proceed past the initial port check/cleanup phase without error, eventually waiting for a client connection via stdio or other configured transport. Actual Behavior: The command fails immediately upon execution, printing the following error to stderr: 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 at genericNodeError (node:internal/errors:984:15) at wrappedFn (node:internal/errors:538:14) at checkExecSyncError (node:child_process:891:11) at execSync (node:child_process:963:15) at killProcessOnPort (file:///C:/Users/[YourUsername]/AppData/Local/npm-cache/_npx/[CacheHash]/node_modules/@browsermcp/mcp/dist/index.js:172:7) at createWebSocketServer (file:///C:/Users/[YourUsername]/AppData/Local/npm-cache/_npx/[CacheHash]/node_modules/@browsermcp/mcp/dist/index.js:185:3) at createServerWithTools (file:///C:/Users/[YourUsername]/AppData/Local/npm-cache/_npx/[CacheHash]/node_modules/@browsermcp/mcp/dist/index.js:205:21) at createServer (file:///C:/Users/[YourUsername]/AppData/Local/npm-cache/_npx/[CacheHash]/node_modules/@browsermcp/mcp/dist/index.js:708:10) at Command. (file:///C:/Users/[YourUsername]/AppData/Local/npm-cache/_npx/[CacheHash]/node_modules/@browsermcp/mcp/dist/index.js:716:24) at Command.listener [as _actionHandler] (C:/Users/[YourUsername]/AppData/Local/npm-cache/_npx/[CacheHash]/node_modules/commander/lib/command.js:552:17) { status: 1, signal: null, output: [ null, , ], pid: [PID], stdout: , stderr: } Use code with caution. (Note: Replace [YourUsername], [CacheHash], and [PID] with the actual values from your error log if desired, though they might not be essential) Analysis: The error seems to originate from the killProcessOnPort function (around dist/index.js:172 in the cached package). This function attempts to clear the port by executing the Windows command FOR /F "tokens=5" %a in ('netstat -ano ^| findstr :9009') do taskkill /F /PID %a using Node.js's child_process.execSync. When port 9009 is already free, the netstat -ano | findstr :9009 part of the command produces no output. Consequently, the FOR /F loop does not find a token to assign to the variable %a. The subsequent taskkill /F /PID %a command is then executed without a valid PID, causing taskkill.exe to fail with exit code 1. The server's startup logic appears to incorrectly interpret this specific command failure (which ironically indicates the port is free) as a fatal error, preventing the server from initializing.

Ltbltbltbltb avatar Apr 09 '25 20:04 Ltbltbltbltb

resolve the issue

xenxe12 avatar Apr 12 '25 10:04 xenxe12

I'm having the same problem on Arch Linux, total blocker:

Failed to kill process on port 9009: Error: Command failed: lsof -ti:9009 | xargs kill -9
kill: not enough arguments

This isn't a platform agnostic approach.

eriknelson avatar Apr 12 '25 20:04 eriknelson

Same issue here. With Roo Code, windows 11, tries to kill task on 9009 port and doesn't find any then fails to install server.

reas24 avatar Apr 29 '25 11:04 reas24

I have little workaround i came up with. Create simple node server with listening port on 9009 outside of vs code, close vs code, run the server and then run vs code again so it will kill your server on 9009 port and will run :) For now this worked.

reas24 avatar Apr 29 '25 12:04 reas24

Yeah that works. On Linux I shimmed the lsof to just return what it expects. This is pretty easy to fix and low hanging fruit for the community. I'll end up submitting a patch if nobody else gets to it when I can find some time.

eriknelson avatar Apr 29 '25 13:04 eriknelson

If you're like me and keep getting failed: FOR /F "tokens=5" %a in ('netstat -ano ^| findstr :9009') do taskkill /F /PID %a no matter what you try, consider reinstalling Node.js and npm to resolve the issue.

mydvdf avatar May 18 '25 09:05 mydvdf

I resolved it in different way:

I added one if in function createWebSocketServer in already installed file @browsermcp/mcp/dist/index.js

On Linux Mint I have this file in ~/.npm/_npx/6ddf87659f2ad8a4/node_modules/@browsermcp/mcp/dist/index.js

It seems it is in /src/ws.ts on repo.

before

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

after

put all in if (await isPortInUse(port)) {...} to stop killing program on port 9009 even if it doesn't exist

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

furas avatar Jul 12 '25 01:07 furas

这是来自QQ邮箱的自动回复邮件。您好,我有点事情不在,无法亲自回复您的邮件。我将在事情结束后,尽快给您回复。

mydvdf avatar Jul 12 '25 01:07 mydvdf

Browser MCP has been completely rewritten, so most open issues should now be resolved. I'm closing this issue as part of a cleanup. If the problem persists on the latest version, you're welcome to file a new issue.

namuorg avatar Oct 27 '26 09:10 namuorg

这是来自QQ邮箱的自动回复邮件。您好,我有点事情不在,无法亲自回复您的邮件。我将在事情结束后,尽快给您回复。

mydvdf avatar Oct 27 '26 09:10 mydvdf