search_by_date
List indexed documents within a specified date range to discover recently indexed content or audit documents from a specific period.
Instructions
List indexed documents within a date range.
Returns file records matching the given date window. Useful for
discovering recently indexed content or auditing what was indexed in
a specific period.
Args:
after: Only include documents indexed/modified after this date.
before: Only include documents indexed/modified before this date.
source: Restrict to this source name.
file_type: Restrict to this file type (e.g. ``".pdf"``).
limit: Maximum records to return.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| after | No | ||
| before | No | ||
| source | No | ||
| file_type | No | ||
| limit | No |
Implementation Reference
- The main handler function for the search_by_date MCP tool. Registered via @mcp.tool() decorator, it accepts ISO-8601 date range parameters (after/before), source name, file_type, and limit. It performs access control via check_access(ctx, 'read'), queries metadata_store.list_files(status='indexed'), filters records by date/source/file_type, and returns matched records with metadata.
@mcp.tool() def search_by_date( after: Annotated[ str | None, "ISO-8601 date string; return only documents indexed/modified after this date.", ] = None, before: Annotated[ str | None, "ISO-8601 date string; return only documents indexed/modified before this date.", ] = None, source: Annotated[ str | None, "Restrict to a specific source name.", ] = None, file_type: Annotated[ str | None, "Restrict to a specific file type extension, e.g. '.jira' or '.pdf'.", ] = None, limit: Annotated[int, "Maximum number of records to return (1-500)."] = 50, ) -> dict: """List indexed documents within a date range. Returns file records matching the given date window. Useful for discovering recently indexed content or auditing what was indexed in a specific period. Args: after: Only include documents indexed/modified after this date. before: Only include documents indexed/modified before this date. source: Restrict to this source name. file_type: Restrict to this file type (e.g. ``".pdf"``). limit: Maximum records to return. """ from datetime import UTC, datetime from memorymesh.server.auth_guard import check_access if (err := check_access(ctx, "read")) is not None: return err limit = max(1, min(500, limit)) after_ts: float | None = None before_ts: float | None = None if after: try: after_ts = datetime.fromisoformat(after.replace("Z", "+00:00")).timestamp() except ValueError: return { "status": "error", "message": f"Invalid 'after' date format: {after!r}", } if before: try: before_ts = datetime.fromisoformat(before.replace("Z", "+00:00")).timestamp() except ValueError: return { "status": "error", "message": f"Invalid 'before' date format: {before!r}", } records = ctx.metadata_store.list_files(status="indexed") filtered = [] for rec in records: if source and rec.source_name != source: continue if file_type and rec.file_type != file_type: continue ts = rec.indexed_at or rec.mtime if after_ts and ts < after_ts: continue if before_ts and ts > before_ts: continue filtered.append(rec) if len(filtered) >= limit: break def _iso(ts: float | None) -> str: if ts is None: return "" return datetime.fromtimestamp(ts, tz=UTC).isoformat() return { "status": "ok", "count": len(filtered), "records": [ { "path": r.path, "source": r.source_name, "file_type": r.file_type, "n_chunks": r.n_chunks, "indexed_at": _iso(r.indexed_at), "mtime": _iso(r.mtime), } for r in filtered ], } - src/memorymesh/server/app.py:137-137 (registration)Registration call that invokes the register() function from search_by_date.py, passing the FastMCP instance and AppContext to wire the tool into the MCP server.
search_by_date.register(mcp, ctx) - src/memorymesh/server/app.py:120-120 (registration)Import of the search_by_date module in build_mcp(), making it available for registration.
search_by_date, - Input schema / type annotations for the search_by_date tool: after, before (optional ISO-8601 strings), source, file_type (optional string filters), and limit (int, clamped 1-500).
after: Annotated[ str | None, "ISO-8601 date string; return only documents indexed/modified after this date.", ] = None, before: Annotated[ str | None, "ISO-8601 date string; return only documents indexed/modified before this date.", ] = None, source: Annotated[ str | None, "Restrict to a specific source name.", ] = None, file_type: Annotated[ str | None, "Restrict to a specific file type extension, e.g. '.jira' or '.pdf'.", ] = None, limit: Annotated[int, "Maximum number of records to return (1-500)."] = 50, ) -> dict: """List indexed documents within a date range. Returns file records matching the given date window. Useful for discovering recently indexed content or auditing what was indexed in a specific period. Args: after: Only include documents indexed/modified after this date. before: Only include documents indexed/modified before this date. source: Restrict to this source name. file_type: Restrict to this file type (e.g. ``".pdf"``). limit: Maximum records to return. - MetadataStore.list_files() delegates to FileRepository.list_files() to fetch all file records, optionally filtered by source_name and status. Used by the search_by_date tool to retrieve indexed records before filtering by date range.
def list_files( self, source_name: str | None = None, status: str | None = None, ) -> list[FileRecord]: """Return all file records matching the optional filters. Args: source_name: Restrict to a specific source. ``None`` = all sources. status: Restrict to a specific status value. ``None`` = all statuses. """ return self._files.list_files(source_name=source_name, status=status)