Skip to content

command in mcp.json is executed twice, causing port conflict #1113

Closed as not planned
@shoheixkimura

Description

@shoheixkimura

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:

  1. 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"
  }
}
  1. Have the script start a server on port 8000 (e.g., using uvicorn).
  2. Launch the MCP client.
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions