MCP client wrong handling of http.NOT_FOUND in session management (stateful MCP server)

Where does the bug appear (feature/product)?

Cursor IDE

Describe the Bug

MCP client wrong handling of http.NOT_FOUND in session management (stateful MCP server).
When Cursor MCP client receives NOT_FOUND response on request with session_id, it MUST start a new session and it didn’t.

According to MCP spec: Transports - Model Context Protocol

  1. The server MAY terminate the session at any time, after which it MUST respond to requests containing that session ID with HTTP 404 Not Found.
  2. When a client receives HTTP 404 in response to a request containing an Mcp-Session-Id, it MUST start a new session by sending a new InitializeRequest without a session ID attached.

Steps to Reproduce

  1. MCP server up and running as stateful streamable-http.
  2. Cursor configured to use the MCP server - initialization OK, tool working
  3. Stop the MCP server and start it again without touching Cursor - simulate network outage, server restart, etc.
  4. In Cursor settings, the MCP indicator turns red
  5. Now, trigger Agent to call the tools, ends with {"error": "Error POSTing to endpoint (HTTP 404): Bad Request: No valid session ID provided"}
  6. Reloading the mcp.json file ends with several requests that gets 404 response

Without OFF/ON the MCP server from Cursor settings, there is no way to establish new session with the MCP server

I used modified python mcp=1.12.1 package: streamable_http_manager.py, line 275 to be sure that after connection terminate, the response on client request with session-id which is not known by the server, server response NOT_FOUND with the session_id.
from:

            response = Response(
                "Bad Request: No valid session ID provided",
                status_code=HTTPStatus.BAD_REQUEST,
            )
            await response(scope, receive, send)

to:

            response = Response(
                "Bad Request: No valid session ID provided",
                status_code=HTTPStatus.NOT_FOUND,
                headers={MCP_SESSION_ID_HEADER: request_mcp_session_id},
            )
            await response(scope, receive, send)

Expected Behavior

When receiving http.NOT_FOUND with session_id, the client MUST start a new session, must send InitializeRequest. This will make the handling of stateful MCP server more robust, more reliable on client-server connection problems

Operating System

Linux

Current Cursor Version (Menu → About Cursor → Copy)

Version: 1.6.45
VSCode Version: 1.99.3
Commit: 3ccce8f55d8cca49f6d28b491a844c699b8719a0
Date: 2025-09-22T18:22:38.013Z
Electron: 34.5.8
Chromium: 132.0.6834.210
Node.js: 20.19.1
V8: 13.2.152.41-electron.0
OS: Linux x64 6.8.0-83-generic

Additional Information

MCP client logs from Cursor->output:

2025-09-24 14:22:26.998 [info] Handling CreateClient action
2025-09-24 14:22:26.998 [info] Creating streamableHttp transport
2025-09-24 14:22:26.998 [info] Connecting to streamableHttp server
2025-09-24 14:22:27.018 [info] No stored tokens found
2025-09-24 14:22:27.043 [info] No stored tokens found
2025-09-24 14:22:27.049 [info] Successfully connected to streamableHttp server
2025-09-24 14:22:27.049 [info] Storing streamableHttp client
2025-09-24 14:22:27.049 [info] CreateClient completed, server stored: true
2025-09-24 14:22:27.055 [info] No stored tokens found
2025-09-24 14:22:33.565 [info] Handling ListOfferings action, server stored: true
2025-09-24 14:22:33.565 [info] Connected to streamableHttp server, fetching offerings
2025-09-24 14:22:33.566 [info] No stored tokens found
2025-09-24 14:22:33.575 [info] No stored tokens found
2025-09-24 14:22:33.586 [info] No stored tokens found
2025-09-24 14:22:33.590 [info] Found 1 tools, 0 prompts, and 0 resources

//Restart MCP server

2025-09-24 14:22:43.496 [error] Client error for command SSE stream disconnected: TypeError: terminated
2025-09-24 14:22:44.498 [info] No stored tokens found
2025-09-24 14:22:44.509 [error] Client error for command fetch failed
2025-09-24 14:22:44.509 [error] Client error for command Failed to reconnect SSE stream: fetch failed
2025-09-24 14:22:46.011 [info] No stored tokens found
2025-09-24 14:22:46.015 [error] Client error for command fetch failed
2025-09-24 14:22:46.015 [error] Client error for command Failed to reconnect SSE stream: fetch failed
2025-09-24 14:22:46.015 [error] Client error for command Maximum reconnection attempts (2) exceeded.

//Trigger to Call tool

2025-09-24 14:23:08.097 [info] Handling CallTool action for tool 'nordic_pr_analyzer'
2025-09-24 14:23:08.097 [info] Calling tool 'nordic_pr_analyzer' with toolCallId: tool_ddaec993-ff17-4e81-9fd3-1c531e8920b
2025-09-24 14:23:08.100 [info] No stored tokens found
2025-09-24 14:23:08.106 [error] Client error for command Error POSTing to endpoint (HTTP 400): Bad Request: No valid session ID provided
2025-09-24 14:23:08.106 [error] Error calling tool 'nordic_pr_analyzer': Error POSTing to endpoint (HTTP 400): Bad Request: No valid session ID provided
2025-09-24 14:23:18.466 [info] Handling CreateClient action
2025-09-24 14:23:18.467 [info] CreateClient completed, server stored: true
2025-09-24 14:23:18.486 [info] Handling CreateClient action
2025-09-24 14:23:18.486 [info] CreateClient completed, server stored: true


//Reload mcp.json (make small change in the file and save)

2025-09-24 14:23:31.073 [info] Handling ListOfferings action, server stored: true
2025-09-24 14:23:31.074 [info] Connected to streamableHttp server, fetching offerings
2025-09-24 14:23:31.074 [info] No stored tokens found
2025-09-24 14:23:31.077 [error] Client error for command Error POSTing to endpoint (HTTP 400): Bad Request: No valid session ID provided
2025-09-24 14:23:31.077 [error] Error listing tools: Error POSTing to endpoint (HTTP 400): Bad Request: No valid session ID provided
2025-09-24 14:23:31.087 [info] No stored tokens found
2025-09-24 14:23:31.090 [error] Client error for command Error POSTing to endpoint (HTTP 400): Bad Request: No valid session ID provided
2025-09-24 14:23:31.090 [error] Error listing prompts: Error POSTing to endpoint (HTTP 400): Bad Request: No valid session ID provided
2025-09-24 14:23:31.092 [info] No stored tokens found
2025-09-24 14:23:31.097 [error] Client error for command Error POSTing to endpoint (HTTP 400): Bad Request: No valid session ID provided
2025-09-24 14:23:31.097 [error] Error listing resources: Error POSTing to endpoint (HTTP 400): Bad Request: No valid session ID provided
2025-09-24 14:23:31.097 [info] Found 0 tools, 0 prompts, and 0 resources
...

//Turn OFF and ON of the MCP server from Cursor settings

2025-09-24 14:23:40.041 [info] Handling DeleteClient action
2025-09-24 14:23:40.042 [info] Cleaning up
2025-09-24 14:23:41.498 [info] Handling CreateClient action
2025-09-24 14:23:41.498 [info] Creating streamableHttp transport
2025-09-24 14:23:41.498 [info] Connecting to streamableHttp server
2025-09-24 14:23:41.504 [info] No stored tokens found
2025-09-24 14:23:41.521 [info] No stored tokens found
2025-09-24 14:23:41.525 [info] Successfully connected to streamableHttp server
2025-09-24 14:23:41.525 [info] Storing streamableHttp client
2025-09-24 14:23:41.525 [info] CreateClient completed, server stored: true
2025-09-24 14:23:41.527 [info] No stored tokens found
2025-09-24 14:23:47.919 [info] Handling ListOfferings action, server stored: true
2025-09-24 14:23:47.919 [info] Connected to streamableHttp server, fetching offerings
2025-09-24 14:23:47.920 [info] No stored tokens found
2025-09-24 14:23:47.936 [info] No stored tokens found
2025-09-24 14:23:47.941 [info] No stored tokens found
2025-09-24 14:23:47.947 [info] Found 1 tools, 0 prompts, and 0 resources

Does this stop you from using Cursor

No - Cursor works, but with this issue

5 Likes

Hey, thanks for the report, we’ll look into it.

seeing the same issue this is breaking hosted MCP servers for me

3 Likes

Yeah I’m also seeing this, we have to continuously turn the MCP server off and on or quit and restart Cursor to get it working.

Is there a resolution for this?

There is a PR #1395 in MCP Python-sdk to change the python-sdk behavior to return NOT_FOUND instead of BAD_REQUEST. However, this improvement has been postponed to version 2. Since updating the return code may take some time, I am opting to reinitialize the MCP server even after receiving a BAD_REQUEST (400) response.

