-
Notifications
You must be signed in to change notification settings - Fork 120
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
Unable to access progress token in McpTool
#67
Comments
I'm in the progress of addressing this. |
The CallToolRequestParams is available to an McpServerTool now as of #89, so if _meta is exposed on that, this issue will be addressed. |
Just playing around with the changes in #89 and it's not exposing the Here's a screenshot of the request running: In the If we added it there we can expose it. |
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 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 |
Created a local branch where I deserialize the [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")? |
This aligns more with the type structure see in the other SDK's (eg: https://github.com/modelcontextprotocol/python-sdk/blob/main/src/mcp/types.py#L41) while also ensuring they are exposing the JSONRPCRequest (https://github.com/modelcontextprotocol/specification/blob/main/schema/2024-11-05/schema.json#L771-L806) data. Storing progressToken as an object as it could be an int or string (per https://github.com/modelcontextprotocol/specification/blob/main/schema/2024-11-05/schema.json#L1268-L1274). Fixes modelcontextprotocol#67
Would it make sense to add the everything server, in samples or tests or something? |
…#99) * Adding a base class for request params that exposes the progressToken This aligns more with the type structure see in the other SDK's (eg: https://github.com/modelcontextprotocol/python-sdk/blob/main/src/mcp/types.py#L41) while also ensuring they are exposing the JSONRPCRequest (https://github.com/modelcontextprotocol/specification/blob/main/schema/2024-11-05/schema.json#L771-L806) data. Storing progressToken as an object as it could be an int or string (per https://github.com/modelcontextprotocol/specification/blob/main/schema/2024-11-05/schema.json#L1268-L1274). Fixes #67 * Using usings * Apply suggestions from code review --------- Co-authored-by: Stephen Toub <[email protected]>
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 aHttpRequest
on minimal API.Describe alternatives you've considered
I've looked at the
CallToolRequestParams
when creating your ownCallToolHandler
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
The text was updated successfully, but these errors were encountered: