Add validation and error signaling guidance to MCP tool XML docs (#1275)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
This commit is contained in:
Copilot 2026-02-17 19:45:48 -05:00 • committed by GitHub
commit ec4c732632
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 61 additions and 1 deletions

View file

@ -14,6 +14,13 @@ namespace ModelContextProtocol.Protocol;
/// and potentially self-correct in subsequent requests.
/// </para>
/// <para>
/// To return a validation or business-logic error from a tool method, either throw an <see cref="McpException"/>
/// (whose <see cref="Exception.Message"/> will be included in the error result), or declare the tool's return type
/// as <see cref="CallToolResult"/> so it can be returned directly with <see cref="IsError"/> set to <see langword="true"/>
/// and details in <see cref="Content"/>. Using <see cref="CallToolResult"/> as the return type gives the tool full control
/// over both success and error responses.
/// </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>

View file

@ -31,7 +31,15 @@ public sealed class Tool : IBaseMetadata
/// </para>
/// <para>
/// The description is typically presented to AI models to help them determine when
/// and how to use the tool based on user requests.
/// and how to use the tool based on user requests. A well-written description significantly
/// reduces incorrect tool invocations. Include information about what the tool does, any
/// constraints or prerequisites, and what it returns.
/// </para>
/// <para>
/// Similarly, individual parameter descriptions (provided via <see cref="System.ComponentModel.DescriptionAttribute"/>
/// on tool method parameters) are important for guiding the model to supply correct argument values.
/// Descriptions should document expected formats, valid value ranges, and any other constraints
/// the model should be aware of.
/// </para>
/// </remarks>
[JsonPropertyName("description")]