Skip to content

Pass request _meta to request handlers extra param #328

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

Merged
merged 1 commit into from
Apr 25, 2025

Conversation

iamarcel
Copy link
Contributor

@iamarcel iamarcel commented Apr 13, 2025

Motivation and Context

The MCP client sends a progress token when calling tools, but there's currently no way for the server (in this SDK) to retrieve this progress token. While the client will receive the progress notifications, it won't associate them with the tool calls and thus it can't properly report on progress.

How Has This Been Tested?

In the inspector, of course, and my chat MCP client (SSE server).

Here's the setup, roughly:

// Server
server.tool(
  "hello",
  { city: z.string() },
  async ({ city }, { sendNotification, _meta }) => {
    if (_meta?.progressToken) {
      await sendNotification({
        method: "notifications/progress",
        params: { progress: 1, progressToken: _meta.progressToken }
      })
    }

    return {
      content: [{ type: "text", text: `Hello, ${city}!` }]
    };
  }
);

// Client
await client.callTool(
  { name: "hello", arguments: { "city": "Ghent" } },
  undefined,
  {
    onprogress: progress => console.log("Hello progress", progress)
  }
);

Breaking Changes

None.

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

This is the smallest possible way to implement the functionality in the SDK, but I'm not convinced on the ergonomics as a user.

I'm open to hear your ideas:

  • Should we add a sendProgress(progress: number, total?:number) in the extra params instead? The Python SDK has a report_progress that it passes to the request context.
  • Does the progressToken make sense, actually? There's already a relatedRequestId passed through by sendNotification—maybe that should be used instead of a separate progress token?

@pulkitsharma07
Copy link

This is helpful, can this be merged @cliffhall ?

@flippinjoe
Copy link

+1 for this. Looks like there's a conflict that needs to fixed

Copy link
Contributor

@cliffhall cliffhall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the ProgressToken gets its own schema, why not the request metadata? Certainly helps with handling that request meta object on its own, since it gets its own inferred type. LGTM! 👍

@jspahrsummers

@ihrpr
Copy link
Contributor

ihrpr commented Apr 25, 2025

Does the progressToken make sense, actually? There's already a relatedRequestId passed through by sendNotification—maybe that should be used instead of a separate progress token?

relatedRequestId is not part the spec, it's an implementation choice, where progressToken in _meta field is part of the spec

Copy link
Contributor

@ihrpr ihrpr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you

@ihrpr
Copy link
Contributor

ihrpr commented Apr 25, 2025

@iamarcel please can you fix the build and then we can merge?

@iamarcel iamarcel reopened this Apr 25, 2025
@iamarcel
Copy link
Contributor Author

@iamarcel please can you fix the build and then we can merge?

Yes! Rebased it on the latest version—the merge before messed up.

@ihrpr ihrpr merged commit 7473694 into modelcontextprotocol:main Apr 25, 2025
3 of 4 checks passed
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.

5 participants