Add validation and error signaling guidance to MCP tool XML docs#1275
Add validation and error signaling guidance to MCP tool XML docs#1275stephentoub merged 4 commits intomainfrom
Conversation
…tion Co-authored-by: stephentoub <[email protected]>
| /// The tool method is responsible for validating its own input arguments (e.g., checking required fields, value ranges, string lengths, or | ||
| /// any other business rules). Data annotations such as <c>RequiredAttribute</c> and | ||
| /// <c>MaxLengthAttribute</c> on parameter types influence the generated JSON schema exposed | ||
| /// to clients, but they are not enforced at runtime by the SDK. Validation should be performed explicitly within the tool method. |
There was a problem hiding this comment.
@jeffhandley / @eiriktsarpalis / @halter73 , do you think the current state of data annotation support is correct, or should the product src actually be validating the annotations?
There was a problem hiding this comment.
We only added data annotation support for Minimal APIs in .NET 10 with dotnet/aspnetcore#60724. As part of this, we did create the https://www.nuget.org/packages/Microsoft.Extensions.Validation package which is used by both Minmal APIs and Blazor and should be a good fit for addressing this. Should we have copilot take a crack at integrating it?
If we decide to hold off until post-1.0, we'll probably be forced to add a separate gesture to opt-in to validating data annotations similar to ASP.NET Core's AddValidation extension method, but we'd might want that anyway to make validation more explicit and avoid duplicating logic.
Co-authored-by: stephentoub <[email protected]>
McpServerToolAttributeXML docs to add explicit validation and error signaling guidanceMcpServerToolXML docs to add matching validation and error signaling guidanceMcpExceptionXML docs to clarify its role in tool validation error signalingTool.DescriptionXML docs to emphasize the importance of good descriptions for input validationCallToolResultXML docs to add guidance on how to signal validation failuresOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.