-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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