csharp-sdk/samples/TasksExtension
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Jeff Handley 314bdb2f49
Refine 2.0.0 concept documentation (#1742)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 782b5bad-4046-49ec-93a6-72768b5b7521
Copilot-Session: 4b938335-418c-4ee7-8287-6c70d9148b89
2026-07-27 20:15:16 -07:00
..
Program.cs Refine 2.0.0 concept documentation (#1742) 2026-07-27 20:15:16 -07:00
README.md Refine 2.0.0 concept documentation (#1742) 2026-07-27 20:15:16 -07:00
TasksExtension.csproj Extract Tasks into the ModelContextProtocol.Extensions.Tasks extension package (#1693) 2026-07-14 18:53:58 -04:00

Tasks Extension Sample

Demonstrates the MCP tasks extension (SEP-2663) end-to-end in a single process.

The server is configured with an in-memory IMcpTaskStore, which is sufficient to make any [McpServerTool] method automatically run as a background task when the client opts into the tasks extension on a per-request basis.

The client invokes the run-report tool with CallToolAsTaskAsync (manual poll). It receives a ResultOrCreatedTask<CallToolResult> and, when the server runs the call as a background task, drives the lifecycle directly with GetTaskAsync — polling at the server's suggested cadence until the task reaches a terminal state (Completed, Failed, or Cancelled). If the server returns an inline result instead of creating a task, the sample surfaces that result and stops.

Both ends of the conversation are connected in-process over an in-memory Pipe, so no separate server process or HTTP transport is required.

Run

dotnet run --project samples/TasksExtension/TasksExtension.csproj

Expected output:

=== CallToolAsTaskAsync (manual poll) ===
  task created: id=… status=Working pollIntervalMs=250
  poll 1: still working …
  …
  task completed after N poll(s): report ready

Notes

  • For production deployments — especially stateless HTTP servers — implement IMcpTaskStore against durable storage and register it as a singleton (see docs/concepts/tasks/tasks.md for the contract).