Skip to content

Error from MCP server: SyntaxError: Unexpected token 'E', "Error: typ"... is not valid JSON #409

Description

@abdulsaminexusaeon

When i run the app with
cmd = mcp dev server.py

then when i click on connect button i got this issue

Stdio transport: command=C:\Users\User\AppData\Local\Programs\Python\Python310\Scripts\uv.exe, args=run,--with,mcp,mcp,run,server.py
Spawned stdio transport
Connected MCP client to backing server transport
Created web app transport
Created web app transport
Set up MCP proxy
Error from MCP server: SyntaxError: Unexpected token 'E', "Error: typ"... is not valid JSON
at JSON.parse ()
at deserializeMessage (file:///C:/Users/User/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js:26:44)
at ReadBuffer.readMessage (file:///C:/Users/User/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js:19:16)
at StdioClientTransport.processReadBuffer (file:///C:/Users/User/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/sdk/dist/esm/client/stdio.js:114:50)
at Socket. (file:///C:/Users/User/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/sdk/dist/esm/client/stdio.js:93:22)
at Socket.emit (node:events:518:28)
at addChunk (node:internal/streams/readable:561:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
at Readable.push (node:internal/streams/readable:392:5)
at Pipe.onStreamRead (node:internal/stream_base_commons:189:23)
Error from MCP server: SyntaxError: Unexpected token 'E', "Error: typ"... is not valid JSON
at JSON.parse ()
at deserializeMessage (file:///C:/Users/User/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js:26:44)
at ReadBuffer.readMessage (file:///C:/Users/User/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js:19:16)
at StdioClientTransport.processReadBuffer (file:///C:/Users/User/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/sdk/dist/esm/client/stdio.js:114:50)
at Socket. (file:///C:/Users/User/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/sdk/dist/esm/client/stdio.js:93:22)
at Socket.emit (node:events:518:28)
at addChunk (node:internal/streams/readable:561:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
at Readable.push (node:internal/streams/readable:392:5)
at Pipe.onStreamRead (node:internal/stream_base_commons:189:23)
Error from MCP server: SyntaxError: Unexpected token 'E', "Error: typ"... is not valid JSON
at JSON.parse ()
at deserializeMessage (file:///C:/Users/User/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js:26:44)
at ReadBuffer.readMessage (file:///C:/Users/User/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js:19:16)
at StdioClientTransport.processReadBuffer (file:///C:/Users/User/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/sdk/dist/esm/client/stdio.js:114:50)
at Socket. (file:///C:/Users/User/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/sdk/dist/esm/client/stdio.js:93:22)
at Socket.emit (node:events:518:28)
at addChunk (node:internal/streams/readable:561:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
at Readable.push (node:internal/streams/readable:392:5)
at Pipe.onStreamRead (node:internal/stream_base_commons:189:23)
Error from MCP server: SyntaxError: Unexpected token 'E', "Error: typ"... is not valid JSON
at JSON.parse ()
at deserializeMessage (file:///C:/Users/User/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js:26:44)
at ReadBuffer.readMessage (file:///C:/Users/User/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js:19:16)
at StdioClientTransport.processReadBuffer (file:///C:/Users/User/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/sdk/dist/esm/client/stdio.js:114:50)
at Socket. (file:///C:/Users/User/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/sdk/dist/esm/client/stdio.js:93:22)
at Socket.emit (node:events:518:28)
at addChunk (node:internal/streams/readable:561:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
at Readable.push (node:internal/streams/readable:392:5)
at Pipe.onStreamRead (node:internal/stream_base_commons:189:23)
Error from MCP server: SyntaxError: Unexpected token 'E', "Error: typ"... is not valid JSON
at JSON.parse ()
at deserializeMessage (file:///C:/Users/User/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js:26:44)
at ReadBuffer.readMessage (file:///C:/Users/User/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js:19:16)
at StdioClientTransport.processReadBuffer (file:///C:/Users/User/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/sdk/dist/esm/client/stdio.js:114:50)
at Socket. (file:///C:/Users/User/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/sdk/dist/esm/client/stdio.js:93:22)
at Socket.emit (node:events:518:28)
at addChunk (node:internal/streams/readable:561:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
at Readable.push (node:internal/streams/readable:392:5)
at Pipe.onStreamRead (node:internal/stream_base_commons:189:23)
Received message for sessionId ac082c68-292e-4cbd-b85e-42046b434b38
Error in /message route: Error: SSE connection not established
at SSEServerTransport.handlePostMessage (file:///C:/Users/User/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/sdk/dist/esm/server/sse.js:53:19)
at file:///C:/Users/User/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/inspector/server/build/index.js:129:25
at Layer.handle [as handle_request] (C:\Users\User\AppData\Local\npm-cache_npx\5a9d879542beca3a\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\User\AppData\Local\npm-cache_npx\5a9d879542beca3a\node_modules\express\lib\router\route.js:149:13)
at Route.dispatch (C:\Users\User\AppData\Local\npm-cache_npx\5a9d879542beca3a\node_modules\express\lib\router\route.js:119:3)
at Layer.handle [as handle_request] (C:\Users\User\AppData\Local\npm-cache_npx\5a9d879542beca3a\node_modules\express\lib\router\layer.js:95:5)
at C:\Users\User\AppData\Local\npm-cache_npx\5a9d879542beca3a\node_modules\express\lib\router\index.js:284:15
at Function.process_params (C:\Users\User\AppData\Local\npm-cache_npx\5a9d879542beca3a\node_modules\express\lib\router\index.js:346:12)
at next (C:\Users\User\AppData\Local\npm-cache_npx\5a9d879542beca3a\node_modules\express\lib\router\index.js:280:10)
at cors (C:\Users\User\AppData\Local\npm-cache_npx\5a9d879542beca3a\node_modules\cors\lib\index.js:188:7)
node:_http_outgoing:699
throw new ERR_HTTP_HEADERS_SENT('set');
^

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at ServerResponse.setHeader (node:_http_outgoing:699:11)
at ServerResponse.header (C:\Users\User\AppData\Local\npm-cache_npx\5a9d879542beca3a\node_modules\express\lib\response.js:794:10)
at ServerResponse.json (C:\Users\User\AppData\Local\npm-cache_npx\5a9d879542beca3a\node_modules\express\lib\response.js:275:10)
at file:///C:/Users/User/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/inspector/server/build/index.js:133:25
at process.processTicksAndRejections (node:internal/process/task_queues:105:5) {
code: 'ERR_HTTP_HEADERS_SENT'
}

Node.js v22.14.0

Activity

  1. eug commented on Apr 6, 2025

    @eug

    I encountered the same issue.

    The error message I got was (like yours):
    Error from MCP server: SyntaxError: Unexpected token 'E', "Error: typ"... is not valid JSON

    It seems related to the following error:
    Error: typer is required. Install with 'pip install mcp[cli]'

    In my case, the problem was that the required packages weren’t installed in the environment I was using. I resolved it by running:

    pip install -U mcp[cli]
    pip install -U typer

    After that, everything worked as expected.

    For reference, here are the package versions I'm using:

    pip show mcp typer     
    Name: mcp
    Version: 1.6.0
    Summary: Model Context Protocol SDK
    Home-page: https://modelcontextprotocol.io
    Author: Anthropic, PBC.
    Author-email:
    License: MIT
    Location: C:\Users\%USER%\AppData\Local\Programs\Python\Python312\Lib\site-packages
    Requires: anyio, httpx, httpx-sse, pydantic, pydantic-settings, sse-starlette, starlette, uvicorn
    Required-by:
    ---
    Name: typer
    Version: 0.15.2
    Summary: Typer, build great CLIs. Easy to code. Based on Python type hints.
    Home-page: https://github.com/fastapi/typer
    Author:
    Author-email: =?utf-8?q?Sebasti=C3=A1n_Ram=C3=ADrez?= <tiangolo@gmail.com>
    License:
    Location: C:\Users\%USER%\AppData\Local\Programs\Python\Python312\Lib\site-packages
    Requires: click, rich, shellingham, typing-extensions
    Required-by: fastapi-cli
    

    Another common possibility is a Python version mismatch:
    Your system’s default Python version (used by pip when installing packages globally) is 3.YY, while the uv tool is executing commands using Python 3.XX. As a result, when you ran uv run --with mcp mcp run main.py, it will attempt to use Python 3.XX. However, the typer package was installed in the Python 3.YY site-packages directory, making it inaccessible to the Python 3.YY environment.

  2. ASaiAnudeep commented on Apr 10, 2025

    @ASaiAnudeep

    I'm also facing similar issues

    2025-04-10 17:16:00.908 [error] iles: Client error for command Unexpected number in JSON at position 2 (line 1 column 3)
    2025-04-10 17:16:00.908 [error] iles: Error in MCP: Unexpected number in JSON at position 2 (line 1 column 3)
    2025-04-10 17:16:00.908 [error] iles: Client error for command Unexpected token 'L', ..."          ListToolsR"... is not valid JSON
    2025-04-10 17:16:00.908 [error] iles: Error in MCP: Unexpected token 'L', ..."          ListToolsR"... is not valid JSON
    2025-04-10 17:16:00.909 [info] listOfferings: Found 1 tools
    
  3. wyxpku commented on Apr 11, 2025

    @wyxpku

    Got the same error on mac, python=3.11.11

    Stdio transport: command=/opt/homebrew/bin/uv, args=run,--with,mcp,mcp,run,server.py
    Spawned stdio transport
    Connected MCP client to backing server transport
    Created web app transport
    Created web app transport
    Set up MCP proxy
    Received message for sessionId 3340924a-e289-4d42-9af5-2377ae3e9994
    Error in /message route: Error: SSE connection not established
        at SSEServerTransport.handlePostMessage (file:///Users/ethan/.npm/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/sdk/dist/esm/server/sse.js:53:19)
        at file:///Users/ethan/.npm/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/inspector/server/build/index.js:130:25
        at Layer.handle [as handle_request] (/Users/ethan/.npm/_npx/5a9d879542beca3a/node_modules/express/lib/router/layer.js:95:5)
        at next (/Users/ethan/.npm/_npx/5a9d879542beca3a/node_modules/express/lib/router/route.js:149:13)
        at Route.dispatch (/Users/ethan/.npm/_npx/5a9d879542beca3a/node_modules/express/lib/router/route.js:119:3)
        at Layer.handle [as handle_request] (/Users/ethan/.npm/_npx/5a9d879542beca3a/node_modules/express/lib/router/layer.js:95:5)
        at /Users/ethan/.npm/_npx/5a9d879542beca3a/node_modules/express/lib/router/index.js:284:15
        at Function.process_params (/Users/ethan/.npm/_npx/5a9d879542beca3a/node_modules/express/lib/router/index.js:346:12)
        at next (/Users/ethan/.npm/_npx/5a9d879542beca3a/node_modules/express/lib/router/index.js:280:10)
        at cors (/Users/ethan/.npm/_npx/5a9d879542beca3a/node_modules/cors/lib/index.js:188:7)
    node:_http_outgoing:699
        throw new ERR_HTTP_HEADERS_SENT('set');
              ^
    
    Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
        at ServerResponse.setHeader (node:_http_outgoing:699:11)
        at ServerResponse.header (/Users/ethan/.npm/_npx/5a9d879542beca3a/node_modules/express/lib/response.js:794:10)
        at ServerResponse.json (/Users/ethan/.npm/_npx/5a9d879542beca3a/node_modules/express/lib/response.js:275:10)
        at file:///Users/ethan/.npm/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/inspector/server/build/index.js:134:25
        at process.processTicksAndRejections (node:internal/process/task_queues:105:5) {
      code: 'ERR_HTTP_HEADERS_SENT'
    }
    
    Node.js v23.10.0
    
  4. subipranuvem commented on Apr 11, 2025

    @subipranuvem

    Any solutions? I got the same problem as @wyxpku ....

  5. wyxpku commented on Apr 11, 2025

    @wyxpku

    Any solutions? I got the same problem as @wyxpku ....

    modelcontextprotocol/inspector#295

    someone fixed it, but not merged yet

  6. subipranuvem commented on Apr 11, 2025

    @subipranuvem

    I tried to use it using the VsCode Simple Browser... It worked, I don't know how ... But it's a "trick" while fix isn't merged...

    Image

    But, the Inspector still doesn't work in my browsers (Chrome, Edge and Firefox).

  7. cliffhall commented on Apr 16, 2025

    @cliffhall
    Member

    Any solutions? I got the same problem as @wyxpku ....

    modelcontextprotocol/inspector#295

    someone fixed it, but not merged yet

    We're waiting for steps to reproduce.

  8. cliffhall commented on Apr 19, 2025

    @cliffhall
    Member

    OBSERVATIONS

    OUTPUT RELEVANT TO THIS ISSUE

    @abdulsaminexusaeon

    Stdio transport: command=C:\Users\User\AppData\Local\Programs\Python\Python310\Scripts\uv.exe, args=run,--with,mcp,mcp,run,server.py
    Spawned stdio transport
    Connected MCP client to backing server transport
    Created web app transport
    Created web app transport
    Set up MCP proxy
    Error from MCP server: SyntaxError: Unexpected token 'E', "Error: typ"... is not valid JSON
    at JSON.parse ()

    @eug

    Error from MCP server: SyntaxError: Unexpected token 'E', "Error: typ"... is not valid JSON

    @ASaiAnudeep

    2025-04-10 17:16:00.908 [error] iles: Client error for command Unexpected number in JSON at position 2 (line 1 column 3)
    2025-04-10 17:16:00.908 [error] iles: Error in MCP: Unexpected number in JSON at position 2 (line 1 column 3)
    2025-04-10 17:16:00.908 [error] iles: Client error for command Unexpected token 'L', ..." ListToolsR"... is not valid JSON
    2025-04-10 17:16:00.908 [error] iles: Error in MCP: Unexpected token 'L', ..." ListToolsR"... is not valid JSON
    2025-04-10 17:16:00.909 [info] listOfferings: Found 1 tools

    CONCLUSION

    What's happening is that something other than a valid JSONRPCMessage is being emitted from those servers on STDOUT. They are writing plain error or log messages.

    The spec for STDIO servers says:

    The server MUST NOT write anything to its stdout that is not a valid MCP message.

    If you want to log messages from your STDIO server, you can do that on on STDERR.

  9. rioultf commented on Apr 24, 2025

    @rioultf

    Got it working using the venv generated by : (see here

    uv init mcp-server-demo
    cd mcp-server-demo/
    uv add "mcp[cli]"
    mcp dev mcp-server-demo.py

    After that I can connect to http://127.0.0.1:6274 and test the server.

    The server has to be launched in the correct environment.

    This is also true when using AnythingLLM is you want him to correctly launch your servers.

  10. zhanwenchen commented on Oct 8, 2025

    @zhanwenchen

    For anyone encountering this issue [error] unable to parse stdout from codex mcp: SyntaxError: Unexpected token '?', "?[?2004h" is not valid JSON, it may be due to setting a custom Codex CLI binary in your VSCode settings. Just removing that would help.

  11. Mo0xy commented on Nov 1, 2025

    @Mo0xy

    Got it working using the venv generated by : (see here

    uv init mcp-server-demo
    cd mcp-server-demo/
    uv add "mcp[cli]"
    mcp dev mcp-server-demo.py
    After that I can connect to http://127.0.0.1:6274 and test the server.

    The server has to be launched in the correct environment.

    This is also true when using AnythingLLM is you want him to correctly launch your servers.

    this worked for me, i forgot to initialize uv project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions