---
title: "Autocomplete server prompt arguments in C#"
url: https://recursiveai.org/onemodelcontext/cookbook/autocomplete-server-prompt-arguments/
description: "Register a C# completion callback for a Model Context Protocol® prompt and test two prefix matches over a local connection without calling a model."
version: "1.0.2"
---

# Autocomplete server prompt arguments in C#

**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/autocomplete-server-prompt-arguments/autocomplete-server-prompt-arguments.zip)

Set `server.Completions` to suggest prompt argument values without a model call.

```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.

```csharp
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](https://recursiveai.org/onemodelcontext/cookbook/autocomplete-server-prompt-arguments/autocomplete-server-prompt-arguments.zip), 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.

```text
python, pyrex
```

## The 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.

```csharp
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);
```

```text
python, pyrex
```

In 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:

```csharp
Argument = new() { Name = "language", Value = "rub" }
```

```text
ruby
```

## Related recipes

- [Serve prompt templates in C#](https://recursiveai.org/onemodelcontext/cookbook/serve-prompt-templates/)
- [Connect to a server in C#](https://recursiveai.org/onemodelcontext/cookbook/connect-to-a-server/)

## 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](https://modelcontextprotocol.io/specification/2026-07-28/server/utilities/completion) 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.
