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.
dotnet add package RecursiveAI.OneModelContextRequires .NET 10 (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.
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, then dotnet run.
That runs the full demo, not the snippet by itself. To run the snippet separately:
- In the unzipped project, run
dotnet run -- --serve. Leave it running and copy the URL it prints. - In your snippet project, run
dotnet run -- <server-url>, replacing<server-url>with that URL. Typeyeswhen asked.
Press Enter in the server terminal when you’re done. The client prints:
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.
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."; } }
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:
dotnet run -- --declineRevision: 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
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 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 before putting sensitive values there. By default the client stops after eight input rounds rather than retrying forever.