Skip to content

[Sampling/Elicitation] Stateless servers silently failing on session-requiring features #857

@KKonstantinov

Description

@KKonstantinov

Describe the bug
Streamable HTTP is silently failing when trying to execute a feature that is only supported if sessions are enabled.

Guilty code here:

if (requestId === undefined) {
// For standalone SSE streams, we can only send requests and notifications
if (isJSONRPCResponse(message) || isJSONRPCError(message)) {
throw new Error("Cannot send a response on a standalone SSE stream unless resuming a previous client request");
}
const standaloneSse = this._streamMapping.get(this._standaloneSseStreamId)
if (standaloneSse === undefined) {
// The spec says the server MAY send messages on the stream, so it's ok to discard if no stream
return;
}
// Generate and store event ID if event store is provided
let eventId: string | undefined;
if (this._eventStore) {
// Stores the event and gets the generated event ID
eventId = await this._eventStore.storeEvent(this._standaloneSseStreamId, message);
}
// Send the message to the standalone SSE stream
this.writeSSEEvent(standaloneSse, message, eventId);
return;

It exits at the following:

        // The spec says the server MAY send messages on the stream, so it's ok to discard if no stream
        return;

It does not help that none of the readme docs do not state explicitly that these features require session implementation (which brings other complexities like event store, etc. especially when horizontally scaled).

To Reproduce
Steps to reproduce the behavior:

  1. Run a stateless MCP server
  2. Attempt sampling or elicitation as per README.md - Sampling section
  3. Observe a timeout happening with no clear indication or a specified error.

Expected behavior

  1. Clear error being sent back.
  2. Logging being done.
  3. Not silently returning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions