McpServerFactory 0.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package McpServerFactory --version 0.1.0
                    
NuGet\Install-Package McpServerFactory -Version 0.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="McpServerFactory" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="McpServerFactory" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="McpServerFactory" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add McpServerFactory --version 0.1.0
                    
#r "nuget: McpServerFactory, 0.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package McpServerFactory@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=McpServerFactory&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=McpServerFactory&version=0.1.0
                    
Install as a Cake Tool

McpServerFactory

NuGet NuGet Downloads CI codecov license .NET 10.0 Status: 0.1.0

In-memory integration testing factory for .NET Model Context Protocol (MCP) servers.

McpServerFactory gives .NET MCP servers a testing experience similar in spirit to WebApplicationFactory<T> for ASP.NET Core. It boots an MCP server in-process, connects a real McpClient through in-memory streams, and lets you run realistic integration tests without network ports, Docker, or external services.

Installation

dotnet add package McpServerFactory

Template-based scaffolding

Install the template pack to bootstrap an MCP integration test project:

dotnet new install McpServerFactory.Templates
dotnet new mcp-itest -n MyServer.Tests

The mcp-itest template accepts --McpServerFactoryVersion to override the package version (default 0.1.0).

Quick start

using McpServerFactory.Testing;
using ModelContextProtocol.Server;

[McpServerToolType]
public sealed class EchoTools
{
    [McpServerTool(Name = "echo")]
    public string Echo(string message)
    {
        return message;
    }
}

await using var factory = new McpServerIntegrationFactory(
    configureMcpServer: builder => builder.WithTools<EchoTools>());

await using var client = await factory.CreateClientAsync();

var result = await client.CallToolAsync(
    "echo",
    arguments: new Dictionary<string, object?> { ["message"] = "hello" });

Why use this library

  • In-memory transport using the MCP SDK's public stream APIs.
  • Real MCP protocol flow (tools/list, tools/call) in tests.
  • Easy dependency overrides through configureServices and ConfigureServices.
  • Framework-agnostic library (works with xUnit, NUnit, MSTest, etc.).

Behavioral guarantees

  • CreateClientAsync is thread-safe and idempotent per factory instance.
  • Concurrent calls return the same connected McpClient instance.
  • Startup failures do not leak the temporary host instance.
  • DisposeAsync is safe to call multiple times.
  • CreateClientAsync throws ObjectDisposedException after disposal.

Compatibility and support

  • Target framework: net10.0.
  • MCP SDK dependency: ModelContextProtocol 0.4.0-preview.3.
  • Compatibility promise: each package release is validated against the pinned MCP SDK version.
  • Upgrade policy: MCP SDK bumps are explicit and called out in CHANGELOG.md.

API overview

  • McpServerFactory
    • Backward-compatible factory entry point.
  • McpServerIntegrationFactory
    • Preferred factory type for new code.
    • Starts an in-process server host.
    • Creates a connected McpClient via CreateClientAsync().
    • Exposes Services for DI validation after startup.
  • McpServerFactoryOptions
    • Configure server identity, startup/disposal timeouts, and instructions.
    • Suppress host logging by default and optionally customize logging.
  • McpTestClient
    • Convenience wrapper for common test operations.

Logging in test output

By default, host logging providers are suppressed to keep test output clean. To enable custom logging during tests:

using Microsoft.Extensions.Logging;

var options = new McpServerFactoryOptions
{
    SuppressHostLogging = false,
    ConfigureLogging = logging => logging.SetMinimumLevel(LogLevel.Debug),
};

Release notes

See CHANGELOG.md for release history and upcoming changes.

Samples

Repository layout

  • src/McpServerFactory — reusable factory library.
  • tests/McpServerFactory.Tests — unit/integration-focused library tests.
  • templates/McpServerFactory.Templatesdotnet new template pack.
  • samples/MinimalSmoke — runnable sample console app.
  • docs — architecture notes and usage guidance.
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on McpServerFactory:

Package Downloads
McpServerFactory.Xunit

xUnit fixtures for McpServerFactory: boot an in-memory MCP server once per test class via IClassFixture.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 130 6/5/2026
0.2.0 73 6/5/2026
0.1.0 93 2/13/2026