Where does the bug appear (feature/product)?

Cursor IDE

Describe the Bug

Upon reconnecting to an MCP server, Cursor reuses a previously valid session ID. The server rejects this with an HTTP 400 Bad Request response. However, the client fails to handle this specific error, does not attempt to establish a new session, and consequently enters an unrecoverable connection state.

Steps to Reproduce

  • Create just a basic MCP server using fastmcp
  • Connect Cursor to the MCP server
  • Use a tool
  • Restart the MCP server
  • Use a tool again

Expected Behavior

Cursor reconnects to the MCP server, if needed initializes a new session and successfully calls the MCP tool

Instead, Cursor does POST to the MCP server, but the session is no longer valid.

{“error”: “Error POSTing to endpoint (HTTP 400): Bad Request: No valid session ID provided”}
After that Cursor is stuck in limbo and this error is always returned. In the MCP settings the server is showing a red dot and the only way to fix this issue is to manually disable and enable the server in settings.

In this situation I would expect Cursor to initialize a new session automatically and continue to successfully call the server’s tools.

Operating System

MacOS

Current Cursor Version (Menu → About Cursor → Copy)

Version: 1.7.52
VSCode Version: 1.99.3
Commit: 9675251a06b1314d50ff34b0cbe5109b78f848c0
Date: 2025-10-17T01:41:03.967Z
Electron: 34.5.8
Chromium: 132.0.6834.210
Node.js: 20.19.1
V8: 13.2.152.41-electron.0
OS: Darwin arm64 24.6.0

Does this stop you from using Cursor

Sometimes - I can sometimes use Cursor

版本: 1.7.54 (user setup)
提交: 1.99.3
日期: 5c17eb2968a37f66bc6662f48d6356a100b67be0
Electron: 2025-10-21T19:07:38.476Z
ElectronBuildId: 34.5.8
Chromium: undefined
Node.js: 132.0.6834.210
V8: 20.19.1
OS: 13.2.152.41-electron.0

It’s still happening :worried:
For what it’s worth, VS Code handles this cleanly. Even with 400 instead of 404

I’m still seeing this bug after an upgrade to Version: 2.1.26
VSCode Version: 1.105.1
Commit: f628a4761be40b8869ca61a6189cafd14756dff0
Date: 2025-11-24T05:39:06.655Z
Electron: 37.7.0
Chromium: 138.0.7204.251
Node.js: 22.20.0
V8: 13.8.258.32-electron.0
OS: Linux x64 6.8.0-87-generic

I also see “This topic will close 22 days after the last reply.”
and it has been 20 days, so this seems like a good time to check in for updates.

Any updates on this issue? It would be great to know if there are any plans to address this before the topic closes. Thank you!

there is a bug in the interface by the way - when it says its not connected or has an error, that is NOT the actual current state (can be stale) - i.e. turning it off and on again makes you think you fixed something (since that fixes the wrong status too), except often it was not broken in the first place.

1 Like

Tested again with version 2.1.36.

The problem still exists, but I observe a change in behavior. Now, when the MCP server disconnects, the Cursor enters an error state, and the Cursor stops detecting the tool in the AI pane—you cannot trigger the LLM to select it.

Reloading the mcp.json file triggers the tool reload, but in the debug logs, I see the following error:

[error] Client error for command Error POSTing to endpoint (HTTP 400): Bad Request: No valid session ID provided

After that, no reinitialization sequence is triggered. The tool remains in an error state and cannot be selected by the LLM.

A new bug in there today as well - will not connect to TLS web servers using the most recent LE certs…

I tested with Cursor 2.2.14 and it seems to be fixed for statefull MCP servers if MCP server responses with HTTP 404. The HTTP 400 does not trigger re-initialization procedure.

So for me it works as expected.

Nevertheless, I found out problem for stateless MCP server you can be interested in: Curosr >=2.2 periodically POST to MCP server to discover tools - how to disable

Peek 2025-12-11 14-52

there’s load of bugs in MCP which are being fixed right now - one is that if any MCP has problems (even disabled ones), Cursor reconnected to EVERY MCP (Even the ones which are OK) every 20s or so, and they have threading problems in their connection code - it can maintain hundreds or thousands of useless simultaneous connections sometimes, which might break your mcp server too.

This topic was automatically closed 22 days after the last reply. New replies are no longer allowed.