Skip to content

Unable to access progress token in McpTool #67

Closed

Description

@aaronpowell

Is your feature request related to a problem? Please describe.
I'm attempting to build out a .NET implementation of server-everything and one of the features is the Long Running Operation. This requires access to a progress token (https://github.com/modelcontextprotocol/servers/blob/e328131d99847e1eae33c7a6a8156fd217cf984f/src/everything/everything.ts#L406) to provide notifications back to the client.

There does not appear to be a way to access that in the McpTool method.

Describe the solution you'd like
I think there should be a way to have an argument to the McpTool method that is bound to the request context (or the equivalent _meta property from TypeScript), in the same way you can have a HttpRequest on minimal API.

Describe alternatives you've considered
I've looked at the CallToolRequestParams when creating your own CallToolHandler callback but I don't think you can get to it through that either.

Additional context
Sample Code - https://github.com/aaronpowell/modelcontextprotocol-csharp-sdk/blob/dotnet-everything/samples/EverythingServer/Tools/LongRunningTool.cs

Activity

  1. stephentoub commented on Mar 23, 2025

    @stephentoub
    Contributor

    I'm in the progress of addressing this.

  2. self-assigned this
    on Mar 23, 2025
  3. stephentoub commented on Mar 24, 2025

    @stephentoub
    Contributor

    (or the equivalent _meta property from TypeScript

    The CallToolRequestParams is available to an McpServerTool now as of #89, so if _meta is exposed on that, this issue will be addressed.

  4. removed their assignment
    on Mar 24, 2025
  5. aaronpowell commented on Mar 25, 2025

    @aaronpowell
    ContributorAuthor

    Just playing around with the changes in #89 and it's not exposing the _meta property from the incoming request.

    Here's a screenshot of the request running:

    Image

    In the jsonString variable we can see the _meta is available, along with the progressToken, but the CallToolRequestParams doesn't deserialize that property.

    If we added it there we can expose it.

  6. aaronpowell commented on Mar 25, 2025

    @aaronpowell
    ContributorAuthor

    If I'm reading the JSON schema correctly, part of this is coming from here: https://github.com/modelcontextprotocol/specification/blob/main/schema/2024-11-05/schema.json#L771-L806

    The JSONRPCRequest type defines the _meta property on params as expected, and the description of it matches the description in the TypeScript SDK and Python SDK implementations (probably the others, I didn't dig that far).

    Going through the Python SDK, it seems that they use a base class for many of the request types (which has that property on it), so would it make sense to create a base class in C# that has the _meta property deserialized to it?

  7. aaronpowell commented on Mar 25, 2025

    @aaronpowell
    ContributorAuthor

    Created a local branch where I deserialize the _meta property and this code now works:

    [McpServerToolType]
    public static class LongRunningTool
    {
        [McpServerTool, Description("Demonstrates a long running operation with progress updates")]
        public static async Task<string> LongRunningOperation(
            IMcpServer server,
            RequestContext<CallToolRequestParams> requestParams,
            int duration = 10,
            int steps = 5)
        {
            var stepDuration = duration / steps;
            var progressToken = requestParams?.Params?.Meta?.ProgressToken;
    
            for (int i = 1; i < steps + 1; i++)
            {
                await Task.Delay(stepDuration * 1000);
    
                if (progressToken is not null && server is not null)
                {
                    // Send progress update
                    await server.SendMessageAsync(new JsonRpcNotification
                    {
                        Method = "notifications/progress",
                        Params = new
                        {
                            progressToken,
                            total = steps,
                            progress = i
                        }
                    });
                }
            }
    
            // Return the result
            return $"Operation completed in {duration} seconds with {steps} steps.";
        }
    }

    Would you like me to PR that on top of #89 (the deserialization, not the whole "everything server")?

  8. added a commit that references this issue on Mar 25, 2025
    a487b44
  9. stephentoub commented on Mar 26, 2025

    @stephentoub
    Contributor

    not the whole "everything server"

    Would it make sense to add the everything server, in samples or tests or something?

  10. added a commit that references this issue on Mar 26, 2025
    6fa1443
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions