Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[MCP] Keep the first list_tools() call cursor-free and require mcp>=1…
….9.4

mcp 1.8.x's list_tools() takes no cursor at all, and before 1.9.4 the cursor
is sent outside params, so a paginating server returns page one forever.
Call list_tools() plainly first so non-paginated servers behave as before,
and raise the extra's floor to the first release that paginates correctly.
  • Loading branch information
Kayvan-Zahiri committed Sep 21, 2026
commit 8fc922f6551e2af416d257b2ee44787bc5260436
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def get_version() -> str:

extras["hf_xet"] = [HF_XET_VERSION]

extras["mcp"] = ["mcp>=1.8.0, <2.0.0"]
extras["mcp"] = ["mcp>=1.9.4, <2.0.0"] # list_tools(cursor=...) only paginates correctly from 1.9.4

extras["testing"] = (
extras["oauth"]
Expand Down
11 changes: 4 additions & 7 deletions src/huggingface_hub/inference/_mcp/mcp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,11 @@ async def add_mcp_server(self, type: ServerType, **params: Any):
await session.initialize()

# List available tools, following `nextCursor` since servers may paginate tools/list
tools: list[mcp_types.Tool] = []
cursor: str | None = None
while True:
response = await session.list_tools(cursor=cursor)
response = await session.list_tools()
tools: list[mcp_types.Tool] = list(response.tools)
while response.nextCursor:
response = await session.list_tools(cursor=response.nextCursor)
tools.extend(response.tools)
cursor = response.nextCursor
if not cursor:
break
logger.debug("Connected to server with tools:", [tool.name for tool in tools])

# Filter tools based on allowed_tools configuration
Expand Down
Loading