Skip to content

Commit 6663422

Browse files
Copilotjongalloway
andcommitted
Address code review feedback: implicit usings, SDK sorting, and error messages
Improvements based on review: - Remove System.IO using statement (implicitly included via ImplicitUsings) - Add explicit sorting of SDKs by version to ensure latest is always correct, regardless of CLI output order - Improve error message in DotNetCommandExecutor to include failed command arguments for better troubleshooting Note: Path construction for SDK/runtime paths is correct as-is. The CLI output format is "version [directory]" where directory does NOT include the version, so Path.Combine(path, version) correctly builds the full path. Co-authored-by: jongalloway <[email protected]>
1 parent 71b79b0 commit 6663422

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

DotNetMcp/DotNetCommandExecutor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public static async Task<string> ExecuteCommandForResourceAsync(string arguments
126126
using var process = Process.Start(startInfo);
127127
if (process == null)
128128
{
129-
throw new InvalidOperationException("Failed to start dotnet process");
129+
throw new InvalidOperationException($"Failed to start dotnet process with arguments: {arguments}");
130130
}
131131

132132
var output = await process.StandardOutput.ReadToEndAsync();

DotNetMcp/DotNetResources.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.IO;
21
using System.Text.Json;
32
using Microsoft.Extensions.Logging;
43
using ModelContextProtocol.Server;
@@ -57,10 +56,15 @@ public async Task<string> GetSdkInfo()
5756
}
5857
}
5958

59+
// Sort SDKs by version to ensure we always return the latest, regardless of CLI output order
60+
var sortedSdks = sdks
61+
.OrderBy(sdk => Version.TryParse(sdk.Version, out var v) ? v : new Version(0, 0))
62+
.ToList();
63+
6064
var response = new
6165
{
62-
sdks,
63-
latestSdk = sdks.LastOrDefault()?.Version
66+
sdks = sortedSdks,
67+
latestSdk = sortedSdks.LastOrDefault()?.Version
6468
};
6569

6670
return JsonSerializer.Serialize(response, new JsonSerializerOptions { WriteIndented = true });

0 commit comments

Comments
 (0)