Skip to content

[Routine - QP] fix: guard against non-array JSON in MCP clipboard history load#47

Draft
winterdrive wants to merge 1 commit into
masterfrom
routine/qp-fix-mcp-clipboard-non-array-260706
Draft

[Routine - QP] fix: guard against non-array JSON in MCP clipboard history load#47
winterdrive wants to merge 1 commit into
masterfrom
routine/qp-fix-mcp-clipboard-non-array-260706

Conversation

@winterdrive

Copy link
Copy Markdown
Owner

1. Pre-flight Check

Open PRs / active routine branches checked before starting:

Also reviewed several closed-but-not-merged routine/qp-fix-* branches (e.g. qp-fix-corrupted-clipboard-json-260626 / PR #34) to understand prior work in this area — that one guarded src/ClipboardManager.ts against non-array JSON, but the equivalent gap in the MCP server's clipboard tool (mcp-server/src/tools/clipboardTools.ts) was never fixed and that PR is closed.

This PR only touches mcp-server/src/tools/clipboardTools.ts, which is not modified by any of the above — no overlap.

2. Changes

ClipboardTools.loadHistory() cast JSON.parse(data) straight to ClipboardHistoryItem[] with no shape check. If ~/.quickprompt/clipboard-history.json is valid JSON but not an array (e.g. corrupted to {} or null), the object masquerades as an array downstream in getClipboardItem(): history.length becomes undefined, bounds checks against NaN always pass, and the code falls through to history[targetIndex].content, throwing an unhandled-shape TypeError that surfaces as a raw internal error message to the MCP client.

Fix: parse into unknown first and fall back to [] when the result isn't an array, matching the existing guard already used in src/ClipboardManager.ts.

  • Does not modify any tool schema, name, or parameters in mcp-server/src/tools/.
  • Does not add/remove/update any dependency.
  • Does not touch package.json, package-lock.json, or CHANGELOG.md.

3. Safety Verification

Commands run locally, all passed:

  • npx tsc -p ./ — no errors
  • npm run test (jest --runInBand) — 7 suites / 107 tests passed

4. CI / Release Gate Note

This is a daily routine Draft PR. Package version bump and CHANGELOG consolidation are intentionally deferred to the weekend release/integration PR. If CI fails only due to the repo's version-bump release gate, that is expected release-readiness behavior for a routine PR, not a code validation failure.

🤖 Generated with Claude Code

ClipboardTools.loadHistory() cast parsed JSON directly to
ClipboardHistoryItem[] without checking it was actually an array,
so a corrupted or unexpectedly-shaped clipboard-history.json (e.g.
`{}` or `null`) would silently produce an object masquerading as
an array, leading to NaN bounds checks and a leaked internal error
message in getClipboardItem. Mirrors the existing array guard
already used in src/ClipboardManager.ts.
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.

1 participant