Client.listTools() silently drops pages when a server repeats a cursor
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 74/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- typescript
- Área
- api
Línea de trabajo
Comienza en el punto de entrada _listAllPages utilizado por listTools(), listPrompts(), listResources() y listResourceTemplates(), y luego inspecciona cómo se supone que listMaxPages y ListPaginationExceeded deben limitar la paginación. Usa la reproducción proporcionada con un cursor vacío repetido para verificar la secuencia de solicitudes y los resultados agregados. Se considera terminado cuando un cursor repetido o cíclico no se informa silenciosamente como una lista completa y los fallos por el límite de paginación siguen siendo visibles.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Version
@modelcontextprotocol/client 2.0.0
Summary
When a server returns the same opaque cursor for more than one page, the auto-aggregating listTools() / listPrompts() / listResources() / listResourceTemplates() path stops early and reports the result as complete. The caller cannot tell that pages are missing.
In _listAllPages:
let cursor = acc.nextCursor;
const seen = new Set();
let pages = 1;
while (cursor !== void 0 && !seen.has(cursor)) {
...
}
delete acc.nextCursor;
Two things combine here. The loop exits when a cursor repeats, and then nextCursor is deleted from the aggregate, so the truncated list is indistinguishable from a complete one. No error is thrown and nothing is logged.
Why this is a problem
The 2026-07-28 pagination rules say cursors are opaque:
Don't make any determination based on cursor value other than whether a non-null value was provided (e.g. an empty string is a valid cursor and thus MUST NOT be treated as the end of results)
Comparing two cursors for equality is a determination based on their value. Nothing in the spec requires successive pages to carry different tokens, so a server that keeps its pagination position server side and returns one constant handle for every page is behaving legally, and the client drops everything after page two.
The empty string makes this concrete. It is the spec's own example of a valid cursor, and it is a natural choice for a server whose token carries no information, but a server that returns nextCursor: "" twice gets truncated.
A cursor cycle such as A, B, A truncates the same way.
Repro
import { Client } from "@modelcontextprotocol/client";
const PAGES = [
{ name: "alpha", nextCursor: "" },
{ name: "beta", nextCursor: "" },
{ name: "gamma" }, // last page, no nextCursor
];
let index = 0;
const received = [];
const transport = {
async start() {},
async close() {},
async send(message) {
if (message.id === undefined || message.id === null) return;
const reply = (result) =>
queueMicrotask(() =>
transport.onmessage?.({ jsonrpc: "2.0", id: message.id, result })
);
if (message.method === "initialize") {
return reply({
protocolVersion: message.params.protocolVersion,
capabilities: { tools: {} },
serverInfo: { name: "repeated-cursor", version: "1.0.0" },
});
}
if (message.method === "tools/list") {
const cursor = message.params?.cursor;
received.push(cursor);
if (cursor === undefined) index = 0;
const page = PAGES[Math.min(index, PAGES.length - 1)];
index += 1;
return reply({
tools: [{ name: page.name, inputSchema: { type: "object" } }],
...(page.nextCursor === undefined ? {} : { nextCursor: page.nextCursor }),
});
}
return reply({});
},
};
const client = new Client({ name: "repro", version: "1.0.0" });
await client.connect(transport);
const result = await client.listTools();
console.log("requests: ", JSON.stringify(received));
console.log("tools: ", result.tools.map((t) => t.name).join(", "));
console.log("nextCursor:", JSON.stringify(result.nextCursor));
Actual:
requests: [null,""]
tools: alpha, beta
nextCursor: undefined
Expected: alpha, beta, gamma. The server was still offering a cursor after beta, and the third request is never sent.
Suggested fix
Drop the seen set and let listMaxPages bound the walk. The cap already covers the case the dedupe is aimed at, its own docs describe it as "a defence against a server whose nextCursor never converges", and it does that without reading cursor values. It also fails loudly with ListPaginationExceeded instead of returning a short list that looks complete. A server that wants to spin the client can return distinct cursors forever anyway, so the dedupe only catches the one shape that may well be legitimate.
If the dedupe is worth keeping for some reason, throwing on a repeat rather than returning a truncated aggregate would at least make the truncation visible.
Happy to send a PR if you would like one.
Context
Found while fixing our own client so it treats an empty-string nextCursor as a real cursor. Our code is correct now, but the aggregate walk is below us, so the tool list still comes back short for this kind of server.
- Lenguaje dominante
- TypeScript
- Estrellas
- 13.6k
- Forks
- 2.5k
- Merge medio
- 1 d 2 h
- PR fusionados (30 d)
- 51
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de modelcontextprotocol/typescript-sdk
-
[v2] e2e `protocol:timeout:max-total` is flaky over SSE: fake timers advance before the request reaches the serverPosiblemente ocupada @Singmin la tomó hace 1 día. Abiertov1 v2
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
modelcontextprotocol/typescript-sdk#3045 ·
Los mantenedores suelen responder en 1 día
-
[v1.x] Backport #2654: `notifications/cancelled` with `requestId: 0` is ignored, so the first server→client request cannot be cancelled (still in 1.32.1)Posiblemente ocupada @CloudCorpRecords la tomó hace 2 días. Abiertov1
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
modelcontextprotocol/typescript-sdk#3043 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Stateless 405 response omits the Allow headerPosiblemente ocupada @Hugo-DDT la tomó hace 9 días. Abiertov2
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
modelcontextprotocol/typescript-sdk#2970 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
[v2] @modelcontextprotocol/server inlines fast-uri 3.1.0, which has 9 published advisoriesPosiblemente ocupada @Andiii208 la tomó hace 11 días. Abiertov2
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
modelcontextprotocol/typescript-sdk#2966 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
v1 v2
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
modelcontextprotocol/typescript-sdk#2946 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de modelcontextprotocol/typescript-sdk
Issues similares
-
DQ assisgnment closing at CRAbiertoenhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
equinor/prisma-decision-web#919 ·
Los mantenedores suelen responder en 1 día
-
[DC] OneLogin sync imports a partial user list when an API request failsPosiblemente ocupada @RaphaelFakhri la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
bitwarden/directory-connector#1276 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
home-assistant/installer#324 ·
Los mantenedores suelen responder en 1 día
-
Mondriaan
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
knaw-huc/textannoviz#733 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día