Provide extensions for calling McpClientTools as tasks
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 38/100
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.
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.
- Dominant language
- C#
- Stars
- 4.5k
- Forks
- 814
- Avg merge
- 9d 19h
- Merged PRs (30d)
- 4
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from modelcontextprotocol/csharp-sdk
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
modelcontextprotocol/csharp-sdk#1867 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
modelcontextprotocol/csharp-sdk#1840 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
modelcontextprotocol/csharp-sdk#1836 ·
-
enhancement needs confirmation
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
modelcontextprotocol/csharp-sdk#678 · 1 comment ·
-
enhancement needs confirmation P3 ready for work
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
modelcontextprotocol/csharp-sdk#515 · 6 comments · 3 reactions ·
All issues in modelcontextprotocol/csharp-sdk
Similar issues
-
type/automation type/tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
t/bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
ci-failure-cause test-failure
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
area:auth FE mvp P3
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
klasolsson81/jobbliggaren#1788 ·