Table of Contents

Class InputRequiredException

Namespace
ModelContextProtocol.Protocol
Assembly
ModelContextProtocol.Core.dll

The exception that is thrown by a server handler to return an InputRequiredResult to the client, signaling that additional input is needed before the request can be completed.

public class InputRequiredException : Exception, ISerializable
Inheritance
InputRequiredException
Implements
Inherited Members

Examples

[McpServerTool, Description("A stateless tool using MRTR")]
public static string MyTool(McpServer server, RequestContext<CallToolRequestParams> context)
{
    if (context.Params.RequestState is { } state)
    {
        // Retry: process accumulated state and input responses
        var responses = context.Params.InputResponses;
        return "Final result";
    }

    if (!server.IsMrtrSupported)
    {
        return "This tool requires MRTR support.";
    }

    throw new InputRequiredException(
        inputRequests: new Dictionary<string, InputRequest>
        {
            ["user_input"] = InputRequest.ForElicitation(new ElicitRequestParams { ... })
        },
        requestState: "encoded-state");
}

Remarks

This exception is part of the Multi Round-Trip Requests (MRTR) API. Tool handlers throw this exception to directly control the input-required result payload, including InputRequests and RequestState.

For stateless servers, this enables multi-round-trip flows without requiring the handler to stay alive between round trips. The server encodes its state in RequestState and receives it back on retry via RequestState.

To return a requestState-only response (e.g., for load shedding), omit InputRequests and set only RequestState. The client will retry the request with the state echoed back.

This exception can only be used when MRTR is supported by the client. Check IsMrtrSupported before throwing. If thrown when MRTR is not supported, the exception will propagate as a JSON-RPC internal error.

Constructors

InputRequiredException(InputRequiredResult)

Initializes a new instance of the InputRequiredException class with the specified InputRequiredResult.

public InputRequiredException(InputRequiredResult result)

Parameters

result InputRequiredResult

The input-required result to return to the client.

InputRequiredException(IDictionary<string, InputRequest>?, string?)

Initializes a new instance of the InputRequiredException class with the specified input requests and/or request state.

public InputRequiredException(IDictionary<string, InputRequest>? inputRequests = null, string? requestState = null)

Parameters

inputRequests IDictionary<string, InputRequest>

Server-initiated requests that the client must fulfill before retrying. Keys are server-assigned identifiers.

requestState string

Opaque state to be echoed back by the client when retrying. The client must treat this as an opaque blob and must not inspect or modify it.

Exceptions

ArgumentException

Both inputRequests and requestState are null. At least one must be provided.

Properties

Result

Gets the input-required result to return to the client.

public InputRequiredResult Result { get; }

Property Value

InputRequiredResult