McpCommand.cpp (2880B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #include "pch.h" 4 #include "McpCommand.h" 5 #include "Workflows/MSStoreInstallerHandler.h" 6 #include <AppInstallerRuntime.h> 7 8 using namespace AppInstaller::CLI::Workflow; 9 10 namespace AppInstaller::CLI 11 { 12 McpCommand::McpCommand(std::string_view parent) : 13 Command("mcp", {}, parent, Settings::TogglePolicy::Policy::McpServer) 14 { 15 } 16 17 std::vector<Argument> McpCommand::GetArguments() const 18 { 19 return { 20 Argument{ Execution::Args::Type::ExtendedFeaturesEnable, Resource::String::ExtendedFeaturesEnableMessage, ArgumentType::Flag, Argument::Visibility::Help }, 21 Argument{ Execution::Args::Type::ExtendedFeaturesDisable, Resource::String::ExtendedFeaturesDisableMessage, ArgumentType::Flag, Argument::Visibility::Help }, 22 }; 23 } 24 25 Resource::LocString McpCommand::ShortDescription() const 26 { 27 return { Resource::String::McpCommandShortDescription }; 28 } 29 30 Resource::LocString McpCommand::LongDescription() const 31 { 32 return { Resource::String::McpCommandLongDescription }; 33 } 34 35 Utility::LocIndView McpCommand::HelpLink() const 36 { 37 return "https://aka.ms/winget-command-mcp"_liv; 38 } 39 40 void McpCommand::ExecuteInternal(Execution::Context& context) const 41 { 42 if (context.Args.Contains(Execution::Args::Type::ExtendedFeaturesEnable)) 43 { 44 context << 45 EnableExtendedFeatures; 46 } 47 else if (context.Args.Contains(Execution::Args::Type::ExtendedFeaturesDisable)) 48 { 49 context << 50 DisableExtendedFeatures; 51 } 52 else 53 { 54 context << 55 VerifyIsFullPackage << 56 [](Execution::Context& context) 57 { 58 std::filesystem::path exePath = Runtime::GetPathTo(Runtime::PathName::MCPExecutable); 59 std::string jsonCompatiblePath = exePath.u8string(); 60 Utility::FindAndReplace(jsonCompatiblePath, "\\", "\\\\"); 61 62 context.Reporter.Info() << Resource::String::McpConfigurationPreamble << 63 R"( 64 "winget-mcp": { 65 "type": "stdio", 66 "command": ")" << jsonCompatiblePath << R"(" 67 })" << std::endl; 68 }; 69 } 70 } 71 72 void McpCommand::ValidateArgumentsInternal(Execution::Args& execArgs) const 73 { 74 if (execArgs.Contains(Execution::Args::Type::ExtendedFeaturesEnable) || 75 execArgs.Contains(Execution::Args::Type::ExtendedFeaturesDisable)) 76 { 77 if (execArgs.GetArgsCount() > 1) 78 { 79 throw CommandException(Resource::String::ExtendedFeaturesEnableArgumentError); 80 } 81 } 82 } 83 }