Set server.Completions to suggest prompt argument values without a model call.
dotnet add package RecursiveAI.OneModelContextRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
using RecursiveAI.OneModelContext; using RecursiveAI.OneModelContext .Protocol; var server = new ContextServer( "notes", "1"); server.Completions = (request, _) => ValueTask.FromResult(new CompleteResult { Completion = new CompletionValues { Values = Match( request.Argument.Value) } }); Console.WriteLine( string.Join(", ", Match("py"))); static List<string> Match(string prefix) => new[] { "python", "pyrex", "ruby" } .Where(value => value.StartsWith( prefix, StringComparison.OrdinalIgnoreCase)) .ToList();
Unzip the example, then dotnet run.
The snippet runs the callback’s prefix filter with py. Only the full program sends a completion request from a client to the server.
python, pyrexThe full program
The download registers a review prompt with a language argument and connects the client and server through a named pipe in the same process. The client calls CompleteAsync with py; it does not fetch or run the prompt. ref/prompt tells the server to look for suggestions for a named prompt, here review. The callback checks the reference type, prompt name and argument name before matching values.
using System.IO.Pipes; using RecursiveAI.OneModelContext; using RecursiveAI.OneModelContext.Protocol; var server = new ContextServer("notes", "1.0.0"); server.Prompts.Add(new PromptDefinition("review") { Arguments = [new() { Name = "language", Required = true }] }, (args, _) => ValueTask.FromResult(new GetPromptResult { Messages = [new PromptMessage { Role = "user", Content = TextContent.Of($"Review the {args["language"]} code.") }] })); string[] languages = ["python", "pyrex", "ruby"]; server.Completions = (request, _) => { string[] values = request.Ref.Type == "ref/prompt" && request.Ref.Name == "review" && request.Argument.Name == "language" ? languages.Where(language => language.StartsWith( request.Argument.Value, StringComparison.OrdinalIgnoreCase)).ToArray() : []; return ValueTask.FromResult(new CompleteResult { Completion = new CompletionValues { Values = [.. values] } }); }; using var stop = new CancellationTokenSource(TimeSpan.FromSeconds(10)); string pipe = $"notes-{Guid.NewGuid():N}"; await using var serverPipe = new NamedPipeServerStream(pipe, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous | PipeOptions.CurrentUserOnly); await using var clientPipe = new NamedPipeClientStream(".", pipe, PipeDirection.InOut, PipeOptions.Asynchronous | PipeOptions.CurrentUserOnly); Task accepting = serverPipe.WaitForConnectionAsync(stop.Token); await clientPipe.ConnectAsync(stop.Token); await accepting; Task serving = server.RunAsync(ContextTransport.Stream(serverPipe), stop.Token); await using (var client = await ContextClient.ConnectAsync( ContextTransport.Stream(clientPipe), cancellationToken: stop.Token)) { var request = new CompleteRequestParams { Ref = new() { Type = "ref/prompt", Name = "review" }, Argument = new() { Name = "language", Value = "py" } }; var result = await client.CompleteAsync(request, stop.Token); Console.WriteLine(string.Join(", ", result.Completion.Values)); } await serving.WaitAsync(stop.Token);
python, pyrexIn this example, an unrecognized prompt or argument returns an empty list rather than suggestions for a different field.
Variations
Ask for a longer prefix by changing the request’s argument in the full program:
Argument = new() { Name = "language", Value = "rub" }rubyRelated recipes
The short answer
Set ContextServer.Completions before connecting a client. For an MCP server (Model Context Protocol®), this makes OneModelContext advertise completion support. The client calls CompleteAsync with a ref/prompt reference, the argument’s name and the text typed so far. The server returns strings for the client to offer as suggestions.
How does argument autocomplete work for prompts and resources?
A completion request identifies the thing being completed separately from the field being edited. ref/prompt identifies a prompt by name; ref/resource identifies a resource template by URI. Two prompts can both have an argument called language and still offer different choices: check the reference first, then match the argument. This recipe handles only review.language and uses a fixed list to make the result repeatable.
The suggestions are not prompt messages. An application might show them in a dropdown or accept free text without displaying them at all. When the user picks a value, use that value in a separate request to retrieve the filled-in prompt. Keep validation in the prompt handler if an argument must be one of a fixed set: an autocomplete response doesn’t prevent the client from submitting something else.