-
Notifications
You must be signed in to change notification settings - Fork 700
Description
1. Title
Infinite Loop in MCP Client When Processing Empty nextCursor
During listTools()
Call
2. Description
The MCP Java SDK client enters an infinite loop when processing the /tools
response from Alibaba Cloud DashScope MCP applications. The client incorrectly interprets an empty nextCursor
value (""
) as a signal to continue pagination, resulting in repeated requests that eventually time out (10s default timeout).
Affected SDK Version: io.modelcontextprotocol.client:client-java:0.14.1
(and likely all prior versions)
3. Steps to Reproduce
- Configure MCP client to connect to Alibaba Cloud DashScope MCP application with
market-cmapi00035184
(Global IP Geolocation) - Call
client.listTools()
- Observe repeated HTTP requests to
/tools
endpoint
java编辑McpClientConfig config = McpClientConfig.builder() .addHeader("Authorization", "Bearer YOUR_API_KEY") .build();
McpSyncClient client = McpClient.connect(
"https://dashscope.aliyuncs.com/api/v1/mcps/market-cmapi00035184/mcp",
config
);
List<Tool> tools = client.listTools(); // Triggers infinite loop
4. Expected Behavior
The client should:
- Receive a single
/tools
response - Detect that
nextCursor
is empty (""
) - Exit pagination loop immediately
- Return the tool list without timeout
5. Actual Behavior
The client:
- Receives valid tool list response with
nextCursor: ""
- Incorrectly interprets empty string as needing pagination
- Sends repeated
/tools
requests (e.g.,2e9e1828-904
,2e9e1828-905
,2e9e1828-906
) - Eventually fails with
TimeoutException
after 10s
Error Log:
log编辑[DEBUG] Sending message for method tools/list (ID: 2e9e1828-904) [DEBUG] Received JSON message: {"jsonrpc":"2.0","id":"2e9e1828-904","result":{"nextCursor":"","tools":[...]}} [DEBUG] Sending message for method tools/list (ID: 2e9e1828-905) [DEBUG] Received JSON message: {"jsonrpc":"2.0","id":"2e9e1828-905","result":{"nextCursor":"","tools":[...]}} [DEBUG] Sending message for method tools/list (ID: 2e9e1828-906) ... [ERROR] TimeoutException: Did not observe any item within 10000ms
6. Key Evidence
Test Case | Application ID | HTTP Response | SDK Behavior |
---|---|---|---|
Working | market-cmapi00035184 (IP Geolocation) | {"nextCursor":"","tools":[...]} | Infinite loop → Timeout |
Working | market-cmapi00035184 (IP Geolocation) | curl -H "Authorization: Bearer KEY" https://dashscope.aliyuncs.com/api/v1/mcps/market-cmapi00035184/mcp/tools | Returns valid JSON (no loop) |
12. Resolution Plan
- Patch: Implement the fix in
McpClientSession.java
(as shown in Section 8) - Test: Add unit tests for empty string handling (see Test Plan)
- Release: New SDK version
1.0.1
- Documentation: Update README with pagination best practices
Note: The fix does not affect applications that return
nextCursor: null
Reported By: moyuyanli
Date: October 20, 2025
SDK Version: io.modelcontextprotocol.client:client-java:0.14.1
Platform: Java 11+
Environment: Alibaba Cloud DashScope MCP (v1.0)