mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 13:37:42 -05:00
feat: Add initial MCP commands to query, open select and read data
This commit is contained in:
@@ -6,6 +6,40 @@
|
||||
|
||||
namespace hex::mcp {
|
||||
|
||||
struct TextContent {
|
||||
std::string text;
|
||||
|
||||
operator nlohmann::json() const {
|
||||
nlohmann::json result;
|
||||
result["content"] = nlohmann::json::array({
|
||||
nlohmann::json::object({
|
||||
{ "type", "text" },
|
||||
{ "text", text }
|
||||
})
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
struct StructuredContent {
|
||||
std::string text;
|
||||
nlohmann::json data;
|
||||
|
||||
operator nlohmann::json() const {
|
||||
nlohmann::json result;
|
||||
result["content"] = nlohmann::json::array({
|
||||
nlohmann::json::object({
|
||||
{ "type", "text" },
|
||||
{ "text", text }
|
||||
})
|
||||
});
|
||||
result["structuredContent"] = data;
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
class Server {
|
||||
public:
|
||||
constexpr static auto McpInternalPort = 19743;
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace hex::mcp {
|
||||
if (!m_id.has_value())
|
||||
return std::nullopt;
|
||||
|
||||
return createResponseMessage(result);
|
||||
return createResponseMessage(result.is_null() ? nlohmann::json::object() : result);
|
||||
}
|
||||
|
||||
std::optional<nlohmann::json> handleBatchedMessages(const nlohmann::json &request, auto callback) {
|
||||
@@ -154,7 +154,9 @@ namespace hex::mcp {
|
||||
if (auto primitiveIt = m_primitives.find(primitive); primitiveIt != m_primitives.end()) {
|
||||
auto name = params.value("name", "");
|
||||
if (auto functionIt = primitiveIt->second.find(name); functionIt != primitiveIt->second.end()) {
|
||||
return functionIt->second.function(params.value("arguments", nlohmann::json::object()));
|
||||
auto result = functionIt->second.function(params.value("arguments", nlohmann::json::object()));
|
||||
|
||||
return result.is_null() ? nlohmann::json::object() : result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user