summaryrefslogtreecommitdiff
path: root/src/mcp/tools/rebuild_index.c
diff options
context:
space:
mode:
authortanaka takashi <isazaka@gmail.com>2026-06-29 21:43:54 +0900
committertanaka takashi <isazaka@gmail.com>2026-06-30 01:23:51 +0900
commit4bc721c3bf7589b519c5730d093f704ce56e3f09 (patch)
tree38da055ab15fd70f5c92584560ea73486e5ddce0 /src/mcp/tools/rebuild_index.c
parent4c6a831aa2a57e2bcc20aa3fc2f1b7172f5be285 (diff)
refactor: MCP層をmcpc APIベースに刷新
- 独自JSON-RPC処理をmcpcへ置き換え - 各MCPツールを個別ソースへ分離 - 共通コンテキストと登録処理を整理 - mcpc互換修正と統合テストを更新
Diffstat (limited to 'src/mcp/tools/rebuild_index.c')
-rw-r--r--src/mcp/tools/rebuild_index.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/mcp/tools/rebuild_index.c b/src/mcp/tools/rebuild_index.c
new file mode 100644
index 0000000..69f8341
--- /dev/null
+++ b/src/mcp/tools/rebuild_index.c
@@ -0,0 +1,57 @@
+#include "mcp/tools/common/registry.h"
+
+#include "mcp/tools/common/common.h"
+#include "mcp/tools/common/context.h"
+
+#include "base/allocator.h"
+
+static void
+call_rebuild_index(const mcpc_tool_t *tool, mcpc_ucbr_t *result)
+{
+ tiny_mcp_tools_context_t *context = tiny_mcp_tools_context_current();
+ tiny_rebuild_report_t report;
+ tiny_search_index_t *rebuilt;
+ tiny_store_status_t status;
+ tiny_json_buffer_t json;
+ (void)tool;
+ if (!context)
+ {
+ tiny_mcp_tool_add_error(result, "INTERNAL_ERROR", "tool context is unavailable");
+ return;
+ }
+ status = tiny_store_rebuild(context->store, &report);
+ if (status != TINY_STORE_OK)
+ {
+ tiny_mcp_tool_add_error(result, tiny_store_status_name(status), "index rebuild failed");
+ return;
+ }
+ rebuilt = tiny_mcp_tools_build_search_index(context->store);
+ if (!rebuilt)
+ {
+ tiny_search_index_free(context->search_index);
+ context->search_index = NULL;
+ tiny_mcp_tool_add_error(result, "INTERNAL_ERROR", "search index allocation failed");
+ return;
+ }
+ tiny_search_index_free(context->search_index);
+ context->search_index = rebuilt;
+ tiny_json_init(&json);
+ tiny_json_raw(&json, "{\"status\":\"OK\",\"messages_indexed\":");
+ tiny_json_u64(&json, report.messages_indexed);
+ tiny_json_raw(&json, ",\"records_removed\":");
+ tiny_json_u64(&json, report.records_removed);
+ tiny_json_raw(&json, ",\"bytes_before\":");
+ tiny_json_u64(&json, report.bytes_before);
+ tiny_json_raw(&json, ",\"bytes_after\":");
+ tiny_json_u64(&json, report.bytes_after);
+ tiny_json_raw(&json, "}");
+ tiny_mcp_tool_add_json(result, &json);
+ tiny_json_free(&json);
+}
+
+bool
+tiny_mcp_register_rebuild_index(mcpc_server_t *server)
+{
+ mcpc_tool_t *tool = tiny_mcp_tool_new("rebuild_index", "Compact and rebuild", call_rebuild_index);
+ return tool && mcpc_server_add_tool(server, tool) == MCPC_EC_0;
+}