[BUG] Native MCP tool discovery ignores pages after nextCursor
Description
Native MCP tool discovery returns only the first page of tools/list. When a server returns nextCursor, MCPClient._list_tools_impl() ignores it, so later tools are omitted from the discovered catalog. Enabling the tool-list cache can retain this incomplete catalog.
This affects the native MCPClient path used by structured MCP server configurations such as MCPServerStdio. For example, if an Agent filter allows only a tool on the second page, that tool cannot be registered even though the server advertises it.
Reproduced on main at 753d1923660207989b6974ef414b8d91cd85e57c (CrewAI 1.15.27).
Steps to Reproduce
- In a CrewAI development environment, save the script below as
repro_mcp_pagination.py. - Run
python repro_mcp_pagination.py. It starts a real local stdio MCP server, asks the SDK for both pages, and compares them with CrewAI's discovered tools. No model call or API key is required. - On the unmodified revision, CrewAI returns only
search-ticketsand the assertion fails becauseget-ticketis missing. - Optionally run
python repro_mcp_pagination.py --agentto exercise Agent registration with a filter allowing only the second-page tool.
Expected behavior
Follow each returned nextCursor, passing the opaque value back as params.cursor, until the response omits the cursor. Return both tools, and let the Agent register the filtered second-page tool.
Screenshots/Code snippets
"""Offline MCP tool discovery reproduction using a real stdio server.
Run with the CrewAI checkout's virtual environment. No model or API key is used.
"""
import asyncio
import json
import os
from pathlib import Path
import sys
sys.stdout.reconfigure(encoding='utf-8')
sys.stderr.reconfigure(encoding='utf-8')
os.environ['OTEL_SDK_DISABLED'] = 'true'
os.environ['CREWAI_TRACING_ENABLED'] = 'false'
os.environ['CREWAI_DISABLE_TELEMETRY'] = 'true'
from mcp import types
from mcp.server.lowlevel import Server
from mcp.server.stdio import stdio_server
CURSOR = 'opaque:second-page/+=token'
SCHEMA = {'type': 'object', 'properties': {'ticket_id': {'type': 'string'}}, 'required': ['ticket_id']}
async def serve():
server = Server('pagination-repro')
@server.list_tools()
async def list_tools(request: types.ListToolsRequest) -> types.ListToolsResult:
cursor = request.params.cursor if request and request.params else None
if cursor is None:
return types.ListToolsResult(
tools=[types.Tool(name='search-tickets', description='Search tickets.', inputSchema=SCHEMA)],
nextCursor=CURSOR,
)
if cursor == CURSOR:
return types.ListToolsResult(
tools=[types.Tool(name='get-ticket', description='Read a ticket.', inputSchema=SCHEMA)],
)
raise ValueError('Unexpected cursor')
@server.call_tool()
async def call_tool(name: str, arguments: dict) -> list[types.TextContent]:
return [types.TextContent(type='text', text=json.dumps({'tool': name, **arguments}))]
async with stdio_server() as (read, write):
await server.run(read, write, server.create_initialization_options())
async def reproduce():
from crewai.mcp.client import MCPClient
from crewai.mcp.transports.stdio import StdioTransport
transport = StdioTransport(command=sys.executable, args=[str(Path(__file__).resolve()), '--server'])
async with MCPClient(transport, max_retries=1) as client:
first = await client.session.list_tools()
second = await client.session.list_tools(params=types.PaginatedRequestParams(cursor=first.nextCursor))
expected = [tool.name for tool in first.tools + second.tools]
discovered = await client.list_tools()
actual = [tool['original_name'] for tool in discovered]
print(json.dumps({'server_tools': expected, 'crewai_discovered': actual, 'missing': sorted(set(expected) - set(actual))}))
assert actual == expected, 'CrewAI did not discover all advertised tools'
result = await client.call_tool('get-ticket', {'ticket_id': 'TKT-123'})
print('second_page_tool_result:', result)
def reproduce_agent():
from crewai import Agent, BaseLLM
from crewai.mcp.config import MCPServerStdio
from crewai.mcp.filters import create_static_tool_filter
class OfflineLLM(BaseLLM):
def call(self, *args, **kwargs):
raise AssertionError('Tool discovery must not call a model')
agent = Agent(role='Ticket analyst', goal='Read a ticket', backstory='Offline reproduction', llm=OfflineLLM(model='offline'))
config = MCPServerStdio(
command=sys.executable,
args=[str(Path(__file__).resolve()), '--server'],
tool_filter=create_static_tool_filter(allowed_tool_names=['get_ticket']),
)
tools = agent.get_mcp_tools([config])
original_names = [item.original_tool_name for item in tools]
print('agent_filtered_tools:', json.dumps(original_names))
assert original_names == ['get-ticket'], 'Agent cannot register the requested second-page tool'
result = tools[0].run(ticket_id='TKT-123')
print('agent_tool_result:', result)
assert json.loads(result) == {'tool': 'get-ticket', 'ticket_id': 'TKT-123'}
if __name__ == '__main__':
if '--agent' in sys.argv:
reproduce_agent()
else:
asyncio.run(serve() if '--server' in sys.argv else reproduce())
Operating System
Windows 11
Python Version
3.12
crewAI Version
1.15.27, editable checkout of 753d1923660207989b6974ef414b8d91cd85e57c.
crewAI Tools Version
1.15.27. The reproduction exercises native MCP discovery rather than MCPServerAdapter.
Virtual Environment
Venv
Evidence
Before the fix:
server_tools: ["search-tickets", "get-ticket"]
crewai_discovered: ["search-tickets"]
missing: ["get-ticket"]
AssertionError: CrewAI did not discover all advertised tools
With the proposed fix:
server_tools: ["search-tickets", "get-ticket"]
crewai_discovered: ["search-tickets", "get-ticket"]
missing: []
second_page_tool_result: {"tool": "get-ticket", "ticket_id": "TKT-123"}
agent_filtered_tools: ["get-ticket"]
agent_tool_result: {"tool": "get-ticket", "ticket_id": "TKT-123"}
The proposed regression file has 9 failures and 2 passes on the unmodified implementation, and all 11 cases pass with the fix. The local MCP suite passes all 94 cases with the fix.
Possible Solution
Collect pages inside _list_tools_impl() using PaginatedRequestParams. Keep the existing tool conversion, retry boundary, discovery timeout, and cache insertion in list_tools() so failed/cancelled attempts cannot cache a partial catalog. A focused implementation and regression tests are ready for a linked PR.
The protocol describes this behavior in MCP pagination.
Additional context
This report and its accompanying implementation/tests were prepared with an AI coding assistant. This is an AI-generated contribution under the repository policy; the llm-generated label is required. My account does not have permission to manage labels in this repository; please add that label.
Tested with Python 3.12.14 and MCP Python SDK 1.28.1 in a uv-managed virtual environment.
This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
The pagination bug has a practical effect for a paid-tool catalog: if a server returns search-tools on page 1 and safe-preflight / verify-result on page 2, a CrewAI buyer can believe it has no verification tool and proceed without discovering the available control. This is a discovery correctness issue, not proof that a particular payment was mishandled.
I'd add four negative cases to the existing no-LLM test:
- a valid opaque
nextCursorwith punctuation must be passed back unchanged; - a repeated cursor must terminate with a descriptive error rather than loop forever;
- two pages containing the same tool name with conflicting schemas must not silently overwrite one another;
- do not write the catalog cache until traversal is complete (or explicitly label partial results as incomplete).
I'm contributing as JamenbinAucs / HumanMirror (commercial affiliation disclosed). Our free MCP discovery endpoint is https://humanmirror.fr/api/one/mcp/, but I have not verified whether it paginates; it should not be treated as a regression fixture for this specific bug. The provided local stdio repro is the appropriate test source. Happy to help review a test matrix if useful.