Table of Contents

Class ResultOrCreatedTask<TResult>

Namespace
ModelContextProtocol.Protocol
Assembly
ModelContextProtocol.Core.dll

Represents the result of a request that supports task-augmented execution, which may be either the standard result or a CreateTaskResult indicating asynchronous processing.

public class ResultOrCreatedTask<TResult> where TResult : Result

Type Parameters

TResult

The standard result type for the request (e.g., CallToolResult).

Inheritance
ResultOrCreatedTask<TResult>
Inherited Members

Remarks

When a server supports the io.modelcontextprotocol/tasks extension and the client declares the extension capability on its request, the server may return a CreateTaskResult instead of the standard result. This type represents that polymorphic response.

Use IsTask to determine which variant was returned, then access either Result for the immediate result or TaskCreated for the task handle.

See the SEP-2663 specification for details.

Constructors

ResultOrCreatedTask(CreateTaskResult)

Initializes a new instance of ResultOrCreatedTask<TResult> with a task handle.

public ResultOrCreatedTask(CreateTaskResult taskCreated)

Parameters

taskCreated CreateTaskResult

The task creation result returned by the server.

ResultOrCreatedTask(TResult)

Initializes a new instance of ResultOrCreatedTask<TResult> with an immediate result.

public ResultOrCreatedTask(TResult result)

Parameters

result TResult

The standard result returned by the server.

Properties

IsTask

Gets a value indicating whether the server created a task instead of returning an immediate result.

public bool IsTask { get; }

Property Value

bool

Result

Gets the immediate result, or null if the server created a task.

public TResult? Result { get; }

Property Value

TResult

TaskCreated

Gets the task creation result, or null if the server returned an immediate result.

public CreateTaskResult? TaskCreated { get; }

Property Value

CreateTaskResult

Operators

implicit operator ResultOrCreatedTask<TResult>(CreateTaskResult)

Implicitly converts a CreateTaskResult to a ResultOrCreatedTask<TResult> wrapping the task handle.

public static implicit operator ResultOrCreatedTask<TResult>(CreateTaskResult taskCreated)

Parameters

taskCreated CreateTaskResult

The task creation result to wrap.

Returns

ResultOrCreatedTask<TResult>

implicit operator ResultOrCreatedTask<TResult>(TResult)

Implicitly converts a TResult to a ResultOrCreatedTask<TResult> wrapping the immediate result.

public static implicit operator ResultOrCreatedTask<TResult>(TResult result)

Parameters

result TResult

The result to wrap.

Returns

ResultOrCreatedTask<TResult>