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
1.6 KiB
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
IMcpTaskStoreagainst durable storage and register it as a singleton (see docs/concepts/tasks/tasks.md for the contract).