Skip to content

feat: add list_recent_files tool#534

Open
Metzpapa wants to merge 1 commit into
taylorwilsdon:mainfrom
Metzpapa:feat/list-recent-files
Open

feat: add list_recent_files tool#534
Metzpapa wants to merge 1 commit into
taylorwilsdon:mainfrom
Metzpapa:feat/list-recent-files

Conversation

@Metzpapa
Copy link
Copy Markdown

@Metzpapa Metzpapa commented Mar 2, 2026

Summary

Adds a new list_recent_files Drive tool that lists recently modified, viewed, shared, or created files across all of Google Drive — not limited to a single folder or root.

This fills a gap where search_drive_files requires a keyword query and list_drive_items is scoped to a single folder. There's currently no way to ask "show me what's been recently touched across my whole Drive, including files shared with me."

Features

  • Sort by: modifiedTime, viewedByMeTime, sharedWithMeTime, or createdTime (all descending)
  • Ownership filter: all (default), owned (my files only), shared (files others shared with me)
  • File type filter: Same friendly names as other Drive tools (doc, sheet, pdf, etc.)
  • Rich metadata: Returns lastModifyingUser (name + email) and owners for each file
  • Pagination: Standard page_token support

Changes

  • gdrive/drive_helpers.py: Added backward-compatible order_by parameter to build_drive_list_params
  • gdrive/drive_tools.py: Added list_recent_files tool function

Why

AI assistants using this MCP server often need to find recently modified files without knowing exact keywords — for example, finding team documents shared in the last few days, or seeing what collaborators have been working on. The ownership: "shared" + sort_by: "modifiedTime" combination is particularly useful for discovering documents you didn't create but need to access.

No new OAuth scopes or API dependencies — uses existing Drive API v3 files.list with orderBy.

Test plan

  • Call list_recent_files with default params — returns 20 most recently modified files
  • Call with ownership: "shared" — returns only files not owned by the caller
  • Call with sort_by: "viewedByMeTime" — returns files sorted by last viewed
  • Call with file_type: "doc" — returns only Google Docs
  • Verify lastModifyingUser and owners fields appear in output
  • Verify pagination via nextPageToken / page_token
  • Verify existing search_drive_files and list_drive_items are unaffected by order_by helper change

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Custom Sort Options: Control how your Google Drive file lists are ordered with flexible sort criteria to match your workflow and preferences.
    • Recent Files Browser: Easily explore recently modified or viewed files across all your drives with granular filtering options (by ownership and file type) and multiple sorting methods including modification time, creation date, and view history.

Adds a new Drive tool that lists recently modified, viewed, shared, or
created files across ALL of Google Drive (not limited to a single folder).

