Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 3, 2025

The MCP C# SDK v0.5.0-preview.1 has fixed the blocking limitations that previously prevented implementation of the XML Documentation Generator. This PR implements the conversion from manual [Description] attributes to XML documentation comments for tool methods.

Status: In Progress (33/62 methods converted - 53%)

SDK v0.5.0-preview.1 has resolved the issues with optional parameters and async methods that blocked this feature in v0.4.1-preview.1.

Changes Made

  • Enable XML documentation file generation in project
  • Update CS1591 suppression comment to reflect active source generator usage
  • Made DotNetCliTools class partial to enable source generator
  • Converted 33 tool methods to use XML documentation pattern:
    • Template tools (5): DotnetTemplateList, DotnetTemplateSearch, DotnetTemplateInfo, DotnetTemplateClearCache, DotnetCacheMetrics
    • Framework tool (1): DotnetFrameworkInfo
    • Project tools (7): DotnetProjectNew, DotnetProjectRestore, DotnetProjectBuild, DotnetProjectRun, DotnetProjectTest, DotnetProjectPublish, DotnetProjectClean
    • Watch tools (3): DotnetWatchRun, DotnetWatchTest, DotnetWatchBuild
    • Package tools (8): DotnetPackCreate, DotnetPackageAdd, DotnetPackageList, DotnetPackageRemove, DotnetPackageSearch, DotnetPackageUpdate
    • Reference tools (3): DotnetReferenceAdd, DotnetReferenceList, DotnetReferenceRemove
    • Solution tools (4): DotnetSolutionCreate, DotnetSolutionAdd, DotnetSolutionList, DotnetSolutionRemove
    • SDK tools (4): DotnetSdkInfo, DotnetSdkVersion, DotnetSdkList, DotnetRuntimeList
    • Help tools (2): DotnetHelp, DotnetServerCapabilities

Verified Working

Optional parameter defaults ARE preserved in SDK v0.5.0-preview.1
Async methods work correctly without manual workarounds
✅ All 300 tests passing
✅ Description attributes generated correctly from XML <summary> tags
✅ Parameter descriptions generated correctly from XML <param> tags

Pattern

Methods are converted from:

[McpServerTool, Description("Build a .NET project")]
public async Task<string> DotnetProjectBuild(
    [Description("The project file")] string? project = null)
{
    // implementation
}

To:

/// <summary>
/// Build a .NET project.
/// </summary>
/// <param name="project">The project file</param>
[McpServerTool]
public async partial Task<string> DotnetProjectBuild(string? project = null)
{
    // implementation
}

The source generator automatically creates the [Description] attributes from the XML documentation.

Remaining Work

29 methods remaining to convert:

  • ServerInfo (1)
  • Format/NuGet tools (2)
  • Security/Certificate tools (4)
  • User Secrets tools (5)
  • Tool Management tools (7)
  • EF Core tools (10)

The conversion is straightforward and can be completed incrementally using the established pattern.

Original prompt

This section details on the original issue you should resolve

<issue_title>Implement XML Documentation Generator for Tool Methods</issue_title>
<issue_description>## Overview

The MCP C# SDK v0.4.1-preview.1 includes a production-ready source generator that automatically creates [Description] attributes from XML documentation comments. This feature would reduce maintenance burden and improve IDE experience by using a single source of truth for documentation.

Current State

Our codebase has:

  • 100+ manual [Description] attributes across all tool methods and parameters
  • ~1400 lines of documentation spread across DotNetCliTools.cs
  • Duplicate information (XML comments would appear in IDE IntelliSense AND generate MCP descriptions)

Benefits

  1. Reduced Maintenance: Single source of truth for documentation
  2. Better IDE Experience: XML comments provide IntelliSense support
  3. Automatic Sync: Descriptions automatically update with XML comments
  4. .NET Best Practices: Follows standard .NET documentation conventions
  5. Built-in Feature: Source generator is included in SDK, no additional dependencies

How It Works

