Skip to content

mcp: add from/to time range to history tools#31

Merged
moeki0 merged 1 commit into
mainfrom
mcp-history-time-range
Apr 29, 2026
Merged

mcp: add from/to time range to history tools#31
moeki0 merged 1 commit into
mainfrom
mcp-history-time-range

Conversation

@moeki0

@moeki0 moeki0 commented Apr 29, 2026

Copy link
Copy Markdown
Owner

Problem

recent_screens({ minutes: 2880 }) で「昨日のやりとり」を取ろうとしても、結果が今朝のセッションしか返らなかった。原因は時間範囲の表現力ではなく limit=20 が新しい順で打ち切っていた こと。広げても上位 N 件は今朝のイベントで埋まってしまっていた。

Solution

5つの history MCP ツールに from / to を追加(ISO datetime か YYYY-MM-DD):

  • search_screen_history
  • recent_screens
  • recent_audio
  • search_audio
  • page_history

resolveRange(args, defaultMinutes) ヘルパーで一元的に解決:

  • from 指定時 → minutes を無視
  • to のみ指定(from なし)→ [to - minutes, to] の窓(to を過去日にしても 0 件にならない
  • YYYY-MM-DD はローカルTZの 00:00:00 / 23:59:59.999
  • 不正な日時は Error で弾く(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 typecheck
  • bun test (58 pass / 0 fail)
  • MCP 経由で recent_screens({ from: "2026-04-28", to: "2026-04-28", limit: 200, channel: "Hobby" }) を叩いて昨日の Hobby が取れることを確認
  • 既存の minutes 単独呼び出しの後方互換確認

🤖 Generated with Claude Code

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>
@moeki0 moeki0 merged commit f9e067d into main Apr 29, 2026
1 check passed
moeki0 added a commit that referenced this pull request Apr 29, 2026
- mcp: from/to time range on history tools (#31)
- swift/ax_text: include image alt + src in browser capture (#33)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant