Skip to content

.NET: Add MCP long-running task support for MCP client tools#5994

Open
peibekwe wants to merge 4 commits into
mainfrom
peibekwe/mcp-lro
Open

.NET: Add MCP long-running task support for MCP client tools#5994
peibekwe wants to merge 4 commits into
mainfrom
peibekwe/mcp-lro

Conversation

@peibekwe
Copy link
Copy Markdown
Contributor

Description

Adds Microsoft Agent Framework client-side support for the MCP tasks extension.

A new Microsoft.Agents.AI.Mcp (alpha) package introduces McpClient.ListAgentToolsWithTaskSupportAsync, which wraps any MCP tool advertising task support with a task-aware AIFunction. The wrapper transparently drives the lifecycle inside the agent's function-calling loop.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

@peibekwe peibekwe self-assigned this May 21, 2026
Copilot AI review requested due to automatic review settings May 21, 2026 06:40
@moonbox3 moonbox3 added documentation Improvements or additions to documentation .NET labels May 21, 2026
@github-actions github-actions Bot changed the title Add MCP long-running task support for MCP client tools .NET: Add MCP long-running task support for MCP client tools May 21, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new .NET (alpha) Microsoft.Agents.AI.Mcp package that enables Microsoft Agent Framework agents to transparently invoke MCP tools using the MCP long-running tasks extension (SEP-2663), including polling to completion and best-effort remote cancellation.

Changes:

  • Introduces McpClientTaskExtensions.ListAgentToolsWithTaskSupportAsync(...) to wrap task-capable MCP tools (Optional/Required) in a task-aware AIFunction.
  • Implements TaskAwareMcpClientAIFunction and McpTaskOptions to drive tools/call (task-augmented) → tasks/get polling → tasks/result, with fallback to non-task invocation when needed.
  • Adds unit tests + an end-to-end sample demonstrating transparent long-running task handling, and wires the sample into sample verification + solution.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated no comments.

Show a summary per file
File Description
dotnet/src/Microsoft.Agents.AI.Mcp/Microsoft.Agents.AI.Mcp.csproj New alpha MCP integration package project definition and dependencies.
dotnet/src/Microsoft.Agents.AI.Mcp/McpClientTaskExtensions.cs Adds extension method to list tools and wrap task-capable ones for agent usage.
dotnet/src/Microsoft.Agents.AI.Mcp/McpTaskOptions.cs Defines configurable task lifecycle options (TTL hint + remote-cancel behavior).
dotnet/src/Microsoft.Agents.AI.Mcp/TaskAwareMcpClientAIFunction.cs Implements the task-aware wrapper driving call/poll/result + cancellation handling.
dotnet/tests/Microsoft.Agents.AI.Mcp.UnitTests/Microsoft.Agents.AI.Mcp.UnitTests.csproj Adds new unit test project for the MCP task-aware client functionality.
dotnet/tests/Microsoft.Agents.AI.Mcp.UnitTests/InMemoryMcpServerFixture.cs In-proc server/client fixture for testing tasks behavior without sockets/processes.
dotnet/tests/Microsoft.Agents.AI.Mcp.UnitTests/TestTools.cs Test helper to create MCP tools with specific task support metadata.
dotnet/tests/Microsoft.Agents.AI.Mcp.UnitTests/ListAgentToolsWithTaskSupportTests.cs Validates wrapping behavior + null client argument validation.
dotnet/tests/Microsoft.Agents.AI.Mcp.UnitTests/TaskAwareMcpClientAIFunctionTests.cs Validates happy paths, TTL propagation, cancellation, and failure behavior.
dotnet/tests/Microsoft.Agents.AI.Mcp.UnitTests/McpTaskOptionsTests.cs Verifies option defaults.
dotnet/samples/02-agents/ModelContextProtocol/README.md Adds the new long-running task client sample to the MCP samples index.
dotnet/samples/02-agents/ModelContextProtocol/Agent_MCP_LongRunningTask_Client/README.md New sample documentation describing task support behavior and usage.
dotnet/samples/02-agents/ModelContextProtocol/Agent_MCP_LongRunningTask_Client/Program.cs New sample demonstrating stdio MCP server + client wrapper + Run/RunStreaming.
dotnet/samples/02-agents/ModelContextProtocol/Agent_MCP_LongRunningTask_Client/Agent_MCP_LongRunningTask_Client.csproj New sample project wiring required dependencies and project references.
dotnet/eng/verify-samples/AgentsSamples.cs Registers the new sample for verification.
dotnet/agent-framework-dotnet.slnx Adds new package, test project, and sample to the solution.

@peibekwe peibekwe marked this pull request as ready for review May 21, 2026 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation .NET

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants