obsidian_get_recent_changes
Retrieve recently modified files from your Obsidian vault to track changes and maintain organization.
Instructions
Get recently modified files in the vault.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum number of files to return (default: 10) | |
| days | No | Only include files modified within this many days (default: 90) |
Implementation Reference
- src/mcp_obsidian/tools.py:615-632 (handler)The run_tool method that executes the tool logic: validates arguments, calls the Obsidian API's get_recent_changes, and returns JSON-formatted results.def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | EmbeddedResource]: limit = args.get("limit", 10) if not isinstance(limit, int) or limit < 1: raise RuntimeError(f"Invalid limit: {limit}. Must be a positive integer") days = args.get("days", 90) if not isinstance(days, int) or days < 1: raise RuntimeError(f"Invalid days: {days}. Must be a positive integer") api = obsidian.Obsidian(api_key=api_key, host=obsidian_host) results = api.get_recent_changes(limit, days) return [ TextContent( type="text", text=json.dumps(results, indent=2) ) ]
- src/mcp_obsidian/tools.py:591-613 (schema)Defines the tool's metadata including name, description, and input schema for parameters limit and days.def get_tool_description(self): return Tool( name=self.name, description="Get recently modified files in the vault.", inputSchema={ "type": "object", "properties": { "limit": { "type": "integer", "description": "Maximum number of files to return (default: 10)", "default": 10, "minimum": 1, "maximum": 100 }, "days": { "type": "integer", "description": "Only include files modified within this many days (default: 90)", "minimum": 1, "default": 90 } } } )
- src/mcp_obsidian/server.py:56-56 (registration)Registers an instance of RecentChangesToolHandler in the tool_handlers dictionary, making the tool available via the MCP server.add_tool_handler(tools.RecentChangesToolHandler())
- src/mcp_obsidian/obsidian.py:253-291 (helper)The Obsidian API helper method that constructs a DQL query to fetch recently modified files from the Obsidian server and handles the HTTP request.def get_recent_changes(self, limit: int = 10, days: int = 90) -> Any: """Get recently modified files in the vault. Args: limit: Maximum number of files to return (default: 10) days: Only include files modified within this many days (default: 90) Returns: List of recently modified files with metadata """ # Build the DQL query query_lines = [ "TABLE file.mtime", f"WHERE file.mtime >= date(today) - dur({days} days)", "SORT file.mtime DESC", f"LIMIT {limit}" ] # Join with proper DQL line breaks dql_query = "\n".join(query_lines) # Make the request to search endpoint url = f"{self.get_base_url()}/search/" headers = self._get_headers() | { 'Content-Type': 'application/vnd.olrapi.dataview.dql+txt' } def call_fn(): response = requests.post( url, headers=headers, data=dql_query.encode('utf-8'), verify=self.verify_ssl, timeout=self.timeout ) response.raise_for_status() return response.json() return self._safe_call(call_fn)