Repository navigation
Implement Model Context Protocol (MCP) server with command handling and JSON-RPC support - #696
Conversation
…nd JSON-RPC support - Added McpCommand class to handle MCP server execution. - Introduced McpServer class to manage service interactions and request handling. - Implemented JSON-RPC request and response models for communication. - Created McpConsole for console output redirection. - Developed unit tests for MCP server functionalities including initialization and tool listing. - Updated DotNetOutdated.Tests project file to disable assembly info generation. Fixes Create MCP server to support LLM-based agent assistance for .NET development Fixes #693
There was a problem hiding this comment.
Pull request overview
This PR implements a Model Context Protocol (MCP) server for dotnet-outdated, enabling AI agents to interact with .NET projects to discover, analyze, and update outdated NuGet packages. The implementation includes JSON-RPC communication, three main tools (discover_projects, analyze_project, update_package), and basic test coverage.
Key Changes:
- Added MCP server implementation with JSON-RPC request/response handling
- Created three MCP tools for project discovery, package analysis, and package updates
- Implemented custom console redirection to support MCP's stdin/stdout communication protocol
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 21 comments.
Show a summary per file
| File | Description |
|---|---|
| src/DotNetOutdated/McpServer.cs | Core MCP server implementation with JSON-RPC handling and tool execution |
| src/DotNetOutdated/McpCommand.cs | Command-line handler to start the MCP server with proper service configuration |
| src/DotNetOutdated/Models/JsonRpc.cs | JSON-RPC request/response models with proper serialization attributes |
| src/DotNetOutdated/Services/McpConsole.cs | Console wrapper that redirects output to stderr for MCP compatibility |
| src/DotNetOutdated/Program.cs | Registered MCP subcommand in the main program |
| test/DotNetOutdated.Tests/McpServerTests.cs | Unit tests for MCP server initialization and basic tool functionality |
| test/DotNetOutdated.Tests/DotNetOutdated.Tests.csproj | Disabled assembly info generation |
| test-projects/development-dependencies-lock/packages.lock.json | Removed net8.0/linux-x64 platform-specific dependencies |
| README.md | Added MCP server documentation with configuration examples |
| DotNetOutdated.sln | Reformatted solution file (GlobalSection reordering) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| else | ||
| { | ||
| status = _centralPackageVersionManagementService.AddPackage(projectPath, packageName, version, false); | ||
|
|
||
| if (!status.IsSuccess) | ||
| { | ||
| return new | ||
| { | ||
| content = new[] { new { type = "text", text = $"Failed to update package. If this is not a CPM project, please provide the 'framework' argument. Error: {status.Errors}" } }, | ||
| isError = true | ||
| }; | ||
| } | ||
| } |
There was a problem hiding this comment.
The early return at lines 371-378 creates an asymmetric flow where the else branch can return early on failure, but the if branch (line 365) continues to check status at line 381. Consider refactoring to make the logic more consistent, such as checking status.IsSuccess after both branches complete without early returns.
| ## FAQ | ||
|
|
There was a problem hiding this comment.
The section doesn't explain what MCP tools are available or what they do. Consider adding a "### Available Tools" subsection that lists discover_projects, analyze_project, and update_package with brief descriptions of each.
| ## FAQ |
| private async Task<object> HandleDiscoverProjects(JsonElement arguments) | ||
| { | ||
| string path = arguments.GetProperty("path").GetString(); | ||
| bool recursive = false; | ||
| if (arguments.TryGetProperty("recursive", out var recursiveProp)) | ||
| { | ||
| recursive = recursiveProp.GetBoolean(); | ||
| } | ||
|
|
||
| var projects = _projectDiscoveryService.DiscoverProjects(path, recursive); | ||
|
|
||
| return new | ||
| { | ||
| content = new[] | ||
| { | ||
| new | ||
| { | ||
| type = "text", | ||
| text = JsonSerializer.Serialize(projects) | ||
| } | ||
| } | ||
| }; | ||
| } |
There was a problem hiding this comment.
The method is marked async but doesn't use any await keywords. Since the method returns a synchronous result, consider removing the async keyword and returning Task.FromResult(...) or add #pragma warning disable CS1998 if the async signature is required for consistency.
|
|
||
| private async Task<object> HandleAnalyzeProject(JsonElement arguments) | ||
| { | ||
| string projectPath = arguments.GetProperty("projectPath").GetString(); |
There was a problem hiding this comment.
Calling GetString() without null check may throw if the "projectPath" property is missing or null. Consider using GetString() ?? throw new ArgumentException("projectPath is required") or add explicit validation.
| string projectPath = arguments.GetProperty("projectPath").GetString(); | |
| string projectPath = arguments.GetProperty("projectPath").GetString() ?? throw new ArgumentException("projectPath is required"); |
| private string GetUpgradeSeverity(NuGetVersion resolved, NuGetVersion latest) | ||
| { | ||
| if (latest == null || resolved == null) | ||
| return "Unknown"; | ||
|
|
||
| if (latest.Major > resolved.Major || resolved.IsPrerelease) | ||
| return "Major"; | ||
| if (latest.Minor > resolved.Minor) | ||
| return "Minor"; | ||
| if (latest.Patch > resolved.Patch || latest.Revision > resolved.Revision) | ||
| return "Patch"; | ||
|
|
||
| return "None"; | ||
| } |
There was a problem hiding this comment.
The method uses nullable parameters but doesn't have nullable annotations (NuGetVersion?). Since the method checks for null at line 332, the parameters should be declared as nullable to match the implementation.
| return; | ||
| } | ||
|
|
||
| object result = null; |
There was a problem hiding this comment.
The variable result is initialized with null but should have an explicit type or be declared as object? to be nullable. This can cause a warning in some compiler configurations.
| object result = null; | |
| object? result = null; |
| "System.Xml.XPath": "4.0.1", | ||
| "System.Xml.XmlDocument": "4.0.1" | ||
| } | ||
| } |
There was a problem hiding this comment.
The entire "net8.0/linux-x64" runtime dependencies section has been removed. This appears to be cleanup, but ensure this doesn't affect test scenarios that depend on these platform-specific packages. Verify that tests still pass on Linux x64 platforms.
| } | |
| } | |
| }, | |
| "net8.0/linux-x64": { | |
| "runtime": { | |
| // TODO: Restore actual runtime dependencies here. | |
| // Example placeholder: | |
| // "Some.Linux.Specific.Package": { | |
| // "type": "Transitive", | |
| // "resolved": "1.0.0", | |
| // "contentHash": "PLACEHOLDER" | |
| // } | |
| } |
| else | ||
| { | ||
| return new | ||
| { | ||
| content = new[] { new { type = "text", text = $"Failed to update package: {status.Errors}" } }, | ||
| isError = true | ||
| }; | ||
| } |
There was a problem hiding this comment.
Both branches of this 'if' statement return - consider using '?' to express intent better.
| else | |
| { | |
| return new | |
| { | |
| content = new[] { new { type = "text", text = $"Failed to update package: {status.Errors}" } }, | |
| isError = true | |
| }; | |
| } | |
| return new | |
| { | |
| content = new[] { new { type = "text", text = $"Failed to update package: {status.Errors}" } }, | |
| isError = true | |
| }; |
|
This is really cool, and I hadn't considered it for dotnet-outdated, but it would be a great fit. My instinct is that this would be packaged up as a dedicated tool, however I can't think of a technical reason for this. Is there precedent for other similar dotnet tools combining a MCP server mode into their existing tool out of interest? (I don't think we should make the decision based on that, I'm just curious) |
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Restores the original CRLF line endings in DotNetOutdated.sln and restores the accidentally deleted packages.lock.json file. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Per the JSON-RPC 2.0 spec, result and error should be mutually exclusive in responses rather than both always being present. Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Sorry for the slow response, this is a great addition (even if Skills is now the new hotness 😅 ) |
Fixes Create MCP server to support LLM-based agent assistance for .NET development
Fixes #693