---
title: "Migrate from the official C# SDK to OneModelContext"
url: https://recursiveai.org/onemodelcontext/articles/migrate-from-official-dotnet-sdk/
description: "Map the C# APIs, keep tool names stable, and test both sides over stdio."
date: 2026-11-27
author: OneModelContext team
---

# Migrate from the official C# SDK to OneModelContext

Map the C# APIs, keep tool names stable, and test both sides over stdio.

November 27, 2026 · OneModelContext team

**OneModelContext** is a free, open-source .NET SDK for the Model Context Protocol® from Recursive AI, licensed [MIT or Apache-2.0](https://www.nuget.org/packages/RecursiveAI.OneModelContext/1.0.2/License). [NuGet](https://www.nuget.org/packages/RecursiveAI.OneModelContext/1.0.2) · [GitHub](https://github.com/recursive-ai-oss/onemodelcontext-csharp/tree/f8d7a692e3f4cf7ce9bf5940ac03eb8fcd0d5c42)

`dotnet add package RecursiveAI.OneModelContext --version 1.0.2`

OneModelContext [generates tool registration at build time](https://recursiveai.org/onemodelcontext/docs/coming-from-the-official-sdk/), and its client tries the 2026-07-28 revision first and falls back to legacy initialization for older servers.

Migrate one side at a time. In a .NET 10 console project named `NewServer`, install OneModelContext and replace `Program.cs`. Tool names default to snake case; `[Tool(Name = "greet")]` pins the name that existing clients already call.

*NewServer/Program.cs · C#*

```
using RecursiveAI.OneModelContext;
 
await ModelContext.ServeAsync(new Greetings());
 
public partial class Greetings
{
    /// <summary>Greet a person.</summary>
    [Tool(Name = "greet")]
    public string Greet(string name) => $"Hello, {name}!";
}
```

In another console project, `NewClient`, install the same package. This client takes the path to the built server DLL as its first argument. It lists the tools before calling `greet`, so a registration or naming change fails the check even before the call.

*NewClient/Program.cs · C#*

```
using RecursiveAI.OneModelContext;
 
await using var client = await ContextClient.ConnectAsync(
    ContextTransport.Process("dotnet", [args[0]]));
var tool = (await client.ListToolsAsync()).Single(t => t.Name == "greet");
var result = await client.CallToolAsync(tool.Name,
    new Dictionary<string, object?> { ["name"] = "Ada" });
Console.WriteLine($"{tool.Name}: {result.Text}");
```

*Run from the parent folder · Shell*

```
dotnet build NewServer
dotnet run --project NewClient -- NewServer/bin/Debug/net10.0/NewServer.dll
```

*Output*

```
greet: Hello, Ada!
```

## The original server and client

For the baseline, create separate .NET 10 console projects named `OfficialServer` and `OfficialClient`. In each project, run the first install command below for [ModelContextProtocol 1.4.2](https://www.nuget.org/packages/ModelContextProtocol/1.4.2). Run the second only in `OfficialServer`. The official SDK’s [server quickstart](https://learn.microsoft.com/en-us/dotnet/ai/quickstarts/build-mcp-server) and [v1 client reference](https://csharp.sdk.modelcontextprotocol.io/v1/api/ModelContextProtocol.Client.McpClient.html) describe these interfaces.

*Baseline packages · Shell*

```
dotnet add package ModelContextProtocol --version 1.4.2
dotnet add package Microsoft.Extensions.Hosting --version 10.0.7
```

*OfficialServer/Program.cs · C#*

```
using System.ComponentModel;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using ModelContextProtocol.Server;
 
var builder = Host.CreateApplicationBuilder(args);
builder.Logging.ClearProviders();
builder.Services.AddMcpServer()
    .WithStdioServerTransport().WithToolsFromAssembly();
await builder.Build().RunAsync();
 
[McpServerToolType]
public static class Greetings
{
    [McpServerTool(Name = "greet"), Description("Greet a person.")]
    public static string Greet(string name) => $"Hello, {name}!";
}
```

*OfficialClient/Program.cs · C#*

```
using ModelContextProtocol.Client;
using ModelContextProtocol.Protocol;
 
await using var client = await McpClient.CreateAsync(
    new StdioClientTransport(new StdioClientTransportOptions
    {
        Name = "Greetings",
        Command = "dotnet",
        Arguments = [args[0]],
    }));
var tool = (await client.ListToolsAsync()).Single(t => t.Name == "greet");
var result = await client.CallToolAsync(tool.Name,
    new Dictionary<string, object?> { ["name"] = "Ada" });
Console.WriteLine($"{tool.Name}: {result.Content.OfType<TextContentBlock>().Single().Text}");
```

*Run the baseline · Shell*

```
dotnet build OfficialServer
dotnet run --project OfficialClient -- OfficialServer/bin/Debug/net10.0/OfficialServer.dll
```

The official pair and both mixed pairs also printed `greet: Hello, Ada!`. To test the mixed pairs, pass the other server’s DLL path to each client. This checks discovery and a text result over stdio, not HTTP, authorization or every tool schema.

## Client and server API map

The left column is for the official SDK’s documented [v1 APIs](https://csharp.sdk.modelcontextprotocol.io/v1/api/ModelContextProtocol.html); the right follows the [OneModelContext 1.0.2 porting reference](https://github.com/recursive-ai-oss/onemodelcontext-csharp/blob/f8d7a692e3f4cf7ce9bf5940ac03eb8fcd0d5c42/docs/coming-from-the-official-sdk.md#L20-L42). These are task mappings, not interchangeable types.

| Task | Official C# SDK | OneModelContext |
|---|---|---|
| Declare and register a tool | `[McpServerToolType]`, `[McpServerTool]`, `[Description]`; register with `WithToolsFromAssembly()`. | `[Tool]` on a method in a `partial` class. Use XML doc comments for descriptions. Pass an instance to `ModelContext.ServeAsync` or call its generated `AddTo(server)`. |
| Serve over stdio | `AddMcpServer().WithStdioServerTransport()` on a host. | `ModelContext.ServeAsync(registrar)` in the core; for hosted DI use `AddContextServer<T>().UseStdio()` from `RecursiveAI.OneModelContext.Hosting`. |
| Connect over stdio | `McpClient.CreateAsync` with `StdioClientTransport`. | `ContextClient.ConnectAsync` with `ContextTransport.Process`. |
| List and call tools | `ListToolsAsync`, `CallToolAsync`; read text blocks in `Content`. | Same method names, different return types. Read `Text` for a text result; inspect `Content` or `Structured` if you need more, and check `IsError`. |
| Read resources or get prompts | `ListResourcesAsync`, `ReadResourceAsync`, `GetPromptAsync`. | Same method names on `ContextClient`; update arguments and result types at the call sites. |
| Host over ASP.NET Core | `MapMcp()` from `ModelContextProtocol.AspNetCore`. | `MapModelContext(path, server)` from `RecursiveAI.OneModelContext.AspNetCore`. Configure authentication and apply authorization on the mapped endpoint if required. |

## What to check before switching traffic

1. **Capture what clients see.** Compare the tool list, input schema, descriptions and annotations. OneModelContext defaults to snake case for tool names. Pin names where clients depend on them and send the same valid and invalid arguments to both servers.
2. **Test the transport you deploy.** Keep stdio logs off stdout. For HTTP, keep the existing path and test both authorized and unauthorized requests through the host. The [HTTP client guide](https://recursiveai.org/onemodelcontext/docs/http-client/) covers supplying your own `HttpClient`.
3. **Test legacy and modern peers.** OneModelContext probes the 2026-07-28 revision by default and can fall back to legacy initialization. If you support both, exercise both deliberately rather than assuming a successful connection used the revision you expected.
4. **Move side effects after user input.** On the modern revision a handler that asks for input can run again. Review [the replay rules](https://recursiveai.org/onemodelcontext/docs/multi-round-trip/) before porting a tool that prompts and also writes data.

See [OneModelContext getting started](https://recursiveai.org/onemodelcontext/docs/getting-started/) for the package and hosting choices.

Model Context Protocol® is a registered trademark of LF Projects, LLC. OneModelContext is an independent project and is not affiliated with or endorsed by LF Projects, LLC or the Model Context Protocol project.
