Description
Description:
When using a custom MCP server defined in mcp.json
with a command
entry, the command is executed twice in quick succession by the MCP client (in my case, Claude.app). This results in the first process successfully binding to port 8000, and the second failing due to [Errno 48] address already in use
.
This behavior causes one of the two processes to exit prematurely, and depending on how the server logs to stdout, it can result in invalid JSON being returned to the client — breaking the protocol.
Steps to reproduce:
- Define a command for a custom MCP server in
mcp.json
like this:
json
"excel": {
"command": "/path/to/run_excel_mcp.sh",
"transport": "sse",
"env": {
"EXCEL_FILES_PATH": "/path/to/workspace"
}
}
- Have the script start a server on port 8000 (e.g., using uvicorn).
- Launch the MCP client.
- Observe in the logs: the command is executed twice.
Expected behavior:
The command should be executed only once per server session.
Actual behavior:
- The same command is executed twice.
- The second instance crashes with a port binding error.
- In some cases, this causes malformed JSON to be sent to the client.
Environment:
- MCP client: Claude.app (version 0.1.0)
- MCP server: Custom Python server using uv run
- OS:macOS (Apple Silicon)
Suggested fix:
Ensure the command is executed only once, and avoid redundant reinitializations unless explicitly intended.
🙏 Thank you for your great work on the MCP framework. I hope this helps improve the robustness of the developer experience.