using System.Diagnostics.CodeAnalysis; using System.Text.Json.Nodes; using System.Text.Json.Serialization; namespace ModelContextProtocol.Protocol; /// /// Represents the result of a request from a client to invoke a tool provided by the server. /// /// /// /// Tool execution errors (including input validation errors, API failures, and business logic errors) /// should be reported inside the result object with set to , /// rather than as a . This allows language models to see error details /// and potentially self-correct in subsequent requests. /// /// /// To return a validation or business-logic error from a tool method, either throw an /// (whose will be included in the error result), or declare the tool's return type /// as so it can be returned directly with set to /// and details in . Using as the return type gives the tool full control /// over both success and error responses. /// /// /// Protocol-level errors (such as unknown tool names, malformed requests that fail schema validation, /// or server errors) should be reported as MCP protocol error responses using . /// /// /// See the schema for details. /// /// public sealed class CallToolResult : Result { /// /// Gets or sets the response content from the tool call. /// [JsonPropertyName("content")] public IList Content { get; set; } = []; /// /// Gets or sets an optional JSON object representing the structured result of the tool call. /// [JsonPropertyName("structuredContent")] public JsonNode? StructuredContent { get; set; } /// /// Gets or sets a value that indicates whether the tool call was unsuccessful. /// /// /// to signify that the tool execution failed; if it was successful. /// /// /// /// Tool execution errors (including input validation errors, API failures, and business logic errors) /// are reported with this property set to and details in the /// property, rather than as protocol-level errors. /// /// /// This design allows language models to receive detailed error feedback and potentially self-correct /// in subsequent requests. For example, if a date parameter is in the wrong format or out of range, /// the error message in can explain the issue, enabling the model to retry /// with corrected parameters. /// /// [JsonPropertyName("isError")] public bool? IsError { get; set; } /// /// Gets or sets the task data for the newly created task. /// /// /// This property is populated only for task-augmented tool calls. When present, the other properties /// (, , ) may not be populated. /// The actual tool result can be retrieved later via tasks/result. /// [Experimental(Experimentals.Tasks_DiagnosticId, UrlFormat = Experimentals.Tasks_Url)] [JsonIgnore] public McpTask? Task { get => TaskCore; set => TaskCore = value; } // See ExperimentalInternalPropertyTests.cs before modifying this property. [JsonInclude] [JsonPropertyName("task")] internal McpTask? TaskCore { get; set; } }