get_by_date_range
Retrieve posts published within a specified date range from your Markdown knowledge base. Input start and end dates in ISO format to filter and access relevant content efficiently.
Instructions
Get posts published within a date range.
Args: start_date: the start date in ISO format (YYYY-MM-DD) end_date: the end date in ISO format (YYYY-MM-DD) limit: the maximum number of posts to return
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| end_date | Yes | ||
| limit | No | ||
| start_date | Yes |
Implementation Reference
- main.py:522-544 (handler)Primary MCP tool handler: parses string date inputs to datetimes, filters posts using content manager helper, formats and returns results.@mcp.tool() async def get_by_date_range(start_date: str, end_date: str, limit: int = 50) -> str: """Get posts published within a date range. Args: start_date: the start date in ISO format (YYYY-MM-DD) end_date: the end date in ISO format (YYYY-MM-DD) limit: the maximum number of posts to return """ if content_manager is None: return "Content has not been loaded. Please ensure the server is properly initialized." try: # Parse dates with time set to beginning/end of day # Always create naive datetimes for consistent comparison start = datetime.fromisoformat(f"{start_date}T00:00:00") end = datetime.fromisoformat(f"{end_date}T23:59:59") except ValueError as e: return f"Error parsing dates: {e}. Please use ISO format (YYYY-MM-DD)." posts = content_manager.get_by_date_range(start, end, limit) return format_content_for_output(posts)
- main.py:331-369 (helper)Core filtering logic in HugoContentManager: matches content files where post date falls within the given datetime range, sorts by recency, applies limit.def get_by_date_range(self, start_date: datetime, end_date: datetime, limit: int = 50) -> List[ContentFile]: """Find all posts within a date range""" matches = [] debug_print(f"Searching for posts between {start_date} and {end_date}") for _, content_file in self.path_to_content.items(): post_date = content_file.date if post_date: # Make date naive for comparison if it has timezone info if hasattr(post_date, 'tzinfo') and post_date.tzinfo is not None: post_date = post_date.replace(tzinfo=None) # Make start and end dates naive for comparison start_naive = start_date if hasattr(start_naive, 'tzinfo') and start_naive.tzinfo is not None: start_naive = start_naive.replace(tzinfo=None) end_naive = end_date if hasattr(end_naive, 'tzinfo') and end_naive.tzinfo is not None: end_naive = end_naive.replace(tzinfo=None) if start_naive <= post_date <= end_naive: matches.append(content_file) debug_print(f"Found {len(matches)} posts within date range") # Sort by date (most recent first) def get_sort_key(content_file): date = content_file.date if date is None: return datetime.min # Make date naive if it has timezone info if hasattr(date, 'tzinfo') and date.tzinfo is not None: date = date.replace(tzinfo=None) return date matches.sort(key=get_sort_key, reverse=True) return matches[:limit]
- main.py:522-522 (registration)FastMCP decorator that registers the get_by_date_range function as a tool.@mcp.tool()
- main.py:523-530 (schema)Input/output schema via type annotations and detailed docstring describing parameters and expected formats.async def get_by_date_range(start_date: str, end_date: str, limit: int = 50) -> str: """Get posts published within a date range. Args: start_date: the start date in ISO format (YYYY-MM-DD) end_date: the end date in ISO format (YYYY-MM-DD) limit: the maximum number of posts to return """