Skip to content

StreamableHttpClientTransport: maxRetries=0 leads to infinite retry #1179

@010gvr

Description

@010gvr

Describe the bug

The condition in this line https://github.com/modelcontextprotocol/typescript-sdk/blob/main/src/client/streamableHttp.ts#L281 leads to infinite retries when set to 0

 // Check if we've exceeded maximum retry attempts
        if (maxRetries > 0 && attemptCount >= maxRetries) {
            this.onerror?.(new Error(`Maximum reconnection attempts (${maxRetries}) exceeded.`));
            return;
        }

To Reproduce
Steps to reproduce the behavior:

  1. Start a StreamableHttpServer demo
  2. Change the StreamableHttpClientTransport's reconnectionOptions to the following:
reconnectionOptions: {
         maxRetries: 0
}

Expected behavior

Two options:
A - Fix the code to handle 0 to disable retry from client side
B - Document clearly the behavior when set to 0 (although, one could argue -1 to be an appropriate value for it)

Logs
If applicable, add logs to help explain your problem.

Additional context
Add any other context about the problem here.

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