mcp: add from/to time range to history tools#31
Merged
Conversation
The original problem was "yesterday's conversation can't be retrieved": recent_screens(minutes=2880) still returned only this morning's records because `limit=20` capped the most-recent-first result before older events could surface. The root cause was the limit, not the time expressiveness, but a date range is also useful and addresses both "yesterday only" and "between X and Y" queries. Added `from` / `to` (ISO datetime or YYYY-MM-DD) to all five history MCP tools: search_screen_history, recent_screens, recent_audio, search_audio, page_history. Implemented via a single resolveRange() helper. When `from` is given it overrides `minutes`; when `to` is given without `from`, the window is `[to - minutes, to]` so a past `to` doesn't collapse to zero rows. Tool descriptions warn that wide ranges need a larger `limit`. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
recent_screens({ minutes: 2880 })で「昨日のやりとり」を取ろうとしても、結果が今朝のセッションしか返らなかった。原因は時間範囲の表現力ではなくlimit=20が新しい順で打ち切っていた こと。広げても上位 N 件は今朝のイベントで埋まってしまっていた。Solution
5つの history MCP ツールに
from/toを追加(ISO datetime かYYYY-MM-DD):search_screen_historyrecent_screensrecent_audiosearch_audiopage_historyresolveRange(args, defaultMinutes)ヘルパーで一元的に解決:from指定時 →minutesを無視toのみ指定(fromなし)→[to - minutes, to]の窓(toを過去日にしても 0 件にならない)YYYY-MM-DDはローカルTZの 00:00:00 / 23:59:59.999Errorで弾く(MCP framework がエラー応答に変換)minutesの負数 / NaN もデフォルト値にフォールバックCaveats / Out of scope
limitのデフォルトは据え置き(20〜50)。動機の根本原因なので tool description で「広い範囲を使うときはlimitを上げる」と明記したが、自動引き上げまではしていない。後続で検討。fromの下限比較は既存のtimestamp > ?のまま(timestamp >= ?ではない)。from=YYYY-MM-DDでちょうど 00:00:00.000 の記録は除外されるが、export.ts と整合するため維持。Test plan
bun run typecheckbun test(58 pass / 0 fail)recent_screens({ from: "2026-04-28", to: "2026-04-28", limit: 200, channel: "Hobby" })を叩いて昨日の Hobby が取れることを確認minutes単独呼び出しの後方互換確認🤖 Generated with Claude Code