mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-27 23:37:05 -05:00
@@ -27,7 +27,7 @@ EXPORT_MODULE namespace hex {
|
|||||||
namespace ContentRegistry::MCP {
|
namespace ContentRegistry::MCP {
|
||||||
|
|
||||||
namespace impl {
|
namespace impl {
|
||||||
mcp::Server& getMcpServerInstance();
|
std::unique_ptr<mcp::Server>& getMcpServerInstance();
|
||||||
|
|
||||||
void setEnabled(bool enabled);
|
void setEnabled(bool enabled);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,9 +87,9 @@ namespace hex {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void reset() override {
|
void reset() override {
|
||||||
if constexpr (requires { m_value.reset(); }) {
|
if constexpr (requires(T t) { t.reset(); }) {
|
||||||
m_value.reset();
|
m_value.reset();
|
||||||
} else if constexpr (requires { m_value.clear(); }) {
|
} else if constexpr (requires(T t) { t.clear(); }) {
|
||||||
m_value.clear();
|
m_value.clear();
|
||||||
} else if constexpr (std::is_pointer_v<T>) {
|
} else if constexpr (std::is_pointer_v<T>) {
|
||||||
m_value = nullptr; // cppcheck-suppress nullPointer
|
m_value = nullptr; // cppcheck-suppress nullPointer
|
||||||
|
|||||||
@@ -1421,13 +1421,13 @@ namespace hex {
|
|||||||
|
|
||||||
namespace impl {
|
namespace impl {
|
||||||
|
|
||||||
mcp::Server& getMcpServerInstance() {
|
std::unique_ptr<mcp::Server>& getMcpServerInstance() {
|
||||||
static AutoReset<std::unique_ptr<mcp::Server>> server;
|
static std::unique_ptr<mcp::Server> server;
|
||||||
|
|
||||||
if (*server == nullptr)
|
if (server == nullptr)
|
||||||
server = std::make_unique<mcp::Server>();
|
server = std::make_unique<mcp::Server>();
|
||||||
|
|
||||||
return **server;
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool s_mcpEnabled = false;
|
static bool s_mcpEnabled = false;
|
||||||
@@ -1442,11 +1442,11 @@ namespace hex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool isConnected() {
|
bool isConnected() {
|
||||||
return impl::getMcpServerInstance().isConnected();
|
return impl::getMcpServerInstance()->isConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
void registerTool(std::string_view capabilities, std::function<nlohmann::json(const nlohmann::json ¶ms)> function) {
|
void registerTool(std::string_view capabilities, std::function<nlohmann::json(const nlohmann::json ¶ms)> function) {
|
||||||
impl::getMcpServerInstance().addPrimitive("tools", capabilities, function);
|
impl::getMcpServerInstance()->addPrimitive("tools", capabilities, function);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,11 +108,11 @@ namespace hex::plugin::builtin {
|
|||||||
void handleMCPServer() {
|
void handleMCPServer() {
|
||||||
if (!ContentRegistry::MCP::isEnabled()) {
|
if (!ContentRegistry::MCP::isEnabled()) {
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
ContentRegistry::MCP::impl::getMcpServerInstance().disconnect();
|
ContentRegistry::MCP::impl::getMcpServerInstance()->disconnect();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ContentRegistry::MCP::impl::getMcpServerInstance().listen();
|
ContentRegistry::MCP::impl::getMcpServerInstance()->listen();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -126,6 +126,10 @@ namespace hex::plugin::builtin {
|
|||||||
ContentRegistry::BackgroundServices::registerService("hex.builtin.background_service.auto_backup", handleAutoBackup);
|
ContentRegistry::BackgroundServices::registerService("hex.builtin.background_service.auto_backup", handleAutoBackup);
|
||||||
ContentRegistry::BackgroundServices::registerService("hex.builtin.background_service.mcp", handleMCPServer);
|
ContentRegistry::BackgroundServices::registerService("hex.builtin.background_service.mcp", handleMCPServer);
|
||||||
|
|
||||||
|
EventImHexClosing::subscribe([] {
|
||||||
|
ContentRegistry::MCP::impl::getMcpServerInstance().reset();
|
||||||
|
});
|
||||||
|
|
||||||
EventProviderDirtied::subscribe([](prv::Provider *) {
|
EventProviderDirtied::subscribe([](prv::Provider *) {
|
||||||
s_dataDirty = true;
|
s_dataDirty = true;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user