* Initial plan * Update documentation to clarify error handling per SEP-1303 - Updated McpErrorCode.InvalidParams documentation to clarify it's for protocol-level errors (malformed requests, unknown primitives) - Updated CallToolResult documentation to distinguish between tool execution errors and protocol errors - Updated McpProtocolException documentation to emphasize it's only for protocol-level errors - Added test to verify input validation errors are returned as tool execution errors (IsError=true) - Implementation already correctly handles input validation as tool execution errors per SEP-1303 Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
57 lines
2.5 KiB
C#
57 lines
2.5 KiB
C#
using System.Text.Json.Nodes;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace ModelContextProtocol.Protocol;
|
|
|
|
/// <summary>
|
|
/// Represents the result of a <see cref="RequestMethods.ToolsCall"/> request from a client to invoke a tool provided by the server.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// Tool execution errors (including input validation errors, API failures, and business logic errors)
|
|
/// should be reported inside the result object with <see cref="IsError"/> set to <see langword="true"/>,
|
|
/// rather than as a <see cref="JsonRpcError"/>. This allows language models to see error details
|
|
/// and potentially self-correct in subsequent requests.
|
|
/// </para>
|
|
/// <para>
|
|
/// 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 cref="McpErrorCode"/>.
|
|
/// </para>
|
|
/// <para>
|
|
/// See the <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/">schema</see> for details.
|
|
/// </para>
|
|
/// </remarks>
|
|
public sealed class CallToolResult : Result
|
|
{
|
|
/// <summary>
|
|
/// Gets or sets the response content from the tool call.
|
|
/// </summary>
|
|
[JsonPropertyName("content")]
|
|
public IList<ContentBlock> Content { get; set; } = [];
|
|
|
|
/// <summary>
|
|
/// Gets or sets an optional JSON object representing the structured result of the tool call.
|
|
/// </summary>
|
|
[JsonPropertyName("structuredContent")]
|
|
public JsonNode? StructuredContent { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets or sets an indication of whether the tool call was unsuccessful.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// When set to <see langword="true"/>, it signifies that the tool execution failed.
|
|
/// Tool execution errors (including input validation errors, API failures, and business logic errors)
|
|
/// are reported with this property set to <see langword="true"/> and details in the <see cref="Content"/>
|
|
/// property, rather than as protocol-level errors.
|
|
/// </para>
|
|
/// <para>
|
|
/// This 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 <see cref="Content"/> can explain the issue, enabling the model to retry
|
|
/// with corrected parameters.
|
|
/// </para>
|
|
/// </remarks>
|
|
[JsonPropertyName("isError")]
|
|
public bool? IsError { get; set; }
|
|
}
|