mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 05:27:41 -05:00
feat: Add initial MCP Server support
This commit is contained in:
@@ -17,6 +17,8 @@
|
||||
|
||||
#include <fmt/chrono.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <romfs/romfs.hpp>
|
||||
#include <toasts/toast_notification.hpp>
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
||||
@@ -103,6 +105,16 @@ namespace hex::plugin::builtin {
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
}
|
||||
|
||||
void handleMCPServer() {
|
||||
if (!ContentRegistry::MCP::isEnabled()) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
ContentRegistry::MCP::impl::getMcpServerInstance().disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
ContentRegistry::MCP::impl::getMcpServerInstance().listen();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void registerBackgroundServices() {
|
||||
@@ -110,12 +122,17 @@ namespace hex::plugin::builtin {
|
||||
s_networkInterfaceServiceEnabled = value.get<bool>(false);
|
||||
});
|
||||
|
||||
ContentRegistry::Settings::onChange("hex.builtin.setting.general", "hex.builtin.setting.general.mcp_server", [](const ContentRegistry::Settings::SettingsValue &value) {
|
||||
ContentRegistry::MCP::impl::setEnabled(value.get<bool>(false));
|
||||
});
|
||||
|
||||
ContentRegistry::Settings::onChange("hex.builtin.setting.general", "hex.builtin.setting.general.backups.auto_backup_time", [](const ContentRegistry::Settings::SettingsValue &value) {
|
||||
s_autoBackupTime = value.get<int>(0) * 30;
|
||||
});
|
||||
|
||||
ContentRegistry::BackgroundServices::registerService("hex.builtin.background_service.network_interface", handleNetworkInterfaceService);
|
||||
ContentRegistry::BackgroundServices::registerService("hex.builtin.background_service.auto_backup", handleAutoBackup);
|
||||
ContentRegistry::BackgroundServices::registerService("hex.builtin.background_service.mcp", handleMCPServer);
|
||||
|
||||
EventProviderDirtied::subscribe([](prv::Provider *) {
|
||||
s_dataDirty = true;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#include <iostream>
|
||||
#include <content/command_line_interface.hpp>
|
||||
#include <hex/mcp/client.hpp>
|
||||
|
||||
#include <hex/api/imhex_api/system.hpp>
|
||||
#include <hex/api/imhex_api/hex_editor.hpp>
|
||||
@@ -530,6 +532,14 @@ namespace hex::plugin::builtin {
|
||||
ContentRegistry::Views::setFullScreenView<ViewFullScreenFileInfo>(path);
|
||||
}
|
||||
|
||||
void handleMCPCommand(const std::vector<std::string> &) {
|
||||
mcp::Client client;
|
||||
|
||||
auto result = client.run(std::cin, std::cout);
|
||||
std::fprintf(stderr, "MCP Client disconnected!\n");
|
||||
std::exit(result);
|
||||
}
|
||||
|
||||
|
||||
void registerCommandForwarders() {
|
||||
hex::subcommands::registerSubCommand("open", [](const std::vector<std::string> &args){
|
||||
|
||||
@@ -768,6 +768,8 @@ namespace hex::plugin::builtin {
|
||||
|
||||
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.general", "hex.builtin.setting.general.network", "hex.builtin.setting.general.network_interface", false);
|
||||
|
||||
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.general", "hex.builtin.setting.general.network", "hex.builtin.setting.general.mcp_server", false);
|
||||
|
||||
#if !defined(OS_WEB)
|
||||
ContentRegistry::Settings::add<ServerContactWidget>("hex.builtin.setting.general", "hex.builtin.setting.general.network", "hex.builtin.setting.general.server_contact");
|
||||
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.general", "hex.builtin.setting.general.network", "hex.builtin.setting.general.upload_crash_logs", true);
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
#include <csignal>
|
||||
#include <fonts/tabler_icons.hpp>
|
||||
#include <hex/api/content_registry/communication_interface.hpp>
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
||||
@@ -239,6 +240,20 @@ namespace hex::plugin::builtin {
|
||||
});
|
||||
}
|
||||
|
||||
ContentRegistry::UserInterface::addFooterItem([] {
|
||||
if (ContentRegistry::MCP::isConnected()) {
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImGuiExt::GetCustomColorU32(ImGuiCustomCol_Highlight));
|
||||
} else {
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetColorU32(ImGuiCol_TextDisabled));
|
||||
}
|
||||
|
||||
if (ContentRegistry::MCP::isEnabled()) {
|
||||
ImGui::TextUnformatted(ICON_VS_MCP);
|
||||
}
|
||||
|
||||
ImGui::PopStyleColor();
|
||||
});
|
||||
|
||||
if (dbg::debugModeEnabled()) {
|
||||
ContentRegistry::UserInterface::addFooterItem([] {
|
||||
static float framerate = 0;
|
||||
|
||||
Reference in New Issue
Block a user