#include "mcp/tools/common/registry.h" #include "mcp/tools/common/common.h" #include "mcp/tools/common/context.h" #include #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 || !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 && 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 persisted message so it is immediately excluded from reads and " "searches. Physical removal occurs after rebuild_index compacts the store.", call_delete_message); return tool && tiny_mcp_tool_add_property(tool, "message_id", "Canonical 26-character ULID of the message to delete.", MCPC_U8STR, true) && tiny_mcp_tool_add_property(tool, "session_id", "Optional session guard; when provided, delete only if the " "message belongs to this session.", MCPC_U8STR, false) && mcpc_server_add_tool(server, tool) == MCPC_EC_0; }