Skip to content

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

Open
Copilot wants to merge 4 commits intomainfrom
copilot/guidance-mcp-tools-validation
Open

Add validation and error signaling guidance to MCP tool XML docs#1275
Copilot wants to merge 4 commits intomainfrom
copilot/guidance-mcp-tools-validation

Conversation

Copy link
Contributor

Copilot AI commented Feb 15, 2026

  • Explore codebase to understand existing docs around tool validation and error handling
  • Update McpServerToolAttribute XML docs to add explicit validation and error signaling guidance
  • Update McpServerTool XML docs to add matching validation and error signaling guidance
  • Update McpException XML docs to clarify its role in tool validation error signaling
  • Update Tool.Description XML docs to emphasize the importance of good descriptions for input validation
  • Update CallToolResult XML docs to add guidance on how to signal validation failures
  • Remove mention of specific validation libraries (FluentValidation) per review feedback
  • Build and verify no errors (0 warnings, 0 errors)
Original prompt

This section details on the original issue you should resolve

<issue_title>Guidance regarding validation with MCP Tools</issue_title>
<issue_description>I am hoping to get some guidance regarding validation when it comes to MCP Tools. Below is just some sample code to help with my questions:

[McpServerToolType]
internal sealed class Update
{

    private static readonly List<ItemRecord> s_items = new(
        [
            new(1, "Item 1", true, "Label 1"),
            new(2, "Item 2", false, "Label 2"),
            new(3, "Item 3", true)
        ]);

    [McpServerTool(Name = "UpdateItem", Title = "Update Item", UseStructuredContent = true), Description("Will update a item.")]
    public static async Task<ItemRecord> ProcessAsync(UpdateRequest request)
    {
        ItemRecord item = s_items
            .Single(i => i.Id == request.Id);

        return await Task.FromResult(
            new ItemRecord(
                item.Id,
                request.Description,
                request.Active,
                item.Label))
            .ConfigureAwait(false);
    }
}

internal sealed record UpdateRequest(int Id, string Description, bool Active);

internal sealed record ItemRecord(int Id, string Description, bool Active, string? Label = null);

Questions:

  • How do I validate UpdateRequest? In a REST API using something like FastEndpoints, I would use FluentValidation to make sure that the request was valid (i.e. required fields, string lengths, etc.) I know I can use Data Annotations on that request object so that the output schema shows those requirements but it doesn't seem to enforce those requirements when the client calls into the server.
  • If I need to manually validate my request, how do I signal back to the client that failure? My current return type is an ItemRecord so how do I handle returning that as a success call and returning a validation failure when validation fails? I assume that whatever the answer is for this, it would apply to when I would go look up an ItemRecord by the Id from he request, and it cannot be found.
  • Is there a way to use FluentValidation instead of DataAnnotations to determine the validation rules in the input and output schema when a tools list is requested?

I appreciate any help that can be provided.</issue_description>

<agent_instructions>Review the questions and recommendations in this issue. Then update the docs / xml comments with guidance if / where necessary, in particular around the importance of good descriptions. </agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…tion

Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Copilot AI changed the title [WIP] Provide guidance on MCP Tools validation Add validation and error signaling guidance to MCP tool XML docs Feb 15, 2026
Copilot AI requested a review from stephentoub February 15, 2026 12:36
/// 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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?

@stephentoub stephentoub marked this pull request as ready for review February 15, 2026 12:46
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Guidance regarding validation with MCP Tools

2 participants