-
Notifications
You must be signed in to change notification settings - Fork 586
Closed
Closed
Copy link
Description
The XmlToDescriptionGenerator copies all modifiers from the original method, including async, to the generated partial declaration. This is invalid C# - partial declarations cannot have the async modifier.
Reproduction
[McpServerToolType]
public partial class Tools
{
/// <summary>Async tool</summary>
[McpServerTool]
public async partial Task<string> DoWorkAsync()
{
await Task.Delay(100);
return "done";
}
}Compiler error
CS1994: The 'async' modifier can only be used in methods that have a body.
Generated code
// Invalid - partial declaration has async modifier
public async partial Task<string> DoWorkAsync();Current workaround
Remove async from the implementation and delegate to a private async helper:
public partial Task<string> DoWorkAsync() => DoWorkAsyncCore();
private async Task<string> DoWorkAsyncCore()
{
await Task.Delay(100);
return "done";
}This adds boilerplate and obscures the implementation.
Expected behavior
The generator should exclude the async modifier when copying modifiers to the partial declaration.
Source location
All modifiers are copied without filtering:
https://github.com/modelcontextprotocol/csharp-sdk/blob/main/src/ModelContextProtocol.Analyzers/XmlToDescriptionGenerator.cs#L323-L325
writer.Write(string.Join(" ", methodDeclaration.Modifiers.Select(m => m.Text)));Suggested fix
Filter out the async modifier:
var modifiers = methodDeclaration.Modifiers
.Where(m => m.Kind() != SyntaxKind.AsyncKeyword)
.Select(m => m.Text);
writer.Write(string.Join(" ", modifiers));Metadata
Metadata
Assignees
Labels
No labels