Skip to content

fix: follow nextCursor when listing MCP tools - #65

Open
airidasbrikas23 wants to merge 1 commit into
knowsuchagency:mainfrom
airidasbrikas23:fix/tools-list-pagination
Open

fix: follow nextCursor when listing MCP tools#65
airidasbrikas23 wants to merge 1 commit into
knowsuchagency:mainfrom
airidasbrikas23:fix/tools-list-pagination

Conversation

@airidasbrikas23

Copy link
Copy Markdown

Fixes #64.

`session.list_tools()` only returns one page; on any MCP server whose tool count exceeds the page size, everything past page 1 was silently missing from `--list` and from the generated CLI subcommands, with no error or warning.

`tools/list` is a paginated operation per the MCP spec — page size is up to the server, and clients should loop until `nextCursor` is absent:

Page size is determined by the server, and clients MUST NOT assume a fixed page size.
Clients SHOULD: Treat a missing `nextCursor` as the end of results. Support both paginated and non-paginated flows.

Changes

  • Adds `_list_all_tools(session)`, a small helper that calls `list_tools(cursor=...)` in a loop, accumulating results until `nextCursor` is empty.
  • Routes all three `session.list_tools()` call sites (the `--list` display path, the `_dispatch_list_tools` persistent-session dispatcher, and `_fetch_mcp_tools`'s CLI-subcommand-generation path) through it.
  • Adds unit tests (`TestListAllTools` in `tests/test_helpers.py`) covering the single-page case, a multi-page walk, and an empty result, using a fake session so the test doesn't depend on any real server's pagination behavior.

Verified against a real paginated server: stimmt/craft-mcp (a Craft CMS MCP server) pages `tools/list` at 50. Before this fix, a 54-tool connection was missing its last 4 tools (`get_entry`, `create_entry`, `update_entry`, `describe_entry_schema`) from `--list` with zero indication anything was wrong; after, all 54 show up and are callable.

Full test suite passes (355 tests, no regressions).

session.list_tools() only returns one page; on any MCP server whose
tool count exceeds the page size, everything past page 1 was silently
missing from --list and from the generated CLI subcommands, with no
error or warning.

tools/list is a paginated operation per the MCP spec (page size is up
to the server, clients should loop until nextCursor is absent):
https://modelcontextprotocol.io/specification/2025-06-18/server/utilities/pagination

Adds _list_all_tools(), a shared helper that loops on cursor until
exhausted, and routes all three session.list_tools() call sites
through it. Reproduced against a real server (stimmt/craft-mcp, a
Craft CMS MCP server) that pages at 50: a 54-tool connection was
missing its last 4 tools before this fix.
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.

--list silently drops tools past the first page on MCP servers that paginate tools/list

1 participant