Repository navigation
Description
Bug Description
When running mcp dev server.py, the Inspector reports PORT IS IN USE at http://localhost:6274 even when the port is confirmed free before launch. The port check appears to run after the Inspector has already bound the port, causing it to detect its own process.
Steps to Reproduce
- Confirm port 6274 is free:
lsof -i :6274returns nothing - Run
mcp dev server.py - Inspector starts the proxy on port 6277 successfully
- Inspector then reports port 6274 is in use and fails
Actual Output
⚙️ Proxy server listening on localhost:6277
🔑 Session token: <token>
Use this token to authenticate requests or set DANGEROUSLY_OMIT_AUTH=true to disable auth
❌ MCP Inspector PORT IS IN USE at http://localhost:6274 ❌
Expected Behavior
The port availability check should run before binding/starting the server on that port, not after. Currently the startup sequence appears to be:
- Start proxy server (port 6277) ✅
- Start Inspector server (binds port 6274)
- Check if port 6274 is available ← detects its own process, fails ❌
The correct sequence should be:
- Check if port 6274 is available ✅
- Check if port 6277 is available ✅
- Start proxy server (port 6277)
- Start Inspector server (port 6274)
Root Cause Analysis
This is a race condition. The port availability check (net.createServer or equivalent) runs concurrently with or after the actual server bind. When the check fires, the port is already occupied by the Inspector's own Node.js process.
Additionally, after killing the process with Ctrl+C, the port sometimes remains in CLOSE_WAIT state, requiring kill -9 of the stale Node process to reclaim it. This suggests the graceful shutdown handler may not be properly closing all sockets.
Environment
- MCP SDK: 1.26.0 (Python)
- OS: macOS (Sequoia)
- Python: 3.12
- Node: (used internally by Inspector)
Workarounds
- Use
--portflag to specify a different port:mcp dev server.py --port 6280 - Kill stale processes before launch:
lsof -ti:6274 | xargs kill -9 2>/dev/null
Activity
btbowman commentedon Feb 16, 2026
Root Cause Analysis & Fix
After reading the source, I found three bugs in
client/bin/client.js:Bug 1: No pre-flight port check
The client calls
server.listen(port, host)directly without checking availability first. If a stale process holds the port, theEADDRINUSEerror fires — but by then the process is already running.Bug 2: Missing
process.exit(1)in error handlerBug 3: No graceful shutdown handler
There are zero
SIGINT/SIGTERMhandlers and noserver.close()call. When the user hits Ctrl+C, the HTTP socket isn't properly closed, leaving the port inCLOSE_WAITstate. The next launch then hits Bug 1.Fix (applied locally, tested)
The same fixes should also be applied to
server/build/index.js(the proxy server). Happy to open a PR if that would be helpful.fix: add pre-flight port check and graceful shutdown to prevent EADDR…
fix: pre-flight port check and graceful shutdown to prevent EADDRINUSE
cliffhall commentedon Aug 1, 2026
Closing: v1 is deprecated.
Thank you for reporting this, and apologies for the long wait for a response.
v1 will receive security fixes only — this issue describes a functionality, compatibility, or usability problem rather than a vulnerability, so it is being closed against v1. This is not a judgment on whether the problem is real — it's a consequence of the v1 line being frozen. This is happening as part of #1872.
If this still happens in v2, we'd genuinely like to know. v2 is a complete rewrite — three clients over a shared core — so many v1 behaviours no longer exist in the same form. Please open a fresh issue against v2 with steps to reproduce, and we'll look at it. Note that we accept external contributions as issues rather than pull requests; maintainers handle design and implementation through a prompt-driven workflow. See
CONTRIBUTING.md.Thanks for taking the time to report it.