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
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:
[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
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)
1. Title
Infinite Loop in MCP Client When Processing Empty
nextCursorDuringlistTools()Call2. Description
The MCP Java SDK client enters an infinite loop when processing the
/toolsresponse from Alibaba Cloud DashScope MCP applications. The client incorrectly interprets an emptynextCursorvalue ("") 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
market-cmapi00035184(Global IP Geolocation)client.listTools()/toolsendpoint4. Expected Behavior
The client should:
/toolsresponsenextCursoris empty ("")5. Actual Behavior
The client:
nextCursor: ""/toolsrequests (e.g.,2e9e1828-904,2e9e1828-905,2e9e1828-906)TimeoutExceptionafter 10sError Log:
6. Key Evidence
12. Resolution Plan
McpClientSession.java(as shown in Section 8)1.0.1Reported By: moyuyanli
Date: October 20, 2025
SDK Version:
io.modelcontextprotocol.client:client-java:0.14.1Platform: Java 11+
Environment: Alibaba Cloud DashScope MCP (v1.0)