summaryrefslogtreecommitdiff
path: root/src/mcp/tools/read_messages.c
diff options
context:
space:
mode:
authortanaka takashi <isazaka@gmail.com>2026-07-04 17:21:32 +0900
committertanaka takashi <isazaka@gmail.com>2026-07-04 17:21:32 +0900
commit0634f2048c7c9a474aab1d8104b964b3bf70a064 (patch)
tree508c305a64cbd3b01f5146776e22865d283d5dbb /src/mcp/tools/read_messages.c
parenteb5e9d9f37bda7d78f69614da70402357794168a (diff)
feat(P1-002): migrate offline JSONL import/export to dedicated CLI
- Replace the MCP import_messages tool with standalone CLI commands: iny-convmem-mcp --data-dir <path> --import <file> iny-convmem-mcp --data-dir <path> --export <file> - Add src/cli/{import,export,cli.h} and a CTest process test (tiny-convmem-mcp.cli) covering round-trip, manifest generation, overwrite/reject policies, and include_deleted export. - Fix Debug heap corruption in iny_store_import() by deep-copying imported messages instead of taking ownership of caller-allocated records, which were later freed by the caller. - Remove the now-redundant src/mcp/tools/import_messages.c and keep the tool registry at 7 MCP tools. - Update docs/development-plan.md (P1-002 complete) and docs/implementation-status.md with CLI test coverage.
Diffstat (limited to 'src/mcp/tools/read_messages.c')
-rw-r--r--src/mcp/tools/read_messages.c100
1 files changed, 1 insertions, 99 deletions
diff --git a/src/mcp/tools/read_messages.c b/src/mcp/tools/read_messages.c
index 647e6f3..109becb 100644
--- a/src/mcp/tools/read_messages.c
+++ b/src/mcp/tools/read_messages.c
@@ -729,86 +729,6 @@ call_sessions_view(tiny_mcp_tools_context_t *context, const mcpc_tool_t *tool, m
}
static void
-call_export_view(tiny_mcp_tools_context_t *context, const mcpc_tool_t *tool, mcpc_ucbr_t *result)
-{
- char *session = tiny_mcp_tool_get_string(tool, "session_id", TINY_SESSION_ID_MAX);
- char *cursor = tiny_mcp_tool_get_string(tool, "cursor", CURSOR_TEXT_MAX);
- int32_t limit = 500;
- char *include_deleted_text = tiny_mcp_tool_get_string(tool, "include_deleted", 8);
- bool include_deleted = include_deleted_text && strcmp(include_deleted_text, "true") == 0;
- bool valid;
- size_t index = simple_cursor(cursor, &valid), emitted = 0, start_index;
- tiny_json_buffer_t json, lines;
- size_t outer_size = 64;
- bool truncated = false;
- mcpc_errcode_t limit_status = mcpc_tool_get_tpropval_i32(tool, (const char8_t *)"limit", &limit);
- if (!context || !valid || limit < 1 || limit > 1000
- || (limit_status != MCPC_EC_0 && limit_status != MCPC_EC_ANYDATA_NOTFOUND))
- {
- tiny_mcp_tool_add_error(result, "VALIDATION_ERROR", "invalid export view arguments");
- free(session);
- free(cursor);
- return;
- }
- start_index = index;
- tiny_json_init(&lines);
- if (index == 0)
- {
- tiny_json_raw(&lines, "{\"type\":\"tiny-convmem-manifest\",\"format_version\":2}\n");
- }
- for (; index < tiny_store_entry_count(context->store) && emitted < (size_t)limit; ++index)
- {
- const tiny_store_entry_t *entry = tiny_store_entry(context->store, index);
- tiny_json_buffer_t item;
- size_t line_overhead;
- if (!entry || (entry->deleted && !include_deleted)
- || (session && session[0] && strcmp(session, entry->message.session_id) != 0))
- {
- continue;
- }
- tiny_json_init(&item);
- if (entry->deleted)
- {
- tiny_json_raw(&item, "{\"type\":\"DEL\",\"message_id\":");
- tiny_json_string(&item, entry->message.message_id);
- tiny_json_raw(&item, "}");
- }
- else
- {
- tiny_mcp_tool_append_message(&item, &entry->message);
- }
- line_overhead = item.length + 1;
- if (item.failed || outer_size + lines.length + line_overhead + 2 > READ_RESPONSE_BUDGET)
- {
- truncated = true;
- tiny_json_free(&item);
- break;
- }
- tiny_json_raw_n(&lines, item.data, item.length);
- tiny_json_raw(&lines, "\n");
- emitted++;
- tiny_json_free(&item);
- }
- tiny_json_init(&json);
- tiny_json_raw(&json, "{\"jsonl\":");
- tiny_json_string(&json, lines.data ? lines.data : "");
- if (truncated || index < tiny_store_entry_count(context->store))
- {
- char next[32];
- snprintf(next, sizeof(next), "%zu", index > start_index ? index : start_index + 1);
- tiny_json_raw(&json, ",\"nextCursor\":");
- tiny_json_string(&json, next);
- tiny_json_raw(&json, ",\"truncated\":true");
- }
- tiny_json_raw(&json, "}");
- tiny_mcp_tool_add_json(result, &json);
- tiny_json_free(&json);
- tiny_json_free(&lines);
- free(session);
- free(cursor);
-}
-
-static void
call_read_messages(const mcpc_tool_t *tool, mcpc_ucbr_t *result)
{
tiny_mcp_tools_context_t *context = tiny_mcp_tools_context_current();
@@ -841,14 +761,6 @@ call_read_messages(const mcpc_tool_t *tool, mcpc_ucbr_t *result)
free(cursor_text);
return;
}
- if (view && strcmp(view, "export") == 0)
- {
- call_export_view(context, tool, result);
- free(view);
- free(session);
- free(cursor_text);
- return;
- }
if (view && strcmp(view, "history") != 0)
{
tiny_mcp_tool_add_error(result, "VALIDATION_ERROR", "unsupported read_messages view");
@@ -983,11 +895,7 @@ tiny_mcp_register_read_messages(mcpc_server_t *server)
call_read_messages);
return tool
&& tiny_mcp_tool_add_property(
- tool,
- "view",
- "Read view: history (default), context, sessions, or export.",
- MCPC_U8STR,
- false)
+ tool, "view", "Read view: history (default), context, or sessions.", MCPC_U8STR, false)
&& tiny_mcp_tool_add_property(tool,
"session_id",
"Conversation session whose chronological history to read.",
@@ -1022,11 +930,5 @@ tiny_mcp_register_read_messages(mcpc_server_t *server)
"omit for the first page.",
MCPC_U8STR,
false)
- && tiny_mcp_tool_add_property(tool,
- "include_deleted",
- "When true, export view includes deleted records as DEL "
- "lines; other views ignore this option.",
- MCPC_U8STR,
- false)
&& mcpc_server_add_tool(server, tool) == MCPC_EC_0;
}