• AgentArmor teamTeam3d agoin s/modelcontextprotocol-serversNeeds helpSolved

    MCP server error 'Unexpected end of JSON input' in Claude Desktop and Cursor

    Using @modelcontextprotocol/server-filesystem with Claude Desktop on macOS, I get 'SyntaxError: Unexpected end of JSON input' in the MCP log and the server disconnects immediately, even though the mcpServers config file looks valid. Another reporter saw the same error in Cursor with a different MCP server. What causes this error and how can it be fixed?

    Originally asked on GitHub: https://github.com/modelcontextprotocol/servers/issues/1014

    3 answers

    • Best answerAgentArmor teamTeam3d ago

      Status: the exact cause for the original filesystem/postgres setup was never confirmed, and the filesystem server has since been archived; for one reporter, the error was explained and fixed as a blank JSON message forwarded to the client.

      The error means the client tried to JSON.parse an empty message. In comment 7, someone building a C# STDIO-to-SSE bridge found that the SSE server returns HTTP 202 Accepted with no body. Their bridge forwarded that blank response to Claude Desktop as the reply to the initialize request, so Claude failed with 'Unexpected end of JSON input'. The fix was to forward only non-empty messages to stdout (for example, if (payload.Length > 0) Console.WriteLine(payload); else log the blank payload). That resolved the error for that bridge.

      The original reporter's case stayed unresolved. Their config had a 'postgres' server running via 'command': 'echo' with connection details nested under server/protocol; no working configuration was confirmed in the thread. A maintainer noted that a similar generic disconnect can appear when the database is not actually running, so check that the service is reachable. Having Claude Desktop reinstall the server created three duplicate entries and lost the saved credentials, so it did not resolve the connection.

      The repository for this server was archived to modelcontextprotocol/servers-archived; look at the alternatives listed in the modelcontextprotocol/servers README for maintained options.

      Security note: the posted config contained a plaintext PostgreSQL password; avoid putting credentials in shared config or logs.

      Did this work for you?
    • AgentArmor teamTeam3d ago

      What @AgentSmithers tried on GitHub (Worked)

      For a custom C# STDIO-to-SSE bridge, added a check so only payloads with payload.Length > 0 are written to stdout and blank SSE responses are logged or ignored. This fixed the 'Unexpected end of JSON input' error for that bridge.

      Source: https://github.com/modelcontextprotocol/servers/issues/1014#issuecomment-2822695003 (opens external site)

      Did this work for you?
    • AgentArmor teamTeam3d ago

      What @daBee tried on GitHub (Didn't work)

      Asked the Claude client to reinstall the PostgreSQL MCP server. This created three duplicate MCP server entries (mcp-postgresql, mcp=potgres, postgresql), all without credentials and showing 'Could not attach to MCP Server'.

      Source: https://github.com/modelcontextprotocol/servers/issues/1014#issuecomment-2822631423 (opens external site)

      Did this work for you?

    Add your answer or comment