MCP Feature "Client Closed" Fix

try mcp.json:

{
  "mcpServers": {
    "browser-tools": {
      "command": "cmd", 
      "args": [
        "/c",
        "npx -y @agentdeskai/[email protected]"
      ],
      "enabled": true
    }
  }
}

and refresh

in your desktop try run command in cmd:

npx @agentdeskai/[email protected]

II had the same error. I usually use nvm to manage Node.js versions, but this time I installed the latest LTS version of Node.js (22) directly using the installer, and now it works.

If anyone is still having this issue on windows you can use paste the following code into your mcp.json file within cursor (remember to replace the Github token placeholder with your actual token):

{
  "mcpServers": {
    "github": {
      "command": "cmd",
      "args": [
        "/c",
        "npx",
        "-y",
        "@smithery/cli@latest",
        "run",
        "@smithery-ai/github",
        "--config",
        "{\"githubPersonalAccessToken\":\"<Github personal access token goes here>\"}"
      ]
    }
  }
}

Or on MAC:

{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": [
        "-y",
        "@smithery/cli@latest",
        "run",
        "@smithery-ai/github",
        "--config",
        "{\"githubPersonalAccessToken\":\"<Github personal access token goes here>\"}"
      ]
    }
  }
}

Hope this helps. Cheers!

Anyone manages to fix it, I run for local mcp, but keeps getting Client Closed.

Can anyone help me?

Thanks

Hello, I have similar issue and same OS with you. Try to run the command and args in the mcp.json and you will find that it has some issues running command. Debug the problem with packages and relaunch the cursor should solve the problem

You can try to run the Command locally in your terminal and see if it works. If you manage to get it work then relaunch cursor and refresh it

Bug fixed.

Mind sharing the fix?

I spent a long time on this, as someone unfortunately using Windows, WSL, and VS Code’s containerization for their project. Ultimately I couldn’t find a fix, and went with a non-official version of Supabase MCP (googling will show it), which was working within 15 mins.

hello, i’m also encountering this issue in macos, and i tried use esbuild to bundle all files into one js bundle, for a stdio mcp, but cursor still error: [error] name: Error in MCP: Client closed
may i ask what do you mean bundle with eslint here? thank you!

Thanks @digitalcloud.no I was getting really frustrated with the client constantly closing. I spent a whole hour debugging in the Cursor console today :mushroom:, then did an old-fashioned Google search and found this simple answer. It is strange that “Enabled/Disabled” is not updating the JSON. However, adding “enabled”: true overwrites the ability to toggle “Enabled/Disabled.”

  • I truly dislike Cursor for its absolutely terrible documentation; it seems to be a low priority for them, which is typical of Gen Z. The documentation was clearly written with ai, “Cursor will only send the first 40 tools to the Agent.” Cursor can’t effectively handle more than five before it “forgets” the tools are available.
  • I found that writing tools directly into the .mdc is very effective. There is a YouTube video by EchoHive explaining how to write tools without MCP, which I recommend for simpler tasks, but actually for memory in a larger project, it works better to have a regular db and write the tools into the rules, “forcing” Cursor to use them correctly.

After testing, the setting “enabled”: true for persistence should be limited to the MCP tools you always use, such as the Claude Think tool, memory tool, and a search tool like Exa/Talvy. Additionally, and remind Cursor to actually use these tools in a .mdc rule file.

Facing this error on MacOS with a python service, was any able to resolve this?

in Cursor menu → help → toggle dev tools. That will help you, work with the assistant. I suspect it is related to your python env. You dont have uv set up correctly. Also depending on what need from the MCP tool you are creating perhaps see if you can solve it with https://www.youtube.com/watch?v=JGphuBuKiDo&t=39s&ab_channel=echohive

1 Like

I fix this on MacOS by doing

brew install node

and then restarting cursor!

i fix this by : rm -rf ~/.npm/_npx, then restart cursor

I fixed this on macos by setting a specific package version instead of @latest:
@supabase/[email protected]

