modelcontextprotocol / modelcontextprotocol/java-sdk

Simplify error response when accessing MCP without session ID

Open Beginner friendly
#577 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement waiting for triage
Dominant language
Java
Stars
3.7k
Forks
1.1k
Avg merge
1d 15h
Merged PRs (30d)
9

Description

Description:
Currently, when accessing the MCP Streamable HTTP server at https://host:port/mcp without providing a session ID, the server responds with the full exception stack trace and detailed error information.

Issue:
Returning the complete stack trace in the response is not user-friendly and may expose internal details unnecessarily.

https://github.com/modelcontextprotocol/java-sdk/blob/7f16cd0b9dc72f5adc3358a903bebb0f909dda3e/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStreamableServerTransportProvider.java#L264C4-L264C100

Suggestion:
Instead of returning the full error, return a simple, clear message indicating there is an issue with the request headers or the session ID

stack trace

{
  "cause": null,
  "stackTrace": [
    {
      "moduleName": null,
      "moduleVersion": null,
      "classLoaderName": null,
      "methodName": "doGet",
      "fileName": "HttpServletStreamableServerTransportProvider.java",
      "lineNumber": 268,
      "className": "com.ibm.modelcontextprotocol.server.transport.HttpServletStreamableServerTransportProvider",
      "nativeMethod": false
    },
    {
      "moduleName": null,
      "moduleVersion": null,
      "classLoaderName": null,
      "methodName": "service",
      "fileName": "HttpServlet.java",
      "lineNumber": 527,
      "className": "jakarta.servlet.http.HttpServlet",
      "nativeMethod": false
    },
    {
      "moduleName": null,
      "moduleVersion": null,
      "classLoaderName": null,
      "methodName": "service",
      "fileName": "HttpServlet.java",
      "lineNumber": 614,
      "className": "jakarta.servlet.http.HttpServlet",
      "nativeMethod": false
    }
  ],
  "jsonRpcError": null,
  "message": "text/event-stream required in Accept header; Session ID required in mcp-session-id header",
  "localizedMessage": "text/event-stream required in Accept header; Session ID required in mcp-session-id header",
  "suppressed": []
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at HttpServletStreamableServerTransportProvider.java around line 264 and inspect the GET handling for requests without an mcp-session-id header. Reproduce the request described in the issue, then verify the response gives a simple request or session-ID message without exposing the exception stack trace.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.