Skip to content

fix(mcp): preserve App pagination cursor bytes - #164368

Merged
obviyus merged 3 commits into
openclaw:mainfrom
ooiuuii:fix/mcp-app-cursors-164365
Oct 3, 2026
Merged

obviyus merged 3 commits into
openclaw:mainfrom
ooiuuii:fix/mcp-app-cursors-164365

Conversation

@ooiuuii

@ooiuuii ooiuuii commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Closes #164365

What Problem This Solves

MCP Apps can receive the first or wrong tools/resource-template page when a server returns an empty or whitespace-bearing continuation cursor. The UI bridge and App operation adapters dropped empty strings, and the Gateway parser trimmed opaque tokens.

User Impact

Apps can request the intended page using the server's exact token, including "" and " page 2 ". Absent cursors still request the first page; normal cursors, catalog discovery, resource aggregation, authorization and tool visibility filtering retain their behavior.

Why This Change Was Made

Preserve present string cursors in the existing forwarding path rather than introduce another paginator. The MCP pagination contract defines opaque string tokens without a nonempty requirement.

No dependency, configuration, permission, persistence or protocol-schema change. No packages/gateway-protocol files change. RPC method names and the optional string cursor wire shape are unchanged; only normalization/omission is removed.

Original report and fix by @ooiuuii. Contributor commits are preserved. Integrated main's intervening MCP authority and file-confirmation changes and supplied the current confirmation callback in the UI regression fixture. No overlap with Pash/Sarah changes.

Evidence

Built Gateway → real WebSocket → local stdio MCP server

Observed on baseline main 67ab6f3104fd5d5016c6fc8f6e1ff3edcb5e078f and candidate ff311f77ed36caa405abf91688a718f0898bc2e8, in an isolated Linux ARM64 Node 24.16.0 container. Built with pnpm build:docker; the candidate runtime rebuild reused unchanged declarations. The actual node openclaw.mjs --profile <isolated-profile> gateway run CLI started each Gateway. Its database-ownership command confirmed task-owned state before startup.

An authenticated WS client created isolated sessions, called mcp.app.discover and mcp.app.launch, then called the same mcp.app.listTools and mcp.app.listResourceTemplates RPCs used by the UI bridge. No Gateway handler, runtime, catalog, view lease or MCP transport was mocked or manually inserted. A local stdio MCP server advertised an App and four pages; it logged every received JSON-RPC request. Unknown/altered tokens return the first page.

Results apply to both list methods:

Requested cursor Baseline stub receives Baseline page Candidate stub receives Candidate page
absent absent first absent first
"" absent first (wrong) "" empty
" page 2 " "page 2" first (wrong) " page 2 " padded
"normal" "normal" normal "normal" normal

Exact candidate upstream trace excerpt, after App launch:

{"method":"tools/list","params":{"cursor":""}}
{"method":"resources/templates/list","params":{"cursor":""}}
{"method":"tools/list","params":{"cursor":" page 2 "}}
{"method":"resources/templates/list","params":{"cursor":" page 2 "}}

Candidate returned nextCursor: " page 2 " with page empty, and nextCursor: "normal" with page padded. Baseline omitted empty request cursors and transmitted "page 2" for padded requests, returning page first in both cases.

Controls compared from retained output: discovery returned the identical four App entrypoints on both versions; mcp.app.listResources returned both aggregated upstream resources and no next cursor. All 16 before/after page observations and both equality controls passed an independent check of the recorded output.

Regression RED → GREEN and standalone file cost

Each command used pnpm test <file> --maxWorkers=1, with isolated test state and real installed dependencies:

File Main with regression tests Candidate Process wall time, base → candidate
src/gateway/server-methods/mcp-app.test.ts 3 fail (empty, whitespace, padded), 47 pass 50 pass 21.78 s → 18.30 s
ui/src/components/mcp-app-bridge.cursor.test.ts fails: empty cursor becomes {} 1 pass 2.68 s → 2.15 s

Gateway Vitest durations: 19.17 s → 15.57 s; UI: 1.27 s → 0.949 s. These are standalone commands, not comparable performance benchmarks; Gateway compilation was cold for both. The UI test uses the installed App/AppBridge in-memory transport, not a mocked SDK.

