From 3bafbf66dd69f53e885c7a5b432f59805e0f4fee Mon Sep 17 00:00:00 2001 From: Tyler Longwell Date: Sat, 21 Mar 2026 14:45:48 -0400 Subject: [PATCH] feat(messages): add `since` parameter to get_messages API and MCP tool Adds forward pagination to the channel messages endpoint, enabling agents to poll for new messages since a given timestamp. Mirrors the existing `before` parameter pattern. When `since` is provided without `before`, results are ordered oldest-first (ASC) for chronological consumption. When both are provided or only `before`, ordering remains newest-first (DESC). Changes: - sprout-db: add since_cursor param to get_channel_messages_top_level - sprout-relay: add since query param to GET /api/channels/:id/messages - sprout-mcp: add since field to GetMessagesParams, update tool description Naming follows NIP-01 convention (since/until) and matches the existing get_feed tool's since parameter. No schema changes or new indexes needed. Codex CLI review: 7/10, SQL injection safe, bind order correct, ORDER BY logic correct. One pre-existing pattern noted (invalid timestamps silently ignored, consistent with existing before behavior). --- crates/sprout-db/src/lib.rs | 2 ++ crates/sprout-db/src/thread.rs | 28 +++++++++++++++++++++---- crates/sprout-mcp/src/server.rs | 14 +++++++++++-- crates/sprout-relay/src/api/messages.rs | 23 +++++++++++++++++--- 4 files changed, 58 insertions(+), 9 deletions(-) diff --git a/crates/sprout-db/src/lib.rs b/crates/sprout-db/src/lib.rs index ca01f76f..052dc204 100644 --- a/crates/sprout-db/src/lib.rs +++ b/crates/sprout-db/src/lib.rs @@ -604,6 +604,7 @@ impl Db { channel_id: Uuid, limit: u32, before_cursor: Option>, + since_cursor: Option>, kind_filter: Option<&[u32]>, ) -> Result> { thread::get_channel_messages_top_level( @@ -611,6 +612,7 @@ impl Db { channel_id, limit, before_cursor, + since_cursor, kind_filter, ) .await diff --git a/crates/sprout-db/src/thread.rs b/crates/sprout-db/src/thread.rs index decde54e..cec99c06 100644 --- a/crates/sprout-db/src/thread.rs +++ b/crates/sprout-db/src/thread.rs @@ -480,14 +480,19 @@ pub async fn get_thread_summary(pool: &PgPool, event_id: &[u8]) -> Result