csharp-sdk/samples/TasksExtension/README.md
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

39 lines
1.6 KiB
Markdown

# Tasks Extension Sample
Demonstrates the MCP tasks extension ([SEP-2663](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/seps/2663-tasks-extension.md)) 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
```bash
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](../../docs/concepts/tasks/tasks.md) for the contract).