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
- Connect to a remote MCP server via mcp-remote with OAuth
- Kill or disconnect the MCP client without cleanly shutting down mcp-remote
- Reconnect — mcp-remote finds the stale lockfile/port and tries to reuse it
- 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
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
[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:
Workaround
Manually kill the orphaned node process:
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