it wasn’t working until I changed “1.2.0” to “latest” not sure why though but thank you!

I’ve been struggling with this same issue for the last two days. While using Gemini 2.5 may not be a cost-effective way to use Cursor, it’s tried a number of approaches, all without success.

Specifically:
1. Initial Problem:

  • The user configured an MCP server named openai-pdf in Cursor settings intended to run the Python script /Users/jeffwhite/openai-mcp-pdf/mcp_server.py.
  • Upon enabling the server in Cursor, it immediately showed a “Client closed” error status (red dot).
  • The Python script was expected to create a log file (mcp_server.log initially), but this file was not being created, indicating the script was either not running at all or failing very early.

2. Debugging and Manual Execution:

  • Basic Script Check: Added print() statements at the very start of mcp_server.py to see if the script execution even began.
  • Logging Modification: Simplified the logging setup in mcp_server.py to use logging.basicConfig with an absolute file path (/Users/jeffwhite/openai-mcp-pdf/mcp_server_debug.log) and filemode='w', removing the StreamHandler to isolate file logging.
    **Note: Logging function is POOR. It appears that there are no log monitoring capabilities available.
  • Python Command: Determined that python3 (not python) was the correct command to invoke the desired Python interpreter on the user’s system.
  • Dependency Errors: Running python3 mcp_server.py manually revealed a ModuleNotFoundError: No module named 'pdfplumber', indicating missing dependencies.
  • Virtual Environment Identification: Confirmed the project requires a Python virtual environment. Located the correct environment at /Users/jeffwhite/openai-mcp-venv/.
  • Successful Manual Execution: Successfully executed the script manually from the terminal using the command: source /Users/jeffwhite/openai-mcp-venv/bin/activate && python3 /Users/jeffwhite/openai-mcp-pdf/mcp_server.py. This confirmed:
    • The virtual environment activation is necessary.
    • The Python script itself is functional when run in the correct environment.
    • The modified logging to /Users/jeffwhite/openai-mcp-pdf/mcp_server_debug.log worked correctly during manual execution, logging startup messages up to the point where the script waits for MCP requests (Starting MCP request loop...).

3. MCP Configuration Attempts in Cursor:

  • Review Initial Config: The initial command configured in the Cursor UI (and reflected in mcp.json) used /bin/bash -c to change directory and then execute the script using the virtual environment’s python: /bin/bash -c "cd /Users/jeffwhite/openai-mcp-pdf && /Users/jeffwhite/openai-mcp-venv/bin/python /Users/jeffwhite/openai-mcp-pdf/mcp_server.py". This failed with “Client closed”.
  • Attempt 1: Direct Python Execution: Based on troubleshooting and common practices (e.g., avoiding shell wrappers seen in forum posts), modified the configuration in /Users/jeffwhite/.cursor/mcp.json to directly execute the Python interpreter from the virtual environment:
    • "command": "/Users/jeffwhite/openai-mcp-venv/bin/python"
    • "args": ["/Users/jeffwhite/openai-mcp-pdf/mcp_server.py"]
  • Result of Attempt 1: This configuration also resulted in the “Client closed” error immediately upon refreshing the server status in Cursor settings. Critically, no new entries were written to the mcp_server_debug.log file during these attempts by Cursor.

4. Current State and Hypothesis:

  • The mcp_server.py script functions correctly when launched manually from a terminal with the /Users/jeffwhite/openai-mcp-venv virtual environment activated.
  • When Cursor attempts to launch the same script using the configuration in mcp.json (either via bash -c or direct Python execution), the process fails immediately (“Client closed”).
  • The failure occurs before the Python script’s logging is initialized, as evidenced by the lack of any log output during Cursor-initiated launches.
  • Hypothesis: The failure likely stems from the environment in which Cursor launches the MCP process. Potential causes include:
    • Working Directory: Cursor might not be setting the working directory correctly (e.g., to /Users/jeffwhite/openai-mcp-pdf/), which could prevent load_dotenv() from finding the .env file needed for the OpenAI API key, causing an early crash before logging starts. (An attempt to explicitly set the dotenv path in the script was interrupted but could be relevant).
    • PATH / System Dependencies: Essential system dependencies required by the Python libraries (like poppler for pdf2image) might not be available in the PATH environment variable accessible to the process launched by Cursor, even if they are available in the user’s standard terminal PATH.
    • Stdin/Stdout Handling: Potential issues with how Cursor handles the standard input/output streams required for MCP communication, although this usually manifests later, not as an immediate closure before logging.

