Hlibz.Results.Mcp
3.0.0-preview.7
dotnet add package Hlibz.Results.Mcp --version 3.0.0-preview.7
NuGet\Install-Package Hlibz.Results.Mcp -Version 3.0.0-preview.7
<PackageReference Include="Hlibz.Results.Mcp" Version="3.0.0-preview.7" />
<PackageVersion Include="Hlibz.Results.Mcp" Version="3.0.0-preview.7" />
<PackageReference Include="Hlibz.Results.Mcp" />
paket add Hlibz.Results.Mcp --version 3.0.0-preview.7
#r "nuget: Hlibz.Results.Mcp, 3.0.0-preview.7"
#:package Hlibz.Results.Mcp@3.0.0-preview.7
#addin nuget:?package=Hlibz.Results.Mcp&version=3.0.0-preview.7&prerelease
#tool nuget:?package=Hlibz.Results.Mcp&version=3.0.0-preview.7&prerelease
![]()
Hlibz.Results.Mcp
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, underhlibz/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 = falseto send the message instead. - Your own sources: register an
IToolErrorSourceto 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'sForbidden. - Your own filters fail a call with
context.CreateToolError(error), the same tool error, wherever they're registered. One registered beforeWithToolErrorsreadscontext.GetToolError()oncenextreturns;ToolErrorOptions.OnErrorsees 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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Hlibz.Results (>= 3.0.0-preview.7)
- ModelContextProtocol (>= 2.4.0)
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 |