Skip to content

Stale OAuth callback server causes EADDRINUSE crash on reconnect #253

Description

@nick-youngblut

Bug Description

When a previous mcp-remote instance doesn't shut down cleanly (e.g., the MCP client disconnects or the process is interrupted), the OAuth callback server remains orphaned and holds the port. On the next invocation, mcp-remote detects the existing port via the lockfile and attempts to reuse it, but crashes with EADDRINUSE because it can't bind a new listener on the already-occupied port.
## Steps to Reproduce

  1. Connect to a remote MCP server via mcp-remote with OAuth
  2. Kill or disconnect the MCP client without cleanly shutting down mcp-remote
  3. Reconnect — mcp-remote finds the stale lockfile/port and tries to reuse it
  4. Crash:

[40217] Using existing client port: 28233
[40217] Connecting to remote server: https://example.com/mcp
[40217] Authentication required. Initializing auth...

Error: listen EADDRINUSE: address already in use 127.0.0.1:28233
at Server.setupListenHandle [as _listen2] (node:net:1940:16)
...

Expected Behavior

mcp-remote should handle this gracefully — either:

  • Detect the stale process and kill it before binding
  • Detect EADDRINUSE, pick a new port, and update the lockfile
  • Properly clean up the callback server on shutdown (signal handlers for SIGTERM/SIGINT)

Workaround

Manually kill the orphaned node process:

lsof -i :<port> # find the PID
kill <pid>                                                                                                                                                                                                                                                       

Or specify an explicit callback port to avoid the stale one:

{                                                                                                                                                                                                                                                                
  "mcpServers": {                                         
    "my-server": {                                                                                                                                                                                                                                               
      "command": "npx",                                   
      "args": ["-y", "mcp-remote", "https://example.com/mcp", "19880"]
    }                                                                                                                                                                                                                                                            
  }
}

Related Issues

Environment

  • mcp-remote: latest (via npx -y mcp-remote)
  • MCP client: Claude Code (CLI)
  • Platform: macOS (Darwin 25.1.0)
  • Node.js: v24.4.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions