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:
parent
841e810167
commit
ec4c732632
2 changed files with 61 additions and 1 deletions
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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")]
|
||||
|
|
|
|||
Loading…
Reference in a new issue