modelcontextprotocol / modelcontextprotocol/csharp-sdk

Provide extensions for calling McpClientTools as tasks

Open
#1,730 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement P3 ready for work
Dominant language
C#
Stars
4.5k
Forks
814
Avg merge
9d 19h
Merged PRs (30d)
4

Description

Is your feature request related to a problem? Please describe.
I would like to be able to call tools as tasks. It would be something like McpClientTool.CallAsTaskAsync or McpClientTool.CallWithPollingAsync. Right now the only way seems to be invoking the tools manually with McpClient, which requires tracking which tool is for which client, and ideally also mapping stuff like metadata.

Describe the solution you'd like
Something like this:

namespace ModelContextProtocol.Extensions.Tasks;

public static class McpTasksClientToolExtensions
{
    public static ValueTask<ResultOrCreatedTask<CallToolResult>> CallAsTaskAsync(this McpClientTool tool, ..., CancellationToken cancellationToken = default);

    public static ValueTask<CallToolResult> CallWithPollingAsync(this McpClientTool tool, int maxConsecutiveStuckPolls = 60, ..., CancellationToken cancellationToken = default);

    public static ValueTask<GetTaskResult> GetTaskAsync(this McpClientTool tool, string taskId, CancellationToken cancellationToken = default);

    public static ValueTask<GetTaskResult> GetTaskAsync(this McpClientTool tool, GetTaskRequestParams requestParams, CancellationToken cancellationToken = default);

    public static ValueTask<CancelTaskResult> CancelTaskAsync(this McpClientTool tool, string taskId, CancellationToken cancellationToken = default);

    public static ValueTask<CancelTaskResult> CancelTaskAsync(this McpClientTool tool, CancelTaskRequestParams requestParams, CancellationToken cancellationToken = default);

    public static ValueTask<UpdateTaskResult> UpdateTaskAsync(this McpClientTool tool, UpdateTaskRequestParams requestParams, CancellationToken cancellationToken = default);
}

the ... indicate placeholders, as I think it may be a good idea to provide additional arguments, similar to McpClientTool.CallAsync.

I am not a fan of all the (Get/Cancel/Update)TaskAsync methods there, because they are just plain wrappers over McpClient, meaning that if you provide a different task ID, they may target a completely unrelated task. Another possible way would be to make CallAsTaskAsync return some object containing the McpClient and the task ID that would make manual polling possible.

Implementation of this will also be a bit tricky because it will require changes in the core package to expose the required data to extensions or/and relying on stuff like InternalsVisibleToAttribute or using reflection/UnsafeAccessors.

I think I may look into implementing this if it would be helpful, but I would likely need a direction as of which ways to choose.

Describe alternatives you've considered
Implementing it myself with UnsafeAccessors.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading McpClientTool.CallAsync and the McpClient task operations described in the issue. Resolve whether extensions should expose direct task wrappers or return a client/task handle, then define completion around safe client/task association and polling behavior. Validate the selected public API against the listed CallAsTaskAsync, CallWithPollingAsync, GetTaskAsync, CancelTaskAsync, and UpdateTaskAsync operations.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.