Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make onprogress handler optional for progress flow #262

Conversation

pulkitsharma07
Copy link

@pulkitsharma07 pulkitsharma07 commented Apr 5, 2025

The protocol implementation indirectly mandates an onprogress handler to be set while making a request to a Server which is expected to send Progress notifications.

The behaviour requirements in the protocol don't seem to mandate this onprogress callback in the Sender. Hence, IMO onprogress handler should be optional. In case client is interested in logging/processing the progress updates) they can set it otherwise they should not be required to pass in the onprogress callback.

This was discovered while working on modelcontextprotocol/inspector#271.

To demonstrate further

Currently in order for progress notification based timeout resets to work, this is the minimum setup:

      const requestPromise = protocol.request(request, mockSchema, {
        timeout: 1000,
        resetTimeoutOnProgress: true,
        onprogress: (progress) => {
                  console.log("made some progress", progress);
        },
      });

^ Here onprogress is mandatory due to the way _onprogress hook is implemented in the protocol, it checks for presence of a progressHandler which is only set when using onprogress

Post this PR, the following would work (added test for the same):

      const requestPromise = protocol.request(request, mockSchema, {
        timeout: 1000,
        resetTimeoutOnProgress: true,
      });

How Has This Been Tested?

  • Added tests for the same

Breaking Changes

  • No

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

@jspahrsummers
Copy link
Member

A progress token is only assigned when onprogress is set, so it's an error for the server to issue progress notifications otherwise (i.e., the currently implemented behavior is correct).

We could change the SDK to create a progress token even without an onprogress, but I think this is somewhat unintuitive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants