---
title: "Resume a C# tool call after user input"
url: https://recursiveai.org/onemodelcontext/cookbook/request-client-retry-with-user-input/
description: "Ask for user input, then finish a C# tool call. See OneModelContext answer the prompt and retry the request on the 2026-07-28 protocol revision."
version: "1.0.2"
---

# Resume a C# tool call after user input

**OneModelContext** is a free, open-source .NET SDK for the Model Context Protocol® from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneModelContext) · [GitHub](https://github.com/recursive-ai-oss/onemodelcontext-csharp) · [Docs](https://recursiveai.org/onemodelcontext/docs/) · [Download example (.zip)](https://recursiveai.org/onemodelcontext/cookbook/request-client-retry-with-user-input/request-client-retry-with-user-input.zip)

The tool asks the client a yes/no question. On the 2026-07-28 revision of the Model Context Protocol®, OneModelContext sends the call again with the answer.

```shell
dotnet add package RecursiveAI.OneModelContext
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

Needs a running server: start the downloaded `preview` server in a separate terminal as shown below.

```csharp
using RecursiveAI.OneModelContext;
// args[0]: preview server URL
await using var client =
    await ModelContext.ConnectAsync(args[0],
        onConfirm: (question, _) =>
        {
            Console.WriteLine(question);
            return ValueTask.FromResult(
                Console.ReadLine() == "yes");
        });
var result =
    await client.CallToolAsync("preview");
Console.WriteLine(result.Text);
```

Unzip [the example](https://recursiveai.org/onemodelcontext/cookbook/request-client-retry-with-user-input/request-client-retry-with-user-input.zip), then `dotnet run`.

That runs the full demo, not the snippet by itself. To run the snippet separately:

1. In the unzipped project, run `dotnet run -- --serve`. Leave it running and copy the URL it prints.
2. In your snippet project, run `dotnet run -- <server-url>`, replacing `<server-url>` with that URL. Type `yes` when asked.

Press Enter in the server terminal when you’re done. The client prints:

```text
Show the draft preview?
Draft preview: Hello, world!
```

## The full program

Run the download with no arguments to start both sides on loopback and answer yes automatically. The tool calls `ConfirmAsync`; the client’s `onConfirm` callback supplies the answer. The two handler entries show that the server reran the tool, not that the client asked the user twice. The core package generates the `AddTo` registration method for the `partial` class.

```csharp
using RecursiveAI.OneModelContext;
using RecursiveAI.OneModelContext.Hosting;
using RecursiveAI.OneModelContext.Http;

var server = new ContextServer("preview", "1.0.0");
new PreviewTools().AddTo(server);
using var endpoint = new StreamableHttpEndpoint(server);
await using var host = new HttpServer(endpoint.HandleAsync);
host.Start();
if (args.Contains("--serve"))
{
    Console.WriteLine(host.BaseAddress);
    Console.ReadLine();
    return;
}

var transport = ContextTransport.Http(host.BaseAddress!);
await using var client = await ModelContext.ConnectAsync(
    transport, era: EraPreference.Modern,
    onConfirm: (question, _) =>
    {
        Console.WriteLine(question);
        // The demo says yes unless you pass --decline.
        var answer = args.Contains("--ask")
            ? string.Equals(Console.ReadLine(), "yes", StringComparison.OrdinalIgnoreCase)
            : !args.Contains("--decline");
        return ValueTask.FromResult(answer);
    });
Console.WriteLine($"Revision: {client.ProtocolVersion}");
var result = await client.CallToolAsync("preview");
Console.WriteLine(result.Text);
if (result.IsError == true) Environment.ExitCode = 1;

public partial class PreviewTools
{
    private int _entries;

    [Tool]
    public async Task<string> Preview(RequestContext context)
    {
        // Trace handler entries only; no business action runs before the ask.
        Console.WriteLine($"Handler entry {Interlocked.Increment(ref _entries)}");
        return await context.ConfirmAsync("Show the draft preview?")
            ? "Draft preview: Hello, world!"
            : "Preview declined.";
    }
}
```

```text
Revision: 2026-07-28
Handler entry 1
Show the draft preview?
Handler entry 2
Draft preview: Hello, world!
```

If the client doesn’t declare support for asking the user, the server returns protocol error `-32021` rather than waiting for an answer.

## Variations

Return a negative answer and see that the tool handles it after the retry:

```shell
dotnet run -- --decline
```

```text
Revision: 2026-07-28
Handler entry 1
Show the draft preview?
Handler entry 2
Preview declined.
```

To answer yourself, use `dotnet run -- --ask` and type `yes` at the prompt.

## Related recipes

- [Ask the user to confirm a tool call](https://recursiveai.org/onemodelcontext/cookbook/ask-the-user-to-confirm/)
- [Connect to a server in C#](https://recursiveai.org/onemodelcontext/cookbook/connect-to-a-server/)
- [Cancel long-running tools](https://recursiveai.org/onemodelcontext/cookbook/cancel-long-running-tools/)

---

## The short answer

Call `context.ConfirmAsync` from the tool and give the client an `onConfirm` callback. Await one `CallToolAsync` in your application. On the 2026-07-28 revision of the Model Context Protocol®, OneModelContext handles the second request for you: it asks the callback, sends the answer, and waits for the final tool result. The server starts the handler from the beginning. To the calling application the original await continues; to the server this is a new attempt, not a continuation of the old stack frame.

## How do I ask for user input during a C# tool call?

A confirmation asks a yes-or-no question; the protocol calls this kind of request *elicitation*. Display the server’s question in your app and return the user’s decision from the client callback. Treat a negative answer as its own branch inside the tool, as the preview example does. For fields such as a choice of destination rather than a yes-or-no answer, the server can use `ElicitAsync` and the client can supply `onElicit`. A client callback belongs on the calling side: it is the app’s chance to show a UI, not permission for the server to read from the client’s terminal.

## Does the tool call continue where it stopped?

Not on 2026-07-28. The [replay guide](https://recursiveai.org/onemodelcontext/docs/multi-round-trip/) says, “The ask ends the current attempt.” The server returns `input_required` and includes the question and `requestState`. The client resends the same request with the state and its `inputResponses`. This time the same `ConfirmAsync` returns the answer, so the handler can produce a preview or decline. On 2025-11-25 and earlier, the same handler code awaits a server-to-client reply on the existing connection instead; the attempt is not replayed.

## How do I avoid doing the same work twice on a retry?

Make work before the last question safe to repeat. For example, read a draft before asking but send it only after an affirmative answer. A trace like `Handler entry` in the download can repeat; a charge or a file append should not. The library can carry strings between attempts in `context.State`. This state travels through the client, which makes it different from private server memory. The default signs it to detect tampering but does not hide its contents; see the [state protection settings](https://recursiveai.org/onemodelcontext/docs/multi-round-trip/#requeststate-is-not-trusted-input) before putting sensitive values there. By default the client stops after eight input rounds rather than retrying forever.
