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
<PackageReference Include="Hmz.Core.Testing.Mcp" Version="0.1.0" />
<PackageVersion Include="Hmz.Core.Testing.Mcp" Version="0.1.0" />
<PackageReference Include="Hmz.Core.Testing.Mcp" />
paket add Hmz.Core.Testing.Mcp --version 0.1.0
#r "nuget: Hmz.Core.Testing.Mcp, 0.1.0"
#:package Hmz.Core.Testing.Mcp@0.1.0
#addin nuget:?package=Hmz.Core.Testing.Mcp&version=0.1.0
#tool nuget:?package=Hmz.Core.Testing.Mcp&version=0.1.0
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.headersadds headers to every MCP request, for example a request scope such asApp-Tenant-Id, which the server forwards to each dispatched call.- An overload takes an
HttpClientof 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 | Versions 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. |
-
net10.0
- Hmz.Core.Mcp (>= 0.1.2)
- Microsoft.AspNetCore.Mvc.Testing (>= 10.0.12)
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 |