Add production-ready incremental source generator for automatic Description attributes from XML comments (#899)

Co-authored-by: Stephen Toub <stoub@microsoft.com>
This commit is contained in:
Copilot 2025-11-20 09:14:17 -05:00 • committed by GitHub
commit ad86b53347
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -0,0 +1,31 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text;
using System.Collections.Immutable;
using System.Text;
using System.Xml.Linq;
namespace ModelContextProtocol.Analyzers;
/// <summary>Provides the diagnostic descriptors used by the assembly.</summary>
internal static class Diagnostics
{
public static DiagnosticDescriptor InvalidXmlDocumentation { get; } = new(
id: "MCP001",
title: "Invalid XML documentation for MCP method",
messageFormat: "XML comment for method '{0}' is invalid and cannot be processed to generate [Description] attributes.",
category: "mcp",
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true,
description: "The XML documentation comment contains invalid XML and cannot be processed to generate Description attributes.");
public static DiagnosticDescriptor McpMethodMustBePartial { get; } = new(
id: "MCP002",
title: "MCP method must be partial to generate [Description] attributes",
messageFormat: "Method '{0}' has XML documentation that could be used to generate [Description] attributes, but the method is not declared as partial.",
category: "mcp",
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true,
description: "Methods with MCP attributes should be declared as partial to allow the source generator to emit Description attributes from XML documentation comments.");
}