Features:
- Sort by modifiedTime, viewedByMeTime, sharedWithMeTime, or createdTime
- Filter by ownership: all, owned (my files), or shared (others' files)
- Filter by file type (doc, sheet, pdf, etc.)
- Returns lastModifyingUser and owner info for each file
- Pagination support via page_token

Also adds backward-compatible `order_by` parameter to
build_drive_list_params helper.

Uses existing Drive API v3 files.list — no new scopes or auth required.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 2, 2026

📝 Walkthrough

Walkthrough

These changes enhance Google Drive integration by adding support for ordered results in list parameters and introducing a new tool to list recently modified files with filtering, sorting, and pagination capabilities.

Changes

Cohort / File(s) Summary
Drive API Helper Enhancement
gdrive/drive_helpers.py
Added optional order_by parameter to build_drive_list_params() to support Drive API ordering; parameter is threaded into list_params as "orderBy" when provided, with no impact on default behavior.
New Recent Files Tool
gdrive/drive_tools.py
Added new async function list_recent_files() decorated as a Google Drive read-only tool. Supports querying recently modified files with validation for sort_by options (modifiedTime, viewedByMeTime, sharedWithMeTime, createdTime), ownership filtering (all/owned/shared), optional MIME-type filtering, and pagination. Clamps page_size to [1, 100] and formats results into human-readable output.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Suggested labels

enhancement

Suggested reviewers

  • taylorwilsdon

Poem

🐰 A rabbit hops through Drive so vast,
Now sorted files move quick, not last!
Recent treasures, freshly found,
With filters spinning all around,
Organization's newfound grace,
Makes searching through the clouds a race! 🚀

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The PR description is comprehensive and well-structured, covering purpose, features, changes, and reasoning. However, it does not follow the required template structure with sections like 'Type of Change', 'Testing', and 'Checklist'. Follow the repository's PR description template by including required sections: Type of Change, Testing checklist, and Checklist items (including 'Allow edits from maintainers').
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: add list_recent_files tool' clearly and concisely describes the primary change: a new feature adding a tool for listing recent files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
gdrive/drive_tools.py (2)

566-583: Consider raising exceptions instead of returning error strings for validation failures.

Other tools in this file (e.g., manage_drive_access, set_drive_file_permissions) raise ValueError for invalid parameters, which allows the @handle_http_errors decorator to properly handle and log these as UserInputError. Returning a plain string bypasses this pattern and may lead to inconsistent error handling/logging.

♻️ Suggested refactor to use exceptions
     if sort_by not in valid_sort_options:
-        return (
-            f"Invalid sort_by '{sort_by}'. Must be one of: "
-            f"{', '.join(valid_sort_options.keys())}"
-        )
+        raise ValueError(
+            f"Invalid sort_by '{sort_by}'. Must be one of: "
+            f"{', '.join(valid_sort_options.keys())}"
+        )
     order_by = valid_sort_options[sort_by]
 
     # Build query based on ownership filter
     query_parts = ["trashed=false"]
 
     if ownership == "owned":
         query_parts.append("'me' in owners")
     elif ownership == "shared":
         query_parts.append("not 'me' in owners")
     elif ownership != "all":
-        return (
-            f"Invalid ownership '{ownership}'. Must be one of: all, owned, shared"
-        )
+        raise ValueError(
+            f"Invalid ownership '{ownership}'. Must be one of: all, owned, shared"
+        )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@gdrive/drive_tools.py` around lines 566 - 583, Replace the validation-return
branches that return error strings with raised ValueError exceptions so they
follow the same error handling pattern as other helpers like manage_drive_access
and set_drive_file_permissions; specifically, in the section using
valid_sort_options and sort_by raise a ValueError with a message listing
valid_sort_options.keys() instead of returning a string, and likewise replace
the ownership validation branch (ownership != "all") with a ValueError
describing allowed values ("all, owned, shared"); keep the same message content
but throw ValueError to let `@handle_http_errors` convert it to UserInputError and
preserve consistent logging/handling.

602-617: Consider reusing build_drive_list_params or documenting the deviation.

The new order_by parameter was added to build_drive_list_params in this PR, but list_recent_files builds its params manually. This is likely intentional due to the custom fields requirement (including lastModifyingUser and owners), but it creates slight duplication.

Either approach is fine, but a brief comment explaining why the helper isn't used would help future maintainers understand the design choice.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@gdrive/drive_tools.py` around lines 602 - 617, list_recent_files currently
builds list_params manually (setting fields to include lastModifyingUser and
owners and passing order_by) instead of reusing build_drive_list_params, which
causes duplication; either call build_drive_list_params(final_query, page_size,
order_by, page_token, include_items_from_all_drives, supportsAllDrives=True) and
then override the "fields" entry to add lastModifyingUser/owners, or keep the
manual construction but add a short comment above this block stating that
build_drive_list_params is intentionally not used because list_recent_files
requires a custom fields string (include reference to variables fields,
list_params and parameter order_by) so future maintainers understand the
deviation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@gdrive/drive_tools.py`:
- Around line 566-583: Replace the validation-return branches that return error
strings with raised ValueError exceptions so they follow the same error handling
pattern as other helpers like manage_drive_access and
set_drive_file_permissions; specifically, in the section using
valid_sort_options and sort_by raise a ValueError with a message listing
valid_sort_options.keys() instead of returning a string, and likewise replace
the ownership validation branch (ownership != "all") with a ValueError
describing allowed values ("all, owned, shared"); keep the same message content
but throw ValueError to let `@handle_http_errors` convert it to UserInputError and
preserve consistent logging/handling.
- Around line 602-617: list_recent_files currently builds list_params manually
(setting fields to include lastModifyingUser and owners and passing order_by)
instead of reusing build_drive_list_params, which causes duplication; either
call build_drive_list_params(final_query, page_size, order_by, page_token,
include_items_from_all_drives, supportsAllDrives=True) and then override the
"fields" entry to add lastModifyingUser/owners, or keep the manual construction
but add a short comment above this block stating that build_drive_list_params is
intentionally not used because list_recent_files requires a custom fields string
(include reference to variables fields, list_params and parameter order_by) so
future maintainers understand the deviation.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 04b9ae0 and 902b8a0.

📒 Files selected for processing (2)
  • gdrive/drive_helpers.py
  • gdrive/drive_tools.py

@taylorwilsdon
Copy link
Copy Markdown
Owner

I just spent several days collapsing down tools that were too specific, I think this is a good idea but I want to build it into an existing tool rather than spinning out another one. I think the most obvious option would be to add logic to search_drive_files that allows it to be used without a query term if a param (ie "recent") is included with the request. Thanks!

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.

2 participants