Skip to content

feat(client): add list_all helpers for paginated MCP operations#2811

Open
ZXT-zjbiliy wants to merge 1 commit into
modelcontextprotocol:mainfrom
ZXT-zjbiliy:feat/list-all-helpers
Open

feat(client): add list_all helpers for paginated MCP operations#2811
ZXT-zjbiliy wants to merge 1 commit into
modelcontextprotocol:mainfrom
ZXT-zjbiliy:feat/list-all-helpers

Conversation

@ZXT-zjbiliy
Copy link
Copy Markdown

Description

Add list_all_tools, list_all_resources, list_all_resource_templates, and list_all_prompts methods to Client that automatically follow next_cursor and return all items across all pages.

Closes #2556

Motivation and Context

Currently, draining pagination requires manual cursor-following boilerplate:

all_tools = []
cursor = None
while True:
    result = await client.list_tools(cursor=cursor)
    all_tools.extend(result.tools)
    if result.next_cursor is None:
        break
    cursor = result.next_cursor

The new helpers reduce this to a single call:

result = await client.list_all_tools()

This is a common pattern that every consumer of paginated list endpoints reimplements. Providing it as a built-in helper reduces duplication and prevents off-by-one / cursor-mishandling bugs.

How Has This Been Tested?

  • 7 new tests covering: multi-page drain, single page, empty results, and output-schema cache population for list_all_tools
  • All 6 existing pagination tests (test_list_methods_cursor.py) still pass
  • Ruff lint and format clean

Breaking Changes

None. These are new additive methods on Client. Existing list_tools, list_resources, list_prompts, and list_resource_templates are unchanged.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Each list_all_* method follows next_cursor until the server returns None, collecting all items into a single result. For list_all_tools, the tool output-schema cache is populated as a side effect (same behavior as list_tools).

Add list_all_tools, list_all_resources, list_all_resource_templates,
and list_all_prompts methods to Client that automatically follow
next_cursor and return all items across all pages.

Closes modelcontextprotocol#2556
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.

Add list_all_* helpers to drain pagination

1 participant