66 lines
3.0 KiB
C++
66 lines
3.0 KiB
C++
#include <iostream>
|
|
#include <string>
|
|
#include "mcp/KomMcpServer.hpp"
|
|
#include "mcp/RegisterTools.hpp"
|
|
|
|
namespace {
|
|
|
|
bool expect_contains(const std::string& haystack, const std::string& needle, const std::string& context) {
|
|
if (haystack.find(needle) == std::string::npos) {
|
|
std::cerr << "Expected response to contain '" << needle << "' but got:\n"
|
|
<< haystack << "\nContext: " << context << "\n";
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
int main() {
|
|
KomMcpServer server;
|
|
register_default_tools(server);
|
|
|
|
const std::string upsertReq = R"({"namespace":"tests","items":[{"text":"hello world","tags":["greeting"],"embedding":[0.1,0.2,0.3]},{"text":"hola mundo","embedding":[0.05,0.1,0.15]}]})";
|
|
std::string upsertResp = server.dispatch("kom.memory.v1.upsert_memory", upsertReq);
|
|
if (!expect_contains(upsertResp, "\"upserted\":2", "upsert_memory count")) return 1;
|
|
if (!expect_contains(upsertResp, "\"status\":\"ok\"", "upsert_memory status")) return 1;
|
|
|
|
std::string firstId;
|
|
const std::string idsAnchor = "\"ids\":[\"";
|
|
auto idsPos = upsertResp.find(idsAnchor);
|
|
if (idsPos != std::string::npos) {
|
|
idsPos += idsAnchor.size();
|
|
auto endPos = upsertResp.find("\"", idsPos);
|
|
if (endPos != std::string::npos) {
|
|
firstId = upsertResp.substr(idsPos, endPos - idsPos);
|
|
}
|
|
}
|
|
if (firstId.empty()) {
|
|
std::cerr << "Failed to extract first item id from upsert response: " << upsertResp << "\n";
|
|
return 1;
|
|
}
|
|
|
|
const std::string searchReq = R"({"namespace":"tests","query":{"text":"hello","k":3}})";
|
|
std::string searchResp = server.dispatch("kom.memory.v1.search_memory", searchReq);
|
|
if (!expect_contains(searchResp, "\"matches\"", "search_memory matches key")) return 1;
|
|
if (!expect_contains(searchResp, "\"text\":\"hello world\"", "search_memory returns stored text")) return 1;
|
|
|
|
const std::string vectorReq = R"({"namespace":"tests","query":{"embedding":[0.1,0.2,0.3],"k":1}})";
|
|
std::string vectorResp = server.dispatch("kom.memory.v1.search_memory", vectorReq);
|
|
if (!expect_contains(vectorResp, "\"id\":\""+firstId+"\"", "vector search returns stored id")) return 1;
|
|
|
|
const std::string snapshotResp = server.dispatch("kom.meta.v1.project_snapshot", "{}");
|
|
if (!expect_contains(snapshotResp, "\"sections\"", "snapshot sections key")) return 1;
|
|
|
|
const std::string exportReq = R"({"namespace":"tests","destination":"/tmp/example.enc"})";
|
|
std::string exportResp = server.dispatch("kom.local.v1.backup.export_encrypted", exportReq);
|
|
if (!expect_contains(exportResp, "\"status\":\"queued\"", "export status")) return 1;
|
|
if (!expect_contains(exportResp, "\"artifact\"", "export artifact path")) return 1;
|
|
|
|
const std::string importReq = R"({"namespace":"tests","source":"/tmp/example.enc"})";
|
|
std::string importResp = server.dispatch("kom.local.v1.backup.import_encrypted", importReq);
|
|
if (!expect_contains(importResp, "\"status\":\"ok\"", "import status")) return 1;
|
|
|
|
return 0;
|
|
}
|