Get the FREE Ultimate OpenClaw Setup Guide →

mcp -factory

Provides an in-memory test harness for .NET MCP servers, similar to WebApplicationFactory<T> for Web APIs.

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio diomonogatari-mcp-server-factory dotnet path/to/McpServerFactory.dll

How to use

McpServerFactory provides an in-memory, in-process MCP server testing experience for .NET MCP servers. It boots a target MCP server within the test process, wires a real MCP client through in-memory streams, and lets you exercise actual MCP protocol flows (such as tools/list and tools/call) without network ports, containers, or external services. This makes integration tests deterministic and fast while preserving realistic protocol behavior. You can define tool sets and interactions via the provided testing helpers, configure DI and services, and then create a connected MCP client to exercise your server’s tooling surface in a realistic scenario.

To use it, create an integration test project and reference McpServerFactory. Define a configuration that describes the in-process server, and then instantiate the McpServerIntegrationFactory. Use CreateClientAsync to obtain an MCP client connected to the in-process server, and call server tools (for example, tools with a custom Echo tool, or your own tool implementations) through the client’s API. The library also supports template-based test project scaffolding for quickly bootstrapping integration tests, and provides options to suppress host logging or enable debugging output during tests.

How to install

Prerequisites

  • .NET 10.0 SDK or later installed on your development machine.
  • A compatible IDE (e.g., Visual Studio, VS Code) with .NET tooling.

Installation steps

  1. Create your test project (or use an existing one): dotnet new xunit -n MyServer.Tests

  2. Add the McpServerFactory package to your test project: dotnet add package McpServerFactory

  3. If you want the scaffolding templates, install the template pack: dotnet new install McpServerFactory.Templates

  4. (Optional) Bootstrap an MCP integration test project using the provided template: dotnet new mcp-itest -n MyServer.Tests

  5. Restore and build: dotnet restore dotnet build

  6. Run tests or integrate into your CI pipeline as you would with regular .NET tests.

Additional notes

Notes and tips:

  • McpServerFactory runs the MCP server in-process, which means no network ports or Docker are required for integration tests.
  • It provides an in-memory transport compatible with the MCP SDK’s public stream APIs for authentic protocol-level testing.
  • You can override dependency injection and startup configuration via configureMcpServer and related options to tailor the test environment.
  • If you enable logging during tests, you can configure the host logger level and providers to capture detailed debug information when diagnosing failures.
  • The library targets .NET 10.0; ensure your test project aligns with the same framework to avoid runtime issues.
  • Release notes and compatibility with the MCP SDK version are documented in CHANGELOG.md and the project’s references.

Related MCP Servers

Sponsor this space

Reach thousands of developers