1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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;
}
|