Skip to content
Merged
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
19 changes: 13 additions & 6 deletions src/huggingface_hub/inference/_mcp/mcp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,24 @@ async def add_mcp_server(self, type: ServerType, **params: Any):
logger.debug("Initializing session...")
await session.initialize()

# List available tools
response = await session.list_tools()
logger.debug("Connected to server with tools:", [tool.name for tool in response.tools])
# 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)
tools.extend(response.tools)
cursor = response.nextCursor
if not cursor:
break

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pagination breaks older allowed mcp

Low Severity

The pagination loop always calls list_tools with cursor=, but that argument does not exist in mcp 1.8.x and is sent incorrectly in 1.9.0. Those versions are still allowed by the extra, so add_mcp_server can raise TypeError or spin forever against a paginating server.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit bf99263. Configure here.

logger.debug("Connected to server with tools:", [tool.name for tool in tools])

# Filter tools based on allowed_tools configuration
filtered_tools = response.tools
filtered_tools = tools

if allowed_tools is not None:
filtered_tools = [tool for tool in response.tools if tool.name in allowed_tools]
filtered_tools = [tool for tool in tools if tool.name in allowed_tools]
logger.debug(
f"Tool filtering applied. Using {len(filtered_tools)} of {len(response.tools)} available tools: {[tool.name for tool in filtered_tools]}"
f"Tool filtering applied. Using {len(filtered_tools)} of {len(tools)} available tools: {[tool.name for tool in filtered_tools]}"
)

for tool in filtered_tools:
Expand Down