Hlibz.Results.Mcp 3.0.0-preview.7

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

Hlibz.Results.Mcp icon

Hlibz.Results.Mcp

NuGet CI

Turns Hlibz.Results errors into MCP tool errors a model can act on. An error's message says what failed, for your logs; guidance says what to do next, in terms of your tools, for the model.

dotnet add package Hlibz.Results.Mcp
[McpServerTool(Name = "delete_city")]
[ToolErrors<DeleteCityError>]   // the error set the tool's result declares
[ToolError<ValidationFailed>]   // an ambient error it can fail with too
public static async Task<Unit> DeleteAsync(CityService cities, Guid cityId, CancellationToken ct) =>
    (await cities.DeleteAsync(cityId, ct)).ValueOrThrow();

builder.Services.AddMcpServer()
    .WithToolsFromAssembly()
    .WithToolErrors(errors => errors
        .Guide<CityNotFound>("No city has id {cityId}. Call list_cities to find its id.")
        .Guide<CityInUse>("{userCount} users live in the city. Ask the user whether to move them first.")
        .Guide<ValidationFailed>("Fix these arguments and call the tool again: {errors}"));

A failed call comes back as a tool error, its placeholders filled from the error's data ({message} is the error's own message). A placeholder the error doesn't have, misspelled or left behind when a property was renamed, fails the build (HRES007, from Hlibz.Results' analyzer) and the server's start:

{
  "isError": true,
  "content": [{ "type": "text", "text": "city_in_use: 3 users live in the city. Ask the user whether to move them first." }],
  "structuredContent": { "code": "city_in_use", "details": { "cityId": "6f1c…", "userCount": 3 } }
}
  • Each tool lists its errors in its _meta, under hlibz/errors: [{ "code", "description", "guidance" }], where the description is the error's declared message. Any client can read them, and Hlibz.McpDocs.AspNetCore shows them on its docs page.
  • The server doesn't start while a tool's error has no guidance, or guidance names a detail its error doesn't have. Set RequireGuidance = false to send the message instead.
  • Your own sources: register an IToolErrorSource to work out a tool's errors some other way, such as from the use case it runs. Its errors follow the declared ones. EveryToolCanFailWith<TError>() lists an error on every tool, or on those a predicate picks, such as a filter's Forbidden.
  • Your own filters fail a call with context.CreateToolError(error), the same tool error, wherever they're registered. One registered before WithToolErrors reads context.GetToolError() once next returns; ToolErrorOptions.OnError sees every tool error, for logging.
  • Details are written with the MCP SDK's JSON options, in camelCase like your tools' results. A ValidationFailed's keys are converted too: items[0].unitPrice.

Tools return their value, which the MCP SDK serializes before any filter sees it, so a tool unwraps its result with ValueOrThrow() (or ThrowIfFailed()). Without WithToolErrors, the ToolErrorException it throws is still an McpException, sent as "code: message".

Works with the MCP C# SDK (ModelContextProtocol) 2.4.0 and later.

Targets .NET 11 (C# 15 unions). .NET 10 apps stay on 2.x.

A family of packages

One of five packages I build to set up new .NET APIs the way I want them: Hlibz.Results, Hlibz.UseCases, Hlibz.MinimalApi.Endpoints, Hlibz.OpenApi and Hlibz.Paging. Each works on its own, and they work best together, as in Hlibz.Stack. New minor and major versions come often, a new major whenever .NET gives me a better way to do something. Breaking changes only ever come in a major and are listed first in its release notes. You're welcome to use the packages, and to open an issue when something is wrong or missing.

Full documentation and samples: github.com/hlib-zinchenko/Hlibz.Results.

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
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 Hlibz.Results.Mcp:

Package Downloads
Hlibz.UseCases.Mcp

Serves Hlibz.UseCases use cases as MCP tools (MCP C# SDK): WithUseCaseTools registers your [McpServerTool] methods with schema options WithToolsFromAssembly can't take, so their input and output schemas say what the use cases check, in the same words as Hlibz.OpenApi's documents: strongly-typed IDs as the value they wrap (a uuid string), XML summaries as descriptions (Hlibz.XmlDocs.AI), and every IDescribedRule and [RuleSummary] as JSON Schema keywords and a sentence, on types, properties, record parameters and tool parameters. Optionally names the tool parameters by a naming policy (snake_case). Each tool lists the errors its use case can fail with (its error set, ValidationFailed, the filters' ambient errors) for Hlibz.Results.Mcp, so no tool declares its own.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.0-preview.7 41 12/1/2026
3.0.0-preview.6 50 12/1/2026
3.0.0-preview.5 48 12/1/2026
3.0.0-preview.4 82 11/29/2026
3.0.0-preview.3 106 11/27/2026
3.0.0-preview.2 67 11/27/2026
3.0.0-preview.1 75 11/27/2026