Earlier contributor-head hosted evidence: CI run 37132655143, Gateway targeted shard 24.23 s; UI shard 170.56 s (includes 545 files, not this test's isolated cost). Fresh CI is required for the integrated head above; no CI jobs have been rerun.

Live smoke

Candidate made one real gpt-5-mini Responses request through a passive, one-call-capped proxy: reasoning.effort: "low", max_output_tokens: 4096, streamed response, HTTP 200, CLI exit 0, nonempty final model response. The response followed the fresh workspace onboarding prompt rather than the requested literal marker; this is a provider transport smoke, not an exact-text assertion. Proxy and task-only credential were removed afterward.

Limits

The complete real transport proof starts at the Gateway WS method used by the UI bridge; Chromium/iframe rendering was not exercised. The separate installed AppBridge regression covers browser-adapter cursor forwarding. Full local lint/typecheck and project-wide suites were not run; hosted CI owns those gates. Initial fixture startup/admission errors were corrected before the successful before/after proof and are not counted as reproductions.

@clawsweeper

clawsweeper Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime size: S labels Oct 3, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 3, 2026
@clawsweeper

clawsweeper Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 3, 2026, 7:26 PM ET / 23:26 UTC (Revision 3).

ClawSweeper review

What this changes

The PR preserves empty and whitespace-bearing MCP App pagination cursors through the UI bridge and Gateway, with regressions for exact token forwarding and returned pages.

Merge readiness

✅ Ready for maintainer review

The repair remains necessary on current main. The new transport evidence resolves the previous proof blocker, and inspection found no introduced correctness defect.

Priority: P2
Reviewed head: ff311f77ed36caa405abf91688a718f0898bc2e8

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with convincing production transport diagnostics and meaningful regressions; no actionable patch defect remains.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): The captured exact-head proof exercises the changed Gateway parser and App operations through authenticated WebSocket RPCs, real view launch, and real stdio MCP transport, showing byte-identical empty/padded cursors and correct returned pages. The installed AppBridge regression supplements coverage of the UI adapter; Chromium rendering is explicitly untested but does not block this forwarding-only repair. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (logs): The captured exact-head proof exercises the changed Gateway parser and App operations through authenticated WebSocket RPCs, real view launch, and real stdio MCP transport, showing byte-identical empty/padded cursors and correct returned pages. The installed AppBridge regression supplements coverage of the UI adapter; Chromium rendering is explicitly untested but does not block this forwarding-only repair. No stored-data contract changes.
Evidence reviewed 9 items Verified introduced repair: Read the pinned introduced diff and original production blobs. The changes replace truthiness-based omission with undefined checks and remove cursor trimming; existing authorization, tool visibility filtering, and complete resources/list aggregation remain intact.
Current main still needs the repair: Fetched main still trims and discards empty cursors in optionalCursor. Its App operations and UI bridge also retain the truthiness checks that omit empty strings.
Latest release remains affected: GitHub's v2026.9.8 source contains optionalCursor at line 32 and the same trimming/nonempty condition at line 34. This is not an already-shipped repair.
Findings None None.
Security None None.

How this fits together

MCP Apps are server-provided interactive views hosted by OpenClaw. Their tool and resource requests pass through the UI bridge and authenticated Gateway to the selected MCP server, then return filtered results to the App.

flowchart LR
  A[App pagination request] --> B[UI protocol bridge]
  B --> C[Authenticated Gateway]
  C --> D[Current view authorization]
  D --> E[Exact cursor forwarding]
  E --> F[Selected MCP server]
  F --> G[Filtered page and next cursor]
  G --> A
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +8, Tests +140. Total +148 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 14 6 +8
Tests 2 140 0 +140
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 154 6 +148

Review metrics

Metric Value Why it matters
Reported standalone regression cost Gateway 18.30 s; AppBridge 2.15 s The supplied single-worker measurements satisfy the earlier request for focused test-cost evidence.

Technical review

Best possible solution:

Keep one App forwarding path that preserves every present string cursor exactly while retaining current authorization, filtering, and resource aggregation.

Do we have a high-confidence way to reproduce the issue?

Yes: current-main source deterministically drops empty tokens and trims padded tokens on the App list path; the supplied before/after Gateway traces corroborate the failure. This reviewer did not execute a reproduction.

Is this the best way to solve the issue?

Yes: preserving the existing optional string parameter through all forwarding adapters is the narrow repair, and the shared catalog paginator serves a different aggregation contract.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 9b16ed050a69.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The captured exact-head proof exercises the changed Gateway parser and App operations through authenticated WebSocket RPCs, real view launch, and real stdio MCP transport, showing byte-identical empty/padded cursors and correct returned pages. The installed AppBridge regression supplements coverage of the UI adapter; Chromium rendering is explicitly untested but does not block this forwarding-only repair. No stored-data contract changes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): The captured exact-head proof exercises the changed Gateway parser and App operations through authenticated WebSocket RPCs, real view launch, and real stdio MCP transport, showing byte-identical empty/padded cursors and correct returned pages. The installed AppBridge regression supplements coverage of the UI adapter; Chromium rendering is explicitly untested but does not block this forwarding-only repair. No stored-data contract changes.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This fixes incorrect continuation pages for MCP Apps using empty or whitespace-bearing tokens, with limited blast radius.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): The captured exact-head proof exercises the changed Gateway parser and App operations through authenticated WebSocket RPCs, real view launch, and real stdio MCP transport, showing byte-identical empty/padded cursors and correct returned pages. The installed AppBridge regression supplements coverage of the UI adapter; Chromium rendering is explicitly untested but does not block this forwarding-only repair. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured exact-head proof exercises the changed Gateway parser and App operations through authenticated WebSocket RPCs, real view launch, and real stdio MCP transport, showing byte-identical empty/padded cursors and correct returned pages. The installed AppBridge regression supplements coverage of the UI adapter; Chromium rendering is explicitly untested but does not block this forwarding-only repair. No stored-data contract changes.

