Repository navigation
fix(tui): delete copy-to-file temp files when the TUI exits - #2692
Merged
Merged
Conversation
The W fallback writes the copied value (possibly an access token) to $TMPDIR/mcp-inspector-copy-*/value.txt and never removed it. Track every directory writeCopyFile creates and remove them synchronously from a process exit listener; every TUI exit path ends in process.exit. The status line now says the file is deleted on exit, and the README notes it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
There was a problem hiding this comment.
🟢 Approval recommended
The cleanup is correctly scoped, synchronous at exit, resilient to failures, and adequately tested.
0 open findings
What changed in this PR
Ensures sensitive TUI copy-fallback files are removed on process exit and clearly communicates their temporary lifetime.
Changes:
- Tracks and synchronously removes generated copy directories at exit.
- Updates status messaging and documentation.
- Adds cleanup and failure-path tests.
| File | Description |
|---|---|
clients/tui/src/utils/clipboard.ts |
Adds best-effort exit cleanup. |
clients/tui/src/hooks/useCopyKeys.ts |
Clarifies temporary-file status. |
clients/tui/README.md |
Documents cleanup behavior. |
clients/tui/__tests__/useCopyKeys.test.tsx |
Verifies updated status text. |
clients/tui/__tests__/clipboard.test.ts |
Tests cleanup and failure handling. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Member
Author
|
Copilot review loop closed: round 1 was clean (0 findings, no inline or suppressed comments), so no further round was requested. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2648
Problem
The TUI's OSC 52 fallback (
W, #2421) writes the copied value to$TMPDIR/mcp-inspector-copy-XXXXXX/value.txtand never removed it. On the Auth tab that value is the full access token, so tokens accumulated in the temp directory until the OS cleaned it.Change
clients/tui/src/utils/clipboard.ts:writeCopyFilerecords each directory it creates (before writing, so a failed write still gets cleaned up) and, on first use, registers a singleprocess.on("exit", removeCopyFiles)listener.removeCopyFilesremoves them synchronously and best-effort — one failing directory doesn't stop the rest or crash the exit. Every way out of the TUI ends inprocess.exit(tui.tsxcalls it after Ink unmounts), so this covers Esc and Ctrl+C. A kill by an unhandled signal still skipsexitlisteners; the file stays in its0700directory with mode0600, as before.useCopyKeys: the status line now says the file is temporary —Saved access token to …/value.txt (deleted when the TUI exits)— so the user knows to copy it elsewhere if they want to keep it.clients/tui/README.md: documents the same.Verification
useCopyKeystest asserts the new status text.writeCopyFilefollowed byprocess.exit(0)printed the path, and that directory no longer existed afterward.npm run local:gatepassed.No screenshot: the only UI change is the status-line text quoted above.
🤖 Generated with Claude Code