Recursive AI

Migrate from the official C# SDK to OneModelContext

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

OneModelContext is a free, open-source .NET SDK for the Model Context Protocol® from Recursive AI, licensed MIT or Apache-2.0. NuGet · GitHub

dotnet add package RecursiveAI.OneModelContext --version 1.0.2

OneModelContext generates tool registration at build time, 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.csC#
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.csC#
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 folderShell
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. Run the second only in OfficialServer. The official SDK’s server quickstart and v1 client reference describe these interfaces.

Baseline packagesShell
dotnet add package ModelContextProtocol --version 1.4.2
dotnet add package Microsoft.Extensions.Hosting --version 10.0.7
OfficialServer/Program.csC#
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.csC#
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 baselineShell
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; the right follows the OneModelContext 1.0.2 porting reference. These are task mappings, not interchangeable types.

TaskOfficial C# SDKOneModelContext
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 stdioAddMcpServer().WithStdioServerTransport() on a host.ModelContext.ServeAsync(registrar) in the core; for hosted DI use AddContextServer<T>().UseStdio() from RecursiveAI.OneModelContext.Hosting.
Connect over stdioMcpClient.CreateAsync with StdioClientTransport.ContextClient.ConnectAsync with ContextTransport.Process.
List and call toolsListToolsAsync, 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 promptsListResourcesAsync, ReadResourceAsync, GetPromptAsync.Same method names on ContextClient; update arguments and result types at the call sites.
Host over ASP.NET CoreMapMcp() 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 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 before porting a tool that prompts and also writes data.

See OneModelContext 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.