The source generator (introduced in #899) automatically generates [Description] attributes from XML comments for partial methods tagged with MCP attributes.

Pattern

Before (Current):

[McpServerTool, Description("Build a .NET project")]
public async Task<string> DotnetProjectBuild(
    [Description("The project file")] string? project = null)
{
    // implementation
}

After (With XML Generator):

/// <summary>
/// Build a .NET project
/// </summary>
/// <param name="project">The project file</param>
[McpServerTool]
public partial Task<string> DotnetProjectBuild(string? project = null);

// Implementation in same file
public async partial Task<string> DotnetProjectBuild(string? project)
{
    // implementation
}

The source generator automatically creates:

[Description("Build a .NET project")]
public partial Task<string> DotnetProjectBuild([Description("The project file")] string? project = null);

Requirements

  1. Class must be partial: public sealed partial class DotNetCliTools
  2. Methods must be partial: Declaration + implementation pattern
  3. XML documentation: Use /// <summary>, /// <param>, /// <returns>
  4. Enable XML generation: Add <GenerateDocumentationFile>true</GenerateDocumentationFile> to project

Implementation Approach

Phase 1: Setup

  • Update to MCP SDK v0.4.1-preview.1 (completed in #XXX)
  • Mark DotNetCliTools class as partial
  • Enable XML documentation file generation in project

Phase 2: Incremental Conversion

Convert methods incrementally by category to minimize risk:

  1. Template tools (5 methods) - Test the pattern
  2. Project tools (10 methods) - Validate approach
  3. Package tools (8 methods)
  4. Solution tools (8 methods)
  5. SDK/Runtime tools (10 methods)
  6. Remaining tools (60+ methods)

Phase 3: Verification

  • Verify all tool descriptions are preserved
  • Check IntelliSense works correctly
  • Run full test suite
  • Test with MCP Inspector
  • Verify generated code in obj/ directory

Risks & Considerations

Risks

  • Large refactor (~1400 lines changed)
  • Potential for regressions if descriptions don't match exactly
  • Partial method pattern is less familiar to contributors
  • Requires careful testing of all tools

Mitigations

  • Incremental approach (convert category by category)
  • Comprehensive testing after each phase
  • Keep PR focused and reviewable
  • Document the pattern clearly for future contributors

Example Conversion

Current Code:

[McpServerTool, Description("List all installed .NET templates with their metadata using the Template Engine. Provides structured information about available project templates.")]
[McpMeta("category", "template")]
[McpMeta("commonlyUsed", true)]
public async Task<string> DotnetTemplateList(
    [Description("If true, bypasses cache and reloads templates from disk")] bool forceReload = false)
    => await TemplateEngineHelper.GetInstalledTemplatesAsync(forceReload, _logger);

Converted Code:

/// <summary>
/// List all installed .NET templates with their metadata using the Template Engine. 
/// Provides structured information about available project templates.
/// </summary>
/// <param name="forceReload">If true, bypasses cache and reloads templates from disk</param>
[McpServerTool]
[McpMeta("category", "template")]
[McpMeta("commonlyUsed", true)]
public partial Task<string> DotnetTemplateList(bool forceReload = false);

public async partial Task<string> DotnetTemplateList(bool forceReload)
    => await TemplateEngineHelper.GetInstalledTemplatesAsync(forceReload, _logger);

Success Criteria

  • All tool methods use XML documentatio...

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits December 3, 2025 19:20
…teList

Co-authored-by: jongalloway <68539+jongalloway@users.noreply.github.com>
…l pattern

Co-authored-by: jongalloway <68539+jongalloway@users.noreply.github.com>
Copilot AI changed the title [WIP] Add XML documentation generator for tool methods Add XML documentation infrastructure with documented SDK limitation Dec 3, 2025
Copilot AI requested a review from jongalloway December 3, 2025 19:40
@jongalloway jongalloway marked this pull request as ready for review December 3, 2025 19:46
@jongalloway jongalloway requested a review from Copilot December 3, 2025 19:46
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds XML documentation file generation infrastructure to prepare for future use of the MCP SDK's source generator feature. The PR correctly identifies a blocking SDK limitation where the source generator doesn't preserve optional parameter default values, which would break backward compatibility for all 54 async tool methods. The infrastructure is put in place now so it can be enabled when the SDK addresses this limitation.

Key changes:

  • Enable XML documentation file generation in the project configuration
  • Suppress CS1591 warnings globally to avoid noise from non-tool helper classes
  • Document the intent to use source generator in the future (though this comment needs clarification)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@jongalloway
Copy link
Owner

@copilot Summarize the limitations I hit in this pull request due to the C# MCP SDK XML Source Generator. I think there were issues with both optional parameters and async method signatures.

Copy link
Contributor Author

Copilot AI commented Dec 3, 2025

@copilot Summarize the limitations I hit in this pull request due to the C# MCP SDK XML Source Generator. I think there were issues with both optional parameters and async method signatures.

During investigation, I found two key limitations with the MCP SDK v0.4.1-preview.1 XML Source Generator:

1. Optional Parameters Lose Default Values

When using partial methods, the source generator creates declarations without preserving default parameter values:

// Original method signature
public async Task<string> DotnetProjectBuild(
    string? project = null,        // Has default
    bool machineReadable = false)  // Has default

// After partial conversion - defaults are lost
public partial Task<string> DotnetProjectBuild(
    string? project,        // Now required
    bool machineReadable)   // Now required

This broke all tests that relied on calling methods with optional parameters like DotnetProjectTest(noBuild: true) - the compiler then required all preceding parameters.

2. Async Methods Cannot Use async Modifier on Partial Declarations

The source generator copies the async modifier to its generated declaration, which is invalid C# (declarations can't have async):

// This fails with CS1994: "The 'async' modifier can only be used in methods that have a body"
public async partial Task<string> DotnetTemplateClearCache()

Workaround attempted: Remove async from implementation and return Task directly. This works for simple one-liners but requires helper methods for complex async logic:

// Partial method delegates to private async helper
public partial Task<string> DotnetTemplateClearCache()
    => DotnetTemplateClearCacheAsync();

private async Task<string> DotnetTemplateClearCacheAsync()
{
    await DotNetResources.ClearAllCachesAsync();
    return "...";
}

Impact

With 54 async methods and 211 parameters with defaults, full conversion would break the entire API surface. The infrastructure is in place for when the SDK addresses these limitations.

Copilot AI changed the title Add XML documentation infrastructure with documented SDK limitation Add XML documentation infrastructure with documented SDK limitations Dec 3, 2025
@jongalloway
Copy link
Owner

@jongalloway jongalloway added the blocked Blocked by external dependency or decision label Dec 4, 2025
@jongalloway jongalloway removed the blocked Blocked by external dependency or decision label Dec 17, 2025
@jongalloway
Copy link
Owner

@copilot This is no longer blocked as it has been fixed in the new release of the C# MCP SDK (v0.5.0-preview.1) which has now been implemented in this project.

Copy link
Contributor Author

Copilot AI commented Dec 17, 2025

@copilot This is no longer blocked as it has been fixed in the new release of the C# MCP SDK (v0.5.0-preview.1) which has now been implemented in this project.

Understood. I'll now implement the XML Documentation Generator conversion for the tool methods using v0.5.0-preview.1 which has fixed the optional parameter and async method issues. I'll proceed with the incremental conversion approach outlined in the original issue.

Copilot AI and others added 3 commits December 17, 2025 01:45
Co-authored-by: jongalloway <68539+jongalloway@users.noreply.github.com>
Co-authored-by: jongalloway <68539+jongalloway@users.noreply.github.com>
Co-authored-by: jongalloway <68539+jongalloway@users.noreply.github.com>
Copilot AI changed the title Add XML documentation infrastructure with documented SDK limitations Implement XML Documentation Generator for Tool Methods (In Progress) Dec 17, 2025
@jongalloway jongalloway requested a review from Copilot December 17, 2025 02:03
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

@jongalloway
Copy link
Owner

@copilot Are there more methods that should be updated to use XML Documentation as part of this pull request?

Copy link
Contributor Author

Copilot AI commented Dec 17, 2025

@copilot Are there more methods that should be updated to use XML Documentation as part of this pull request?

Yes, there are 50 more methods that should be converted to use XML Documentation. I've converted 12 out of 62 total methods so far (19%). The remaining methods follow the same pattern and can be converted incrementally. All converted methods are working correctly with optional parameters preserved and all tests passing.

Copilot AI and others added 2 commits December 17, 2025 02:11
…more - 32 total)

Co-authored-by: jongalloway <68539+jongalloway@users.noreply.github.com>
Co-authored-by: jongalloway <68539+jongalloway@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 2 changed files in this pull request and generated no new comments.

@jongalloway jongalloway merged commit 4a34083 into main Dec 17, 2025
1 check passed
@jongalloway jongalloway deleted the copilot/implement-xml-documentation-generator branch December 17, 2025 03:44
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.

Implement XML Documentation Generator for Tool Methods

2 participants