Skip to content

Bugfix: Adding missing nextPageToken for pagination in drive tools - #513

Merged
taylorwilsdon merged 6 commits into
taylorwilsdon:mainfrom
fmgs31:drive_files_pagination_fix
Feb 28, 2026
Merged

Bugfix: Adding missing nextPageToken for pagination in drive tools#513
taylorwilsdon merged 6 commits into
taylorwilsdon:mainfrom
fmgs31:drive_files_pagination_fix

Conversation

@fmgs31

@fmgs31 fmgs31 commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

Closes: #512

Description

Bug fix for #512

In GDrive Tools, nextPageToken is mentioned here:

google_workspace_mcp/gdrive/drive_helpers.py

However, it's not implemented.
Right now, only the first page can be returned.

This is true for both list_drive_items and search_drive_files.In GDrive Tools, nextPageToken is mentioned at:

Testing

  • [+ ] I have added tests that prove my fix is effective or that my feature works
  • [+ ] New and existing unit tests pass locally with my changes
  • [+ ] I have tested this change manually

Checklist

  • [+ ] My code follows the style guidelines of this project
  • [+ ] I have performed a self-review of my own code
  • [+ ] I have commented my code, particularly in hard-to-understand areas
  • [ +] My changes generate no new warnings
  • [+ ] I have enabled "Allow edits from maintainers" for this pull request

Additional Notes

Add any other context about the pull request here.

Summary by CodeRabbit

  • New Features

    • Added optional pagination parameter to Drive search/listing so callers can request specific pages; results now include nextPageToken when more pages exist.
    • Listings can include additional item details (size, modified time, view link) in detailed view.
  • Tests

    • Expanded tests for pagination, nextPageToken propagation, page-parameter forwarding, and detailed vs compact listing outputs.

@coderabbitai

coderabbitai Bot commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3d3932c and 8b69a49.

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

📝 Walkthrough

Walkthrough

Adds optional page_token propagation to Drive list parameter construction and to search/list tool functions; formatted outputs now include nextPageToken when returned by the API. Tests updated to cover token forwarding, pagination output, and detailed-vs-compact output behavior.

Changes

Cohort / File(s) Summary
Parameter builder
gdrive/drive_helpers.py
Added page_token: Optional[str] = None to build_drive_list_params signature and docstring; conditionally includes pageToken in returned params when provided.
Tools: search & list
gdrive/drive_tools.py
Added page_token: Optional[str] = None to search_drive_files and list_drive_items; forward token to build_drive_list_params; append nextPageToken: {token} to formatted output when API returns it.
Tests: drive tools
tests/gdrive/test_drive_tools.py
Expanded tests to verify page_token is forwarded as pageToken, nextPageToken inclusion/omission in outputs, and detailed vs compact field behavior for search and list functions. Added related helper/tests for folder resolving and create-folder checks.

Sequence Diagram

sequenceDiagram
    actor Client
    participant Tools as search_drive_files / list_drive_items
    participant Builder as build_drive_list_params
    participant API as Google Drive API

    Client->>Tools: Call with (query, page_size, page_token, ...)
    Tools->>Builder: build_drive_list_params(..., page_token)
    Builder-->>Tools: params (may include pageToken)
    Tools->>API: Execute files.list with params
    API-->>Tools: items + nextPageToken?
    Tools-->>Client: return formatted items (include nextPageToken if present)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐇 I hopped through pages, token in paw,

fetching files from Drive by law.
nextPageToken glows like a starry dome,
hop, fetch, follow — bring the pages home. 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: implementing missing nextPageToken for pagination in drive tools, which is the core fix for the bug mentioned in issue #512.
Description check ✅ Passed The description identifies the bug being fixed and mentions that nextPageToken was documented but not implemented, affecting both list_drive_items and search_drive_files. However, the testing and checklist sections have formatting issues (mixed brackets and symbols) and lack detail about the specific changes made.
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

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.

@fmgs31 fmgs31 changed the title Adding nextPageToken for pagination in drive tools Bugfix: Adding missing nextPageToken for pagination in drive tools Feb 26, 2026
@taylorwilsdon
taylorwilsdon requested review from Copilot and taylorwilsdon and removed request for Copilot February 27, 2026 17:18
@taylorwilsdon taylorwilsdon self-assigned this Feb 27, 2026
@taylorwilsdon taylorwilsdon added the bug Something isn't working label Feb 27, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/gdrive/test_drive_tools.py (1)

16-36: ⚠️ Potential issue | 🟠 Major

Duplicate imports and incomplete function definition need cleanup.

This segment appears to have merge artifacts or copy-paste errors:

  1. Lines 16-17 and line 24 duplicate the same imports from gdrive.drive_tools
  2. Lines 19-22 define an incomplete _unwrap function (no return statement, missing __wrapped__ handling)
  3. Lines 27-36 define the complete, correct _unwrap function
  4. The import on line 23 comes after code, causing the E402 linter failure

The second _unwrap definition (lines 27-36) shadows the first, so tests will run, but the dead code should be removed.

🔧 Proposed fix to consolidate imports and remove duplicate code
-from gdrive.drive_tools import list_drive_items, search_drive_files
-
-
-def _unwrap(fn):
-    """Unwrap a decorator chain to the original async function."""
-    if hasattr(fn, "fn"):
-        fn = fn.fn  # FunctionTool wrapper (other server versions)
-from gdrive.drive_helpers import build_drive_list_params
 from gdrive.drive_tools import list_drive_items, search_drive_files
+from gdrive.drive_helpers import build_drive_list_params


 def _unwrap(tool):
     """Unwrap a FunctionTool + decorator chain to the original async function.

     Handles both older FastMCP (FunctionTool with .fn) and newer FastMCP
     (server.tool() returns the function directly).
     """
     fn = tool.fn if hasattr(tool, "fn") else tool
     while hasattr(fn, "__wrapped__"):
         fn = fn.__wrapped__
     return fn
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/gdrive/test_drive_tools.py` around lines 16 - 36, Remove the merge
artifacts: consolidate imports so that build_drive_list_params,
list_drive_items, and search_drive_files are imported once at the top (no
imports after code to avoid E402), delete the incomplete duplicate _unwrap
definition (the one missing return and __wrapped__ handling), and keep the
complete _unwrap implementation (the version that handles tool.fn and unwraps
__wrapped__); ensure only the final _unwrap symbol remains and that imports
appear before any function definitions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@tests/gdrive/test_drive_tools.py`:
- Around line 16-36: Remove the merge artifacts: consolidate imports so that
build_drive_list_params, list_drive_items, and search_drive_files are imported
once at the top (no imports after code to avoid E402), delete the incomplete
duplicate _unwrap definition (the one missing return and __wrapped__ handling),
and keep the complete _unwrap implementation (the version that handles tool.fn
and unwraps __wrapped__); ensure only the final _unwrap symbol remains and that
imports appear before any function definitions.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1fab9a8 and 3d3932c.

📒 Files selected for processing (3)
  • gdrive/drive_helpers.py
  • gdrive/drive_tools.py
  • tests/gdrive/test_drive_tools.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • gdrive/drive_tools.py

Repository owner deleted a comment from carlosvianney Feb 28, 2026
@taylorwilsdon
taylorwilsdon merged commit 3286194 into taylorwilsdon:main Feb 28, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Pagination not working in gdrive tools

2 participants