Transport-neutral operation contracts for HTTP, CLI, and MCP. One request type carries the canonical name; member metadata and kind are derived by each host's generator.

Latest prerelease 2.0.0-beta.31
Stable release none yet (prerelease only)
Downloads 2,361
Last published 2026-11-01
Target frameworks net10.0, net11.0

Install

dotnet add package TimeWarp.Contracts --prerelease

NuGet ยท Source


TimeWarp.Contracts

Transport-neutral operation contracts shared by HTTP, CLI, and MCP hosts. One request class is the operation. Each host projects it: an HTTP host supplies the route and verb, and TimeWarp.Nuru supplies CLI and MCP. There is no second schema.

The package publishes from this repository as TimeWarp.Contracts, on its own version line. It targets net10.0 and net11.0. Dependencies are TimeWarp.Mediator (15.0.0-beta.4) and OneOf. The marker interfaces a request implements (IQuery<T>, ICommand, IIdempotentCommand, ...) come from TimeWarp.Mediator.

[Operation]

Apply [Operation(name, Description = ..., Group = ..., Title = ...)] to the request class (Query or Command).

Tool hints

readOnlyHint and idempotentHint come from the kind. The contract states the three hints the kind cannot supply. A generator reads them by metadata name.

The hints belong on a request that has [Operation] with a name that is not blank. The contracts generator and the endpoint emit model ignore [Destructive] and [OpenWorld] without that name. A reflection reader still sees the attributes.

Hint Declaration Catalog field Unset
Title Title on [Operation] OperationDescriptor.Title Null or whitespace
Destructive [Destructive], [Destructive(false)] DestructiveHint Attribute absent. That is not false. MCP clients treat an omitted destructiveHint as true, and they read it only when the tool is not read-only
Open world [OpenWorld], [OpenWorld(false)] OpenWorldHint Attribute absent. MCP clients treat an omitted openWorldHint as true

[Destructive] and [OpenWorld] with no argument are true. [Destructive(true)] is the same claim as a bare [Destructive]. [Destructive(false)] states that the operation only adds data: it does not delete or overwrite. [OpenWorld(false)] states that it only touches local state. destructiveHint does not apply to an IQuery, because that kind is read-only.

[Operation("notes.append", Description = "Append a note to the log.", Title = "Append note")]
[Destructive(false)]
[OpenWorld(false)]
public sealed class AppendNoteCommand : ICommand<string> { }

Metadata names: TimeWarp.Contracts.OperationAttribute (named argument Title), TimeWarp.Contracts.DestructiveAttribute, and TimeWarp.Contracts.OpenWorldAttribute. The constructor parameters are isDestructive and isOpenWorld.

TimeWarp.Nuru has its own [Destructive] and [OpenWorld] with the same constructors. A file that imports both TimeWarp.Contracts and TimeWarp.Nuru gets an ambiguous reference (CS0104) on the bare name. Put the contracts attributes on the contract, and qualify the name ([TimeWarp.Contracts.Destructive]) where both namespaces are in scope.

Kind

Request implements OperationKind
IQuery<TResponse> Query
IIdempotentCommand or IIdempotentCommand<TResponse> IdempotentCommand
ICommand or ICommand<TResponse> Command

Test IIdempotentCommand before ICommand. The idempotent interfaces extend the command interfaces, and the more specific kind wins. IQuery<TResponse> stands on its own. A request that implements none of these is omitted from the catalog. The HTTP verb lives on the HTTP binding, supplied by the host that owns [ApiRoute].

Member derivation

Generators derive member metadata. This package does not reflect over request types.

Field Rule
Name The property's declared identifier, as written on the request.
Required True when the property has the required modifier. Otherwise true when the type is non-nullable and the property has no initializer. A nullable annotation (T?) is not required. required wins over a nullable annotation and over an initializer.
Default The property initializer rendered as source text. Omitted when the property has no initializer. Generators do not invent 0, false, null, or default(T).
Allowed values When the member type is an enum, the enum's named constants in declaration order. Omitted for every other type.
Description System.ComponentModel.DescriptionAttribute.Description on the property. Omitted when the attribute is absent. XML documentation is not this field; HTTP OpenAPI keeps using the request's XML docs.

Catalog

OperationCatalog is the document. --capabilities, OpenAPI, and MCP tools/list are projections of it, not separate schemas.

IResponseRenderer<TResponse>

A CLI or MCP host calls Render when a renderer is registered for the response type, and writes that text. HTTP hosts do not consult it. With no renderer, the host writes JSON.

SharedProblemDetails

The RFC 7807 problem type lives in this assembly, in namespace TimeWarp.Foundation.Types. The namespace stays so TypeForwardedTo in TimeWarp.Foundation.Contracts preserves the identity already compiled into callers. It has no ASP.NET Core dependency.