Browse Source

Add McpCommand to CLI core module

Introduces the McpCommand for running a local MCP server and outputting client configuration for AI tool integration. Registers the new command in AbpCliCoreModule.
pull/24677/head
Mansur Besleney 4 months ago
parent
commit
5b8c1a4813
  1. 1
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/AbpCliCoreModule.cs
  2. 76
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/McpCommand.cs

1
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/AbpCliCoreModule.cs

@ -79,6 +79,7 @@ public class AbpCliCoreModule : AbpModule
options.Commands[ClearDownloadCacheCommand.Name] = typeof(ClearDownloadCacheCommand);
options.Commands[RecreateInitialMigrationCommand.Name] = typeof(RecreateInitialMigrationCommand);
options.Commands[GenerateRazorPage.Name] = typeof(GenerateRazorPage);
options.Commands[McpCommand.Name] = typeof(McpCommand);
options.DisabledModulesToAddToSolution.Add("Volo.Abp.LeptonXTheme.Pro");
options.DisabledModulesToAddToSolution.Add("Volo.Abp.LeptonXTheme.Lite");

76
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/McpCommand.cs

@ -0,0 +1,76 @@
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Volo.Abp.Cli.Args;
using Volo.Abp.Cli.Auth;
using Volo.Abp.Cli.Commands.Services;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.Cli.Commands;
public class McpCommand : IConsoleCommand, ITransientDependency
{
public const string Name = "mcp";
private readonly AuthService _authService;
private readonly AbpNuGetIndexUrlService _nuGetIndexUrlService;
public ILogger<McpCommand> Logger { get; set; }
public McpCommand(
AbpNuGetIndexUrlService nuGetIndexUrlService,
AuthService authService, ILogger<McpCommand> logger)
{
_nuGetIndexUrlService = nuGetIndexUrlService;
_authService = authService;
Logger = NullLogger<McpCommand>.Instance;
}
public async Task ExecuteAsync(CommandLineArgs commandLineArgs)
{
var loginInfo = await _authService.GetLoginInfoAsync();
if (string.IsNullOrEmpty(loginInfo?.Organization))
{
throw new CliUsageException("Please log in with your account!");
}
var nugetIndexUrl = await _nuGetIndexUrlService.GetAsync();
if (nugetIndexUrl == null)
{
throw new CliUsageException("Could not find Nuget Index Url!");
}
Logger.LogInformation("Starting MCP server...");
}
public string GetUsageInfo()
{
var sb = new StringBuilder();
sb.AppendLine("");
sb.AppendLine("Usage:");
sb.AppendLine("");
sb.AppendLine(" abp mcp [options]");
sb.AppendLine("");
sb.AppendLine("Options:");
sb.AppendLine("");
sb.AppendLine("<no argument> (start the local MCP server)");
sb.AppendLine("getconfig (print MCP client configuration as JSON)");
sb.AppendLine("");
sb.AppendLine("Examples:");
sb.AppendLine("");
sb.AppendLine(" abp mcp");
sb.AppendLine(" abp mcp getconfig");
sb.AppendLine("");
return sb.ToString();
}
public static string GetShortDescription()
{
return "Runs the local MCP server and outputs client configuration for AI tool integration.";
}
}
Loading…
Cancel
Save