Evidence

What I checked:

  • Verified introduced repair: Read the pinned introduced diff and original production blobs. The changes replace truthiness-based omission with undefined checks and remove cursor trimming; existing authorization, tool visibility filtering, and complete resources/list aggregation remain intact. (src/gateway/mcp-app-operations.ts:494, ff311f77ed36)
  • Current main still needs the repair: Fetched main still trims and discards empty cursors in optionalCursor. Its App operations and UI bridge also retain the truthiness checks that omit empty strings. (src/gateway/server-methods/mcp-app.ts:79, 9b16ed050a69)
  • Latest release remains affected: GitHub's v2026.9.8 source contains optionalCursor at line 32 and the same trimming/nonempty condition at line 34. This is not an already-shipped repair. (src/gateway/server-methods/mcp-app.ts:34, fc23bc864e45)
  • Authoritative opaque-string contract: Verified repository identity through GitHub and inspected the pinned official schema. Cursor is an opaque string without a nonempty restriction, and nextCursor is an optional string. Dependency inspection applies because the production operation imports MCP request schemas and the added UI regression exercises installed MCP App/AppBridge contracts. (schema/2025-11-25/schema.json:830, c4c367f9f582)
  • After-fix production transport proof: The complete supplied PR body, captured with sourceRevision 11fa57bf58fa3c07ecd338ef49efa1ee817767877cda636022a76f62eb2eb76b, records baseline 67ab6f3 versus exact candidate ff311f7 in an isolated Linux ARM64 Node 24.16.0 container. An authenticated WebSocket client discovers and launches real App views, then invokes both production list RPCs through the built Gateway and real stdio MCP transport. Copied upstream JSON-RPC traces preserve empty and padded tokens; returned pages change from wrong first pages to the expected continuation pages. Absent/normal cursor, discovery, and resource-aggregation controls remain correct. Chromium rendering was not exercised; the unrelated provider smoke does not establish cursor correctness. (src/gateway/server-methods/mcp-app.ts:383, ff311f77ed36)
  • Prior review requests addressed: The previous review had no code findings and requested real cursor diagnostics plus standalone test costs. The new body supplies those diagnostics and reports Gateway regressions changing from three failures to 50 passes, and the installed AppBridge regression changing from an empty-cursor failure to a pass. Candidate standalone process wall times are 18.30 seconds and 2.15 seconds. The AppBridge test independently covers browser-adapter omission; Gateway coverage independently covers parser and operation forwarding. Neither adds a production test seam. Tests were inspected but not executed during this read-only review. (ui/src/components/mcp-app-bridge.cursor.test.ts:8, ff311f77ed36)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-03T15:21:15.782Z sha 7ed1aae :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-03T15:37:24.564Z sha 7ed1aae :: needs real behavior proof before merge. :: none

@obviyus

obviyus commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review: exact head ff311f7 now has built-Gateway real WebSocket-to-stdio-MCP before/after cursor traces, unchanged aggregation/discovery controls, failing-before/passing-after installed regressions with standalone single-worker timings, and one real provider smoke. Evidence and explicit browser-proof limit are in the updated PR body.

@clawsweeper

clawsweeper Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 3, 2026
@obviyus
obviyus merged commit 64772f5 into openclaw:main Oct 3, 2026
136 checks passed
@obviyus

obviyus commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator

Landed as 64772f5. Thanks @ooiuuii!

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 4, 2026
Fixes openclaw#164365.

MCP Apps received the first or wrong tools or resource-template page when a server returned an empty or whitespace-bearing continuation cursor, because the UI bridge and the Gateway trimmed or dropped it. Present string cursors now pass through the bridge, the Gateway parser and MCP app operations unchanged. The wire shape (an optional string cursor) is unchanged, with no gateway-protocol schema change. Absent and normal cursors, resource aggregation and catalog discovery are unchanged.

Proof: a built Gateway over authenticated WS, with a local stdio MCP App that paginates using `""` and padded cursors, dropped or trimmed them on base and returned the wrong page. With this change the exact bytes reached the server and the correct pages came back. The Gateway and installed AppBridge regression tests fail on base and pass here. A live gpt-5-mini smoke call passed.

Co-authored-by: Ayaan Zaidi <[email protected]>
@ooiuuii

ooiuuii commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for adding the built Gateway-to-MCP cursor traces and the confirmation fixture. The before/after calls and unchanged discovery controls make the forwarding behavior much easier to verify. I appreciate the extra validation and landing work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP App pagination drops empty cursors and trims opaque continuation tokens

2 participants