Hmz.Core.Testing.Mcp 0.1.0

dotnet add package Hmz.Core.Testing.Mcp --version 0.1.0
                    
NuGet\Install-Package Hmz.Core.Testing.Mcp -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="Hmz.Core.Testing.Mcp" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Hmz.Core.Testing.Mcp" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Hmz.Core.Testing.Mcp" />
                    
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 Hmz.Core.Testing.Mcp --version 0.1.0
                    
#r "nuget: Hmz.Core.Testing.Mcp, 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 Hmz.Core.Testing.Mcp@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=Hmz.Core.Testing.Mcp&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Hmz.Core.Testing.Mcp&version=0.1.0
                    
Install as a Cake Tool

Hmz.Core.Testing.Mcp

Functional-test helpers for applications that expose their endpoints as MCP tools with Hmz.Core.Mcp. They drive the real /mcp route of an in-process test server over Streamable HTTP, so authorization, the write gate, header arguments, ETags and Problem Details are tested end to end. Reference it from test projects only; it is separate from Hmz.Core.Testing, so test projects without MCP do not take the MCP SDK.

Failures throw InvalidOperationException with the tool name, status, error code and detail, so the helpers work with any assertion library.

Connect

await using var client = await McpTestClient.ConnectAsync(
    factory,                                          // WebApplicationFactory<Program>
    new AuthenticationHeaderValue("TestBearer", "alice|ADMIN"),
    ct: TestContext.Current.CancellationToken);
  • route (default /mcp) may carry a query, for example /mcp?tags=Catalog.
  • headers adds headers to every MCP request, for example a request scope such as App-Tenant-Id, which the server forwards to each dispatched call.
  • An overload takes an HttpClient of a test server (TestServer.CreateClient()), resolving the route against its base address.

List and call tools

var names = await client.ToolNamesAsync(ct);                     // sorted, as this caller sees them

var tools = await factory.Services.ToolNamesByEndpointAsync(ct); // endpoint name -> tool name
var created = await client.CallToolExpectingAsync(
    tools["CreateProduct"],
    new Dictionary<string, object?>
    {
        ["tenantId"] = 3,                                         // a header argument of the host
        ["body"] = McpArguments.Json(request, apiJsonOptions),    // Smart Enums, typed ids
    },
    expectedStatus: 201,
    ct);

created.ETag.Should().NotBeNull();
var product = created.BodyAs<ProductResponse>(apiJsonOptions);

var missing = await client.CallToolExpectingAsync(tools["GetProduct"], new Dictionary<string, object?> { ["id"] = 404 }, 404, ct);
missing.Code.Should().Be("CM.NOTF.PRODUCT");

CallToolExpectingAsync requires the dispatched status and that the tool reports an error exactly when the status is 400 or more. CallToolForResultAsync reads the result without an expectation, for example for a discovery tool that dispatches nothing (Status is null).

McpToolCallResult exposes Status, ETag, Body (JSON), Code, Title, Detail, Errors, IsError, the structured Content and the Raw SDK result.

Build and pack

dotnet build Hmz.Core.Testing.Mcp/Hmz.Core.Testing.Mcp.csproj --configuration Release
dotnet pack Hmz.Core.Testing.Mcp/Hmz.Core.Testing.Mcp.csproj --configuration Release --output <package-output>

The package depends on Hmz.Core.Mcp (which brings the MCP SDK client) and Microsoft.AspNetCore.Mvc.Testing. Its tests run in tests/Hmz.Core.Mcp.UnitTests, whose MCP functional tests use it.

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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0 48 11/21/2026