using Microsoft.Extensions.AI; using ModelContextProtocol.Protocol; using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Nodes; namespace ModelContextProtocol.Server; /// /// Provides options for controlling the creation of an . /// /// /// /// These options allow for customizing the behavior and metadata of tools created with /// . They provide control over naming, description, /// tool properties, and dependency injection integration. /// /// /// When creating tools programmatically rather than using attributes, these options /// provide the same level of configuration flexibility. /// /// public sealed class McpServerToolCreateOptions { /// /// Gets or sets optional services used in the construction of the . /// /// /// These services will be used to determine which parameters should be satisfied from dependency injection. As such, /// what services are satisfied via this provider should match what's satisfied via the provider passed in at invocation time. /// public IServiceProvider? Services { get; set; } /// /// Gets or sets the name to use for the . /// /// /// If , but an is applied to the method, /// the name from the attribute is used. If that's not present, a name based on the method's name is used. /// public string? Name { get; set; } /// /// Gets or sets the description to use for the . /// /// /// If , but a is applied to the method, /// the description from that attribute is used. /// public string? Description { get; set; } /// /// Gets or sets a human-readable title for the tool that can be displayed to users. /// /// /// /// The title provides a more descriptive, user-friendly name for the tool than the tool's /// programmatic name. It is intended for display purposes and to help users understand /// the tool's purpose at a glance. /// /// /// Unlike the tool name (which follows programmatic naming conventions), the title can /// include spaces, special characters, and be phrased in a more natural language style. /// /// public string? Title { get; set; } /// /// Gets or sets a value that indicates whether the tool might perform destructive updates to its environment. /// /// /// if the tool might perform destructive updates to its environment. /// if the tool performs only additive updates. /// The default is . /// /// /// This property is most relevant when the tool modifies its environment (ReadOnly = false). /// public bool? Destructive { get; set; } /// /// Gets or sets a value that indicates whether calling the tool repeatedly with the same arguments /// has no additional effect on its environment. /// /// /// if calling the tool repeatedly with the same arguments /// has no additional effect on the environment; if it does. /// The default is . /// /// /// This property is most relevant when the tool modifies its environment (ReadOnly = false). /// public bool? Idempotent { get; set; } /// /// Gets or sets a value that indicates whether this tool can interact with an "open world" of external entities. /// /// /// if the tool can interact with an unpredictable or dynamic set of entities (like web search). /// if the tool's domain of interaction is closed and well-defined (like memory access). /// The default is . /// public bool? OpenWorld { get; set; } /// /// Gets or sets a value that indicates whether this tool does not modify its environment. /// /// /// If , the tool only performs read operations without changing state. /// If , the tool might make modifications to its environment. /// The default is . /// /// /// Read-only tools do not have side effects beyond computational resource usage. /// They don't create, update, or delete data in any system. /// public bool? ReadOnly { get; set; } /// /// Gets or sets a value that indicates whether the tool should report an output schema for structured content. /// /// /// The default is . /// /// /// When enabled, the tool will attempt to populate the /// and provide structured content in the property. /// public bool UseStructuredContent { get; set; } /// /// Gets or sets an explicit JSON schema to use as the tool's output schema. /// /// /// The default is , which means the output schema is inferred from the return type. /// /// /// /// When set, this schema is used as the instead of the schema /// inferred from the tool method's return type. This is particularly useful when a tool method /// returns directly (to control properties like , /// , or ) but still /// needs to advertise a meaningful output schema to clients. /// /// /// must also be set to for this property to take effect. /// /// public JsonElement? OutputSchema { get; set; } /// /// Gets or sets the JSON serializer options to use when marshalling data to/from JSON. /// /// /// The default is . /// public JsonSerializerOptions? SerializerOptions { get; set; } /// /// Gets or sets the JSON schema options when creating an from a method. /// /// /// The default is . /// public AIJsonSchemaCreateOptions? SchemaCreateOptions { get; set; } /// /// Gets or sets the metadata associated with the tool. /// /// /// Metadata includes information such as attributes extracted from the method and its declaring class. /// If not provided, metadata will be automatically generated for methods created via reflection. /// public IReadOnlyList? Metadata { get; set; } /// /// Gets or sets the icons for this tool. /// /// /// This property can be used by clients to display the tool's icon in a user interface. /// public IList? Icons { get; set; } /// /// Gets or sets metadata reserved by MCP for protocol-level metadata. /// /// /// /// This is used to seed the property. Any metadata from /// instances on the method will be added to this object, but /// properties already present in this will not be overwritten. /// /// /// Implementations must not make assumptions about its contents. /// /// public JsonObject? Meta { get; set; } /// /// Creates a shallow clone of the current instance. /// internal McpServerToolCreateOptions Clone() => new() { Services = Services, Name = Name, Description = Description, Title = Title, Destructive = Destructive, Idempotent = Idempotent, OpenWorld = OpenWorld, ReadOnly = ReadOnly, UseStructuredContent = UseStructuredContent, OutputSchema = OutputSchema, SerializerOptions = SerializerOptions, SchemaCreateOptions = SchemaCreateOptions, Metadata = Metadata, Icons = Icons, Meta = Meta, }; }