Skip to content

Unexpected end of JSON input #1014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
daBee opened this issue Mar 22, 2025 · 10 comments
Open

Unexpected end of JSON input #1014

daBee opened this issue Mar 22, 2025 · 10 comments
Labels
bug Something isn't working server-postgres Reference implementation for the PostgreSQL MCP server - src/postgres

Comments

@daBee
Copy link

daBee commented Mar 22, 2025

Describe the bug
Cannot connect & Errors on Claude Desktop launched.

2025-03-22T20:59:59.754Z [postgres] [info] Initializing server...
2025-03-22T20:59:59.786Z [postgres] [info] Server started and connected successfully
2025-03-22T20:59:59.814Z [postgres] [info] Message from client: {"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"claude-ai","version":"0.1.0"}},"jsonrpc":"2.0","id":0}
2025-03-22T20:59:59.981Z [postgres] [error] Unexpected end of JSON input {"context":"connection","stack":"SyntaxError: Unexpected end of JSON input\n    at JSON.parse (<anonymous>)\n    at EPe (/Applications/RF_Utilities/Claude.app/Contents/Resources/app.asar/.vite/build/index.js:82:189)\n    at SPe.readMessage (/Applications/RF_Utilities/Claude.app/Contents/Resources/app.asar/.vite/build/index.js:82:115)\n    at TPe.processReadBuffer (/Applications/RF_Utilities/Claude.app/Contents/Resources/app.asar/.vite/build/index.js:83:1842)\n    at Socket.<anonymous> (/Applications/RF_Utilities/Claude.app/Contents/Resources/app.asar/.vite/build/index.js:83:1523)\n    at Socket.emit (node:events:518:28)\n    at addChunk (node:internal/streams/readable:561:12)\n    at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)\n    at Readable.push (node:internal/streams/readable:392:5)\n    at Pipe.onStreamRead (node:internal/stream_base_commons:191:23)"}
2025-03-22T20:59:59.988Z [postgres] [info] Server transport closed
2025-03-22T20:59:59.988Z [postgres] [info] Client transport closed
2025-03-22T20:59:59.988Z [postgres] [info] Server transport closed unexpectedly, this is likely due to the process exiting early. If you are developing this MCP server you can add output to stderr (i.e. `console.error('...')` in JavaScript, `print('...', file=sys.stderr)` in python) and it will appear in this log.
2025-03-22T20:59:59.988Z [postgres] [error] Server disconnected. For troubleshooting guidance, please visit our [debugging documentation](https://modelcontextprotocol.io/docs/tools/debugging) {"context":"connection"}
2025-03-22T20:59:59.989Z [postgres] [info] Client transport closed

To Reproduce
Steps to reproduce the behavior:

  1. Startup Claude Desktop
  2. Read Log

Expected behavior
I thought it would have the ability to connect properly. Errors up front and no working connection.

Logs
see above

Additional context
Checked the json in the config file and everything seems legit.

@daBee daBee added the bug Something isn't working label Mar 22, 2025
@ron-42
Copy link

ron-42 commented Apr 7, 2025

Can you share MCP configuration file?

@daBee
Copy link
Author

daBee commented Apr 8, 2025

{
  "globalShortcut": "Ctrl+Space",
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-filesystem",
        "/Users/rich/Desktop",
        "/Users/rich/Downloads"
      ]
    },
    "postgres": {
      "command": "echo",
      "server": {
        "type": "tcp",
        "host": "192.168.1.23",
        "port": 5432,
        "timeout": 10000,
        "authentication": {
          "type": "postgres",
          "username": "richie",
          "password": "secretpassword",
          "database": "richie"
        }
      },
      "protocol": "postgres"
    },
    "mcp-installer": {
      "command": "npx",
      "args": [
        "@anaisbetts/mcp-installer"
      ]
    }
  }
}

@andrefelipe18
Copy link

Same error here, any resolution @daBee ?

@daBee
Copy link
Author

daBee commented Apr 16, 2025

Nothing yet.

@AgentSmithers
Copy link

I am receiving this while building a STDIO to SSE bridge. Judging by the response time I don't think the webserver can response fast enough before this error is sent by the Claude client. Can one receiving this error confirm that their MCP server is sending a response before receiving this within the log?

@daBee
Copy link
Author

daBee commented Apr 22, 2025

I've just asked the Claude client to reinstall the postgresql mcp server and I now have three of them in there. It's more confusing now than before. I now have mcp-postgresql, mcp=potgres, and postgresql MCP servers reporting "Could not attach to MCP Server ". It asked me to restart the app because of a fresh install twice, after I inserted my credentials for the first version, which I had to install twice, and now all of those are gone, and I have entries for the three I just mentioned, none with any credentials in the JSON.

@AgentSmithers
Copy link

AgentSmithers commented Apr 22, 2025

So funny enough I just resolved my own bug. It turns out the bridge I was using was forwarding a blank response from the SSE server because the SSE server is required to send 202 Accepted (no body). The STDIO bridge would receive this and forward the blank message back to Claude Desktop as a response to the "initialize" method being invoked and Claude seems to be trying to parse that blank message as a JSON. I was at first thinking it was a timing issue initially.

In my project I simply added
'''
if (payload.Length > 0)
{
Console.WriteLine(payload); //<-- Forward message from SSE back to STDIO
LogMessage("Server->Client", $"[data: {payload}]");
}
else
{
LogMessage("Server->X", $"[Data is blank]");
}
'''

And it resolved the issue. Now it appears I have a working Console STIDO -> SSE bridge in c#.

Note: I hope my comments are on topic, I am not attempting to POST hijack. :)

@olaservo olaservo added the server-postgres Reference implementation for the PostgreSQL MCP server - src/postgres label Apr 26, 2025
@olaservo
Copy link
Member

Hi @daBee I know its been ages since you opened this, but if you're still trying to resolve this I'm curious if you found what cause for your error was. I was having similar issues when my database wasn't running when I thought it was, so if you're still looking to fix this, then it could help to share more details on how your database is set up.

In general I think this server could use more useful error or debug logs since the connection closed error is very generic.

@daBee
Copy link
Author

daBee commented Apr 26, 2025

It's a LAN postgresql database. Nothing fancy. I have completely lost all bearing on what I should be using with postgresql.

@Priyanka06-droid
Copy link

I am seeing the same error when trying to integrate with aws athena mcp server with cursor.
STREAM 47931: push <Buffer 0a>
[MCP Error] SyntaxError: Unexpected end of JSON input
at JSON.parse ()
at deserializeMessage (file:///opt/homebrew/lib/node_modules/@lishenxydlgzs/aws-athena-mcp/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js:26:44)
at ReadBuffer.readMessage (file:///opt/homebrew/lib/node_modules/@lishenxydlgzs/aws-athena-mcp/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js:19:16)
at StdioServerTransport.processReadBuffer (file:///opt/homebrew/lib/node_modules/@lishenxydlgzs/aws-athena-mcp/node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js:39:50)
at StdioServerTransport._ondata (file:///opt/homebrew/lib/node_modules/@lishenxydlgzs/aws-athena-mcp/node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js:17:18)
at ReadStream.emit (node:events:507:28)
at addChunk (node:internal/streams/readable:559:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
at Readable.push (node:internal/streams/readable:390:5)
at TTY.onStreamRead (node:internal/stream_base_commons:189:23)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working server-postgres Reference implementation for the PostgreSQL MCP server - src/postgres
Projects
None yet
Development

No branches or pull requests

6 participants