using System.Text.Json.Nodes;
using ModelContextProtocol.Interceptors.Client;
namespace ModelContextProtocol.Interceptors;
///
/// Configuration options for .
///
///
///
/// Use these options to configure how the executes interceptor
/// chains for MCP tool operations. You can register interceptors, configure timeouts, and control
/// error handling behavior.
///
///
///
/// Creating options with interceptors:
///
/// var options = new InterceptingMcpClientOptions
/// {
/// Interceptors =
/// [
/// McpClientInterceptor.Create(
/// name: "logging",
/// events: [InterceptorEvents.ToolsCall],
/// type: InterceptorType.Observability,
/// handler: (ctx, ct) => { /* log */ })
/// ],
/// DefaultTimeoutMs = 5000,
/// ThrowOnValidationError = true
/// };
///
///
public sealed class InterceptingMcpClientOptions
{
///
/// Gets or sets the collection of interceptors to execute for MCP operations.
///
///
///
/// Interceptors are executed according to SEP-1763 ordering rules:
///
///
/// - Sending (outgoing): Mutations run sequentially by priority, then validations and observability run in parallel.
/// - Receiving (incoming): Validations and observability run in parallel, then mutations run sequentially by priority.
///
///
/// Only interceptors whose match the current operation
/// (e.g., "tools/call") will be executed.
///
///
public IList Interceptors { get; set; } = [];
///
/// Gets or sets the service provider for dependency injection.
///
///
/// If provided, this service provider will be passed to interceptors via the
/// property, allowing
/// interceptors to resolve dependencies.
///
public IServiceProvider? Services { get; set; }
///
/// Gets or sets the default timeout in milliseconds for interceptor chain execution.
///
///
///
/// If the interceptor chain takes longer than this timeout, execution will be aborted
/// and the chain result will have status .
///
///
/// Set to null for no timeout (default). A reasonable production value might be
/// 5000-30000ms depending on interceptor complexity.
///
///
public int? DefaultTimeoutMs { get; set; }
///
/// Gets or sets the default configuration passed to interceptors.
///
///
///
/// This configuration dictionary is merged with any per-call configuration and passed
/// to interceptors. Keys should match interceptor names, and values should be JSON
/// objects containing interceptor-specific configuration.
///
///
///
/// Setting default interceptor configuration:
///
/// options.DefaultConfig = new Dictionary<string, JsonNode>
/// {
/// ["pii-filter"] = JsonNode.Parse("""{"sensitivity": "high", "regions": ["US", "EU"]}"""),
/// ["rate-limiter"] = JsonNode.Parse("""{"maxRequestsPerMinute": 100}""")
/// };
///
///
public IDictionary? DefaultConfig { get; set; }
///
/// Gets or sets a value indicating whether to throw
/// when a validation interceptor fails with error severity.
///
///
///
/// When true (default), the will throw
/// if any validation interceptor returns
/// . The exception contains the full
/// for inspection.
///
///
/// When false, validation errors will not throw exceptions. Instead, the operation
/// will proceed without calling the underlying MCP client, and the caller is responsible
/// for checking results. This mode is primarily useful for testing or scenarios where
/// you want to handle validation failures differently.
///
///
/// true to throw on validation errors; false to continue silently. Default is true.
public bool ThrowOnValidationError { get; set; } = true;
///
/// Gets or sets a value indicating whether to execute interceptors for response/result payloads.
///
///
///
/// When true (default), interceptors will be executed both when sending requests
/// (via ) and when receiving
/// responses (via ).
///
///
/// When false, only request interception is performed. This can be useful when you
/// only need to validate/transform outgoing requests and want to minimize overhead on responses.
///
///
/// true to intercept responses; false to only intercept requests. Default is true.
public bool InterceptResponses { get; set; } = true;
}