Skip to main content
Glama

get_by_date_range

Retrieve posts published between specific dates from your local markdown knowledge base using ISO date format inputs.

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
NameRequiredDescriptionDefault
start_dateYes
end_dateYes
limitNo

Implementation Reference

  • main.py:522-544 (handler)
    The main MCP tool handler function for 'get_by_date_range'. It is registered via @mcp.tool() decorator, includes input schema in docstring and type hints, parses date strings to datetimes, calls the content manager helper, and formats the output.
    @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)
  • Supporting method in HugoContentManager class that implements the core logic for filtering content files within the specified date range, handling timezone normalization, sorting by date descending, and limiting results.
    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]

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/lethain/library-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server