summaryrefslogtreecommitdiff
path: root/src/mcp/tools/delete_message.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/delete_message.c
parent4c6a831aa2a57e2bcc20aa3fc2f1b7172f5be285 (diff)
refactor: MCP層をmcpc APIベースに刷新
- 独自JSON-RPC処理をmcpcへ置き換え - 各MCPツールを個別ソースへ分離 - 共通コンテキストと登録処理を整理 - mcpc互換修正と統合テストを更新
Diffstat (limited to 'src/mcp/tools/delete_message.c')
-rw-r--r--src/mcp/tools/delete_message.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/mcp/tools/delete_message.c b/src/mcp/tools/delete_message.c
new file mode 100644
index 0000000..ae924d7
--- /dev/null
+++ b/src/mcp/tools/delete_message.c
@@ -0,0 +1,50 @@
+#include "mcp/tools/common/registry.h"
+
+#include "mcp/tools/common/common.h"
+#include "mcp/tools/common/context.h"
+
+#include <stdlib.h>
+
+#include "base/allocator.h"
+
+static void
+call_delete_message(const mcpc_tool_t *tool, mcpc_ucbr_t *result)
+{
+ tiny_mcp_tools_context_t *context = tiny_mcp_tools_context_current();
+ char *message_id = tiny_mcp_tool_get_string(tool, "message_id", TINY_MESSAGE_ID_LENGTH);
+ char *session = tiny_mcp_tool_get_string(tool, "session_id", TINY_SESSION_ID_MAX);
+ tiny_store_status_t status;
+ if (!context || !message_id || !session || !tiny_message_id_valid(message_id))
+ {
+ tiny_mcp_tool_add_error(
+ result, "VALIDATION_ERROR", "message_id must be a canonical 26-character ULID");
+ }
+ else
+ {
+ status = tiny_store_delete(context->store, message_id, session[0] ? session : NULL);
+ if (status != TINY_STORE_OK && status != TINY_STORE_NOT_FOUND)
+ {
+ tiny_mcp_tool_add_error(
+ result, tiny_store_status_name(status), "delete record was not written");
+ }
+ else
+ {
+ mcpc_toolcall_result_add_text_printf8(
+ result,
+ (const char8_t *)(status == TINY_STORE_OK ? "{\"status\":\"OK\"}"
+ : "{\"status\":\"NOT_FOUND\"}"));
+ }
+ }
+ free(message_id);
+ free(session);
+}
+
+bool
+tiny_mcp_register_delete_message(mcpc_server_t *server)
+{
+ mcpc_tool_t *tool = tiny_mcp_tool_new("delete_message", "Delete a message", call_delete_message);
+ return tool && tiny_mcp_tool_add_property(tool, "message_id", "Message ULID", MCPC_U8STR)
+ && tiny_mcp_tool_add_property(
+ tool, "session_id", "Session ID; empty if omitted", MCPC_U8STR)
+ && mcpc_server_add_tool(server, tool) == MCPC_EC_0;
+}