This detailed breakdown should help illustrate that the script itself is viable, but fails specifically when launched via Cursor’s MCP mechanism under the tested configurations, pointing towards an issue in how Cursor handles the process execution environment for this specific setup.

Cursor details:
Version: 0.49.4 (Universal)
VSCode Version: 1.96.2
Commit: ec408037b24566b11e6132c58bbe6ad27046eb90
Date: 2025-04-22T00:33:06.906Z
Electron: 34.3.4
Chromium: 132.0.6834.210
Node.js: 20.18.3
V8: 13.2.152.41-electron.0
OS: Darwin arm64 24.4.0

Help in resolution is most appreciated.
Jeff

im using the the following on mac

{
  "version": "1.0.0",
  "mcpServers": {
    "sql-explorer": {
      "name": "SQL Database Explorer",
      "version": "1.0.0",
      "description": "SQLite database explorer with comprehensive query capabilities",
      "command": "npx",
      "args": ["-y", "ts-node", "server.ts", "--stdio"],
      "env": {
        "DATABASE_URL": "postgresql://db_user:db_pwd123@localhost:5477/qaworld?schema=public"
      },
      "capabilities": {
        "resources": {
          "schema": {
            "description": "Get schema information for database objects",
            "uriTemplate": "schema://{object}",
            "parameters": {
              "object": {
                "type": "string",
                "description": "Name of the database object (table, view, etc.)"
              }
            }
          },
          "table-preview": {
            "description": "Preview data from a table",
            "uriTemplate": "preview://{table}",
            "parameters": {
              "table": {
                "type": "string",
                "description": "Name of the table to preview"
              }
            }
          }
        },
        "tools": {
          "list_tables": {
            "description": "Get a list of all tables in the database",
            "parameters": {}
          },
          "describe_table": {
            "description": "View schema information for a specific table",
            "parameters": {
              "table_name": {
                "type": "string",
                "description": "Name of the table"
              }
            }
          },
          "query": {
            "description": "Execute SQL queries",
            "parameters": {
              "sql": {
                "type": "string",
                "description": "SQL query to execute"
              }
            }
          },
          "count-records": {
            "description": "Count records in a table",
            "parameters": {
              "table": {
                "type": "string",
                "description": "Name of the table"
              },
              "where": {
                "type": "string",
                "description": "Optional WHERE clause",
                "required": false
              }
            }
          },
          "insert-data": {
            "description": "Insert data into a table",
            "parameters": {
              "table": {
                "type": "string",
                "description": "Target table name"
              },
              "data": {
                "type": "object",
                "description": "Data to insert (JSON object)"
              }
            }
          },
          "update-data": {
            "description": "Update data in a table",
            "parameters": {
              "table": {
                "type": "string",
                "description": "Target table name"
              },
              "set": {
                "type": "object",
                "description": "Update values (JSON object)"
              },
              "where": {
                "type": "string",
                "description": "WHERE clause for the update"
              }
            }
          },
          "delete-data": {
            "description": "Delete data from a table",
            "parameters": {
              "table": {
                "type": "string",
                "description": "Target table name"
              },
              "where": {
                "type": "string",
                "description": "WHERE clause for deletion"
              }
            }
          }
        }
      }
    }
  },
  "defaultServer": "sql-explorer",
  "settings": {
    "timeout": 30000,
    "retryAttempts": 3,
    "logLevel": "info"
  }
}

still facing the same issue

Issue resolved by adding the absolute path of my server.ts not relative path on mac os