Skip to content

fix(mcp): keep list_tasks pagination cursor intact on large pages - #805

Merged
pikann merged 1 commit into
Paca-AI:masterfrom
RiccardoBifulco:fix/mcp-list-tasks-cursor-803
Nov 20, 2026
Merged

pikann merged 1 commit into
Paca-AI:masterfrom
RiccardoBifulco:fix/mcp-list-tasks-cursor-803

Conversation

@RiccardoBifulco

Copy link
Copy Markdown
Contributor

Fixes #803

Changes

  • list_tasks now returns a compact summary per task by default; full descriptions are opt-in via includeDescription: true (use get_task for full content).
  • next_cursor and the total count are emitted in the header, before the task list, so a response-size limit can't truncate the cursor.
  • PacaAPIClient.listTasks preserves total_count (as total) and URL-encodes the cursor.

Tests

Added tests for long descriptions at pageSize=100 (exact cursor, placed before the list), total preservation, last page without cursor, compact vs detailed output, and cursor encoding. Targeted vitest suites pass, tsc --noEmit is clean and biome is clean on the changed files.

Return a compact task summary by default (descriptions behind the new
includeDescription flag), put next_cursor and total before the task list,
preserve total_count from the API and URL-encode the cursor.

Fixes #803
Copilot AI balanced review requested due to automatic review settings November 20, 2026 12:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No blocking issues — a few small suggestions inline.

Approach: sound — shrink the page by defaulting to a description-free summary and move the cursor ahead of the list, so a host that abbreviates oversized tool output can no longer eat the continuation token.

Reviewed changes

  • Cursor-first layout — list_tasks now emits Tasks (N returned, T total, more available): and a next_cursor: line before the task list, replacing the old end-of-response note.
  • Compact output by default — new includeDescription flag (default false) selects a new formatTaskSummary instead of formatTask; full descriptions remain available via the flag or get_task.
  • total_count preserved — PacaAPIClient.listTasks keeps total_count (falling back to total) as total, and the handler surfaces it as N total.
  • Cursor encoding — the cursor query value is now encodeURIComponent'd.
  • Regression tests — long-description page at pageSize=100, cursor ordering, total preservation, last page without cursor, compact vs detailed output, and cursor encoding.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

Comment on lines +212 to 217
const total = response.total_count ?? response.total;
return {
items: response.items || response.tasks || response.data || [],
nextCursor: response.next_cursor ?? null,
...(typeof total === "number" ? { total } : {}),
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This re-implements toPage, which is already imported into this file (line 25) and used by listSprints / listDocuments. Delegating keeps total_count mapping in one place and lets listTasks return the shared Page<Task> type (its shape is already identical).

Technical details
# Use the shared page reader

## Affected sites
- `apps/mcp/src/api/client.ts:212-217` — hand-rolled `items` / `next_cursor` / `total_count` extraction
- `apps/mcp/src/api/paginate.ts:56` — `toPage<T>` does the same mapping (`items ?? data`, `next_cursor`, `total_count ?? total`)

## Required outcome
- `listTasks` returns `Page<Task>` and delegates to `toPage<Task>(response)`.
- The `response.tasks` fallback can go: the API `ListTasks` handler returns `items`.

## Open questions for the human (optional)
- `withPaging` would also remove the manual `encodeURIComponent`, but it owns the whole query string; adopting it here means building the filters after the paging params, so it can stay out of this PR.
Suggested change
const total = response.total_count ?? response.total;
return {
items: response.items || response.tasks || response.data || [],
nextCursor: response.next_cursor ?? null,
...(typeof total === "number" ? { total } : {}),
};
return toPage<Task>(response);

Comment on lines +73 to +88
function formatTaskSummary(task: Task): string {
const assignees =
task.assignee_ids && task.assignee_ids.length > 0
? task.assignee_ids.join(", ")
: "Unassigned";
return `Task #${task.task_number}: ${task.title}
ID: ${task.id}
Status: ${task.status_id || "None"}
Type: ${task.task_type_id || "None"}
Sprint: ${task.sprint_id || "None"}
Assignees: ${assignees}
Parent Task: ${task.parent_task_id || "None"}
Importance: ${task.importance}
Story Points: ${task.story_points ?? "None"}
Tags: ${task.tags && task.tags.length > 0 ? task.tags.join(", ") : "None"}
Due Date: ${task.due_date || "None"}`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

formatTaskSummary isn't formatTask minus the description: it also drops Start Date, Created and Updated, which are cheap fields and not what makes the page large. That's a second, unannounced change to list_tasks output. Consider giving formatTask a description option (or moving the summary beside it in utils/formatters.ts) so the two views can't drift on the fields the compact output is supposed to keep.

Technical details
# Keep compact and full task views in sync

## Affected sites
- `apps/mcp/src/tools/task-tools.ts:73-88` — `formatTaskSummary` (no `start_date`, `created_at`, `updated_at`)
- `apps/mcp/src/utils/formatters.ts:87-109` — `formatTask` (all fields plus description)
- `apps/mcp/src/tools/task-tools.ts:399-402` — selects between the two formatters

## Required outcome
- The compact list keeps the small fields `formatTask` shows and omits only the description, so `list_tasks` output differs from the previous format in exactly the way the PR body describes.
- One field list, one place to update.

## Suggested approach (optional)
- `formatTask(task, { includeDescription = true })` rendering `Description:` only when asked, and drop the local duplicate.

Comment on lines +141 to +145
includeDescription: {
type: "boolean",
description:
"Include full task descriptions (default false). The default compact summary keeps responses small so the pagination cursor is never truncated; use get_task for a task's full content.",
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This changes the default shape of a widely used tool and isn't recorded anywhere outside the schema: this repo logs behavioural changes in CHANGELOG.md under [Unreleased], and README.md:262 still tells readers that paged list replies end with the cursor line (no longer true for list_tasks). A short changelog bullet under Changed and a README tweak (list_tasks returns compact summaries and puts next_cursor before the list) would keep the docs honest.

@pikann pikann left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! Thank you for the contribution! 🚀

@pikann
pikann merged commit 8424cf4 into Paca-AI:master Nov 20, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] MCP list_tasks can make opaque pagination cursors unusable on large responses

3 participants