Skip to content

Commit 3619c9f

Browse files
authored
Centralize the definition of MCP Server and Tool names into Constants class (#7168)
1 parent f424430 commit 3619c9f

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
namespace NuGet.PackageManagement.VisualStudio
5+
{
6+
public static class McpServerConstants
7+
{
8+
// This value must match the server name registered in mcp.json. Keep both in sync.
9+
public const string NuGetMcpServerName = "nuget";
10+
11+
// Tool names below must match their respective tool names defined in the NuGet MCP Server.
12+
public const string NuGetSolverToolName = "get-nuget-solver";
13+
14+
// Fully qualified tool names are in the format of "{serverName}_{toolName}".
15+
public const string NuGetSolverFullyQualifiedToolName = $"{NuGetMcpServerName}_{NuGetSolverToolName}";
16+
}
17+
}

src/NuGet.Clients/NuGet.Tools/FixVulnerablitiesService.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ internal class FixVulnerablitiesService : IFixVulnerabilitiesService
2727
private const string AgentModeResponderServiceMoniker = "Microsoft.VisualStudio.Copilot.AgentModeResponder";
2828
private const string AuthStatusDetermined = "c936efcc-6baa-4ad3-9c2b-7ba750acf18f";
2929
private const string ServiceName = "Microsoft.VisualStudio.Copilot.SolutionContextProvider";
30-
private const string NuGetMCPServerName = "nuget";
31-
private const string NuGetSolverToolName = "get-nuget-solver";
3230

3331
private static readonly Guid CopilotReadyUIContext = new(AuthStatusDetermined);
3432
private static readonly ServiceRpcDescriptor ProviderDescriptor = CopilotDescriptors.CreateContextProviderDescriptor(ServiceName);
@@ -101,7 +99,7 @@ public async Task LaunchFixVulnerabilitiesAsync(CancellationToken cancellationTo
10199
string solutionPathContext = $"The current solution file path is: {GetSolutionPath()}.";
102100
CopilotContext context = new CopilotContext(ProviderDescriptor.Moniker, ContextDescriptor, request.CorrelationId, solutionPathContext);
103101
IReadOnlyList<CopilotFunctionDescriptor> functions = await cfp.GetFunctionsAsync(request.CorrelationId, cancellationToken);
104-
if (functions is null || !functions.Any(f => string.Equals(f.Name, $"{NuGetMCPServerName}_{NuGetSolverToolName}", StringComparison.OrdinalIgnoreCase)))
102+
if (functions is null || !functions.Any(f => string.Equals(f.Name, McpServerConstants.NuGetSolverFullyQualifiedToolName, StringComparison.OrdinalIgnoreCase)))
105103
{
106104
SendTelemetryEvent(FixVulnerabilitiesWithCopilotErrorType.NuGetSolverNotAvailable);
107105
ShowWarningMessage(Resources.Error_NuGetSolverNotAvailable);

0 commit comments

Comments
 (0)