---
title: "Register and advertise a tool server extension in C#"
url: https://recursiveai.org/onemodelcontext/cookbook/publish-tool-server-extension/
description: "Register a Model Context Protocol® extension on a C# tool server and advertise its JSON settings so a connecting client can discover them."
version: "1.0.2"
---

# Register and advertise a tool server extension 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/publish-tool-server-extension/publish-tool-server-extension.zip)

Register a Model Context Protocol® extension to tell a client which extra capability your server offers and what settings it uses.

```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 System.Text.Json;
using RecursiveAI.OneModelContext;
using RecursiveAI.OneModelContext.Extensions;

var server = new ContextServer("Exports", "1.0");
using var json = JsonDocument.Parse(
    """{"format":"csv"}""");
var extension = new ExtensionRegistration(
    "com.example/export", json.RootElement);
server.Extensions.Add(extension);
Console.WriteLine(extension.Id);
```

[The example](https://recursiveai.org/onemodelcontext/cookbook/publish-tool-server-extension/publish-tool-server-extension.zip) is the full program below: unzip it and `dotnet run`. To run only the code above, paste it into Program.cs of a new `dotnet new console` project and `dotnet run`.

The snippet registers the extension with its JSON settings and prints its ID:

```text
com.example/export
```

## The full program

The server advertises the inline setting `{"format":"csv"}`. The example connects a client through two in-memory streams and reads the setting from the client’s view of the server. There is no external service or export file.

```csharp
using System.IO.Pipelines;
using System.Text.Json;
using RecursiveAI.OneModelContext;
using RecursiveAI.OneModelContext.Extensions;

const string id = "com.example/export";
var server = new ContextServer("Exports", "1.0");
using var settings = JsonDocument.Parse("""{"format":"csv"}""");
server.Extensions.Add(new ExtensionRegistration(id, settings.RootElement));

var toServer = new Pipe();
var toClient = new Pipe();
var serving = server.RunAsync(ContextTransport.Stream(
    toServer.Reader.AsStream(), toClient.Writer.AsStream()));
await using (var client = await ContextClient.ConnectAsync(
    ContextTransport.Stream(toClient.Reader.AsStream(), toServer.Writer.AsStream()),
    new ContextClientOptions { Extensions = [new ClientExtension(id)] }))
{
    Console.WriteLine($"Advertised: {client.ServerSupportsExtension(id)}");
    var advertised = client.ServerExtensions[id];
    Console.WriteLine($"Format: {advertised.GetProperty("format").GetString()}");
}
await serving;
```

```text
Advertised: True
Format: csv
```

The registration rejects invalid or reserved extension IDs with `ArgumentException`; replace the example prefix with a reversed domain name you own.

## Variations

**Advertise only on one protocol revision.** In the full program, add a `revisions` list to the registration:

```csharp
server.Extensions.Add(new ExtensionRegistration(
    id, settings.RootElement,
    revisions: ["2026-07-28"]));
```

## Related recipes

- [Register a protocol extension method](https://recursiveai.org/onemodelcontext/cookbook/register-protocol-extension/)
- [List a tool server’s capabilities](https://recursiveai.org/onemodelcontext/cookbook/list-tool-server-capabilities/)

---

## The short answer

Pass a namespaced ID and a JSON object to `ExtensionRegistration`, then add it to `ContextServer.Extensions` before serving connections. A client can check the ID with `ServerSupportsExtension` and read the advertised object from `ServerExtensions`. In the example, `format` describes the capability; advertising that setting does not make the server export CSV or register a callable method.

## How does a tool client discover server extension settings?

It reads the extension entries as part of the protocol’s capability exchange, not from the list of tools. In revision `2026-07-28`, the server includes extensions in its `server/discover` capabilities. In `2025-11-25` and earlier revisions, they travel in `capabilities.extensions` during `initialize`. The same `ServerExtensions` property exposes the result on either path. Check for the ID before reading a setting when you don’t control the server. The absence of an ID can mean the server didn’t register it or that the negotiated revision is outside the registration’s revision list.

## What’s the difference between advertising an extension and making it callable?

The ID and settings tell a peer what’s available. To add a callable method, attach a `Request` handler before adding the registration to the server; registration freezes it. A method name can use a suffix such as `/list` under the extension ID so clients can distinguish the method from the extension itself. A peer also has to declare the matching `ClientExtension` to call that method. If it doesn’t, the extension method answers method-not-found even though the server can advertise the extension. Leave the registration optional if clients that don’t know about it should still use the server’s normal features. See the [extension reference](https://recursiveai.org/onemodelcontext/docs/extensions/#methods-and-notifications) for the dispatch rules.
