@shieldfive/mcp 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,200 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@shieldfive/mcp` will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## Unreleased
9
+
10
+ ## 0.2.0 - 2026-09-16
11
+
12
+ The first version published to npm. 0.1.0 below was tagged in this changelog
13
+ and never published; nothing depends on its behaviour, but its contract did
14
+ change here — a confirmed call now needs the `plan_token` its preview returned —
15
+ so the version moves a minor step rather than a patch, as semver asks of a 0.x
16
+ release that breaks callers.
17
+
18
+ Fixes from a second review before the first publish. Each item has a test that
19
+ failed before its fix.
20
+
21
+ ### Security
22
+
23
+ - A confirmed call was not bound to the preview the user approved. `confirm:
24
+ true` planned the operation again from scratch, so a directory that had grown,
25
+ a destination that had appeared, or a path that now pointed at a different file
26
+ was acted on without the user ever being shown it. Each preview now returns a
27
+ `plan_token`; a confirmed call must carry it, and the tool refuses
28
+ (`plan_changed`) when the plan it builds differs from the one approved, naming
29
+ what changed. Tokens are single use and expire after ten minutes.
30
+ - The trash directory was never resolved or `lstat`'d. With
31
+ `<root>/.shieldfive-mcp-trash` a symlink out of the root, `trash_local` and an
32
+ overwriting `move_local` moved the user's files and the manifest out of the
33
+ root. The directory is now checked while planning, created without following
34
+ links and checked again before anything moves in; a link or a non-directory
35
+ there is refused (`trash_unsafe`).
36
+ - A dangling symlink read as a free path. A move onto one previewed
37
+ `replaces_existing: false`; on the same device the link was replaced with no
38
+ trash entry, and across devices the copy wrote through it, outside the root,
39
+ before removing the source. At a destination it is now an existing entry, and
40
+ anywhere a write would pass through it the write is refused
41
+ (`dangling_symlink`).
42
+ - The cross-device move fallback deleted data. It `rm -rf`'d whatever was at
43
+ `<destination>.shieldfive-mcp-incoming`, dropped FIFOs, sockets and device
44
+ files and then removed the source tree, and removed a file's source without
45
+ flushing or checking the copy. A cross-device move now copies under a fresh,
46
+ exclusively created name, refuses symlinks and special files in the tree
47
+ (`symlink_in_tree`, `special_file_in_tree`), flushes and verifies every file by
48
+ size and SHA-256 against a source that has not changed
49
+ (`copy_verification_failed`, `source_changed`), and removes the source entry by
50
+ entry, only what is unchanged since it was copied (`source_left_in_place`).
51
+ - The trash lived per root rather than per volume, so for a root such as
52
+ `/Volumes`, trashing from an external drive copied the tree onto the boot
53
+ volume. An item's trash is now on its own volume, in the highest directory
54
+ between it and its root on that device; a move into the trash is always a
55
+ rename; a mount point cannot be trashed (`trash_no_same_volume`).
56
+ - `trash_local` on a symlink trashed the tree it pointed to, and `rename_local`
57
+ renamed the file behind a link. `move_local`, `rename_local` and `trash_local`
58
+ now act on a link itself, never on its target.
59
+ - `rename_local`'s "never replaces" was a check followed by `rename(2)`. Renames
60
+ and moves now use operations that fail when the destination exists: a hard link
61
+ then an unlink for files, a recreated symlink, a rename over an empty
62
+ placeholder for directories. Special files, filesystems without hard links and
63
+ directories on Windows still fall back to checking and then renaming;
64
+ SECURITY.md records the window that leaves.
65
+
66
+ ### Fixed
67
+
68
+ - `find_duplicates` spent its hashing budget all-or-nothing per size group, so
69
+ the most valuable group was skipped when its worst case did not fit and the
70
+ smaller groups behind it were hashed instead. The budget is now spent per file,
71
+ largest group first, hashing a group in part when it must
72
+ (`groups_partially_hashed`, `files_not_hashed`).
73
+ - The copy nominated to keep was chosen by modification time, with ties left to
74
+ directory order. A tie now goes to the shorter path, then to the path in
75
+ code-unit order (`compareKeeper`).
76
+ - Hardlinks counted as reclaimable space. Names of one file are now one copy,
77
+ listed under `hardlinked_names`, and `reclaimable_bytes` counts files on disk.
78
+ - A trash batch that failed after moving something could report the moved item
79
+ as recorded "in no manifest (nothing moved)", and the structured detail never
80
+ reached the client. The error now names each moved item and its manifest, and
81
+ the detail is returned as a second content block.
82
+ - Manifest updates raced: concurrent calls in the same millisecond shared a batch
83
+ and lost entries, and a corrupt manifest was silently reset. Each call now has
84
+ its own exclusively created batch directory; its manifest is written before
85
+ anything moves, atomically and one write at a time, and no manifest this
86
+ server did not write is read or replaced.
87
+ - Path arguments and `new_name` were trimmed, so `"report "` acted on
88
+ `"report"`. They are used exactly as given.
89
+ - `limit`, `max_files`, `max_files_hashed`, `paths` and `new_name` had no upper
90
+ bound, and a refusal echoed its input whole. They are capped — 10,000 rows;
91
+ 1,000,000 files; 1,000,000 hash reads; 1,000 paths; 255 bytes — at the MCP
92
+ schema and again in the handlers, and echoed values are cut short.
93
+ - `trash_local` counted a path given twice twice, and given a folder and
94
+ something inside it, moved the folder and then failed on the file. A repeated
95
+ path is taken once and an overlap is refused before anything moves
96
+ (`overlapping_paths`).
97
+ - The mutating tools ignored cancellation. Nothing starts once a request is
98
+ cancelled (`cancelled`); a trash batch stops between items
99
+ (`cancelled_partially_applied`); a move is rolled back until its source starts
100
+ being removed. The SDK sends no response to a cancelled request, so the server
101
+ logs what happened.
102
+ - `scanned` listed roots the file budget never reached. Payloads carry
103
+ `scanned` and `not_scanned`, and the warning names the roots never reached.
104
+
105
+ ### Changed
106
+
107
+ - A symlink given as the destination of `move_local` is an entry that
108
+ `overwrite` can replace, not a directory to move into. Give the real path of a
109
+ directory to move into it.
110
+ - The server version is read from `package.json` rather than kept as a second
111
+ copy.
112
+ - The README said scans stop at "64 directory levels"; they walk the root and
113
+ 64 levels of subdirectories below it.
114
+ - Removed a scratch script committed at the repository root, a `.npmrc` and
115
+ `.gitignore` entries left over from other projects, and renamed a test whose
116
+ name contradicted its assertion.
117
+
118
+ ### Not covered
119
+
120
+ - The cross-device tests need a RAM disk and run only on macOS; elsewhere they
121
+ are skipped, visibly. Windows remains untested.
122
+
123
+ ## 0.1.0 - 2026-09-14
124
+
125
+ Initial release.
126
+
127
+ ### Added
128
+
129
+ - Nine local file-management tools over MCP stdio: `list_local`,
130
+ `find_duplicates`, `find_large_files`, `find_old_files`, `storage_summary`,
131
+ `move_local`, `rename_local`, `create_local_folder`, `trash_local`.
132
+ - Root-based containment. Every path is `realpath`-resolved, following symlinks,
133
+ and must land inside a directory the user named at startup. No default root,
134
+ no override.
135
+ - Content-based duplicate detection: grouped by size, then by a hash of the
136
+ first 64 KiB, then confirmed by a full SHA-256. Filenames are never used to
137
+ decide identity.
138
+ - `confirm: true` gating on every tool that changes the filesystem. Without it,
139
+ each returns the plan its real code path produced and changes nothing.
140
+ - `trash_local` moves rather than deletes, into a `.shieldfive-mcp-trash`
141
+ directory inside the item's own root, with a `manifest.json` recording the
142
+ original location.
143
+
144
+ ### Security
145
+
146
+ - Path containment was attacked across four independent lenses before release.
147
+ Two data-loss paths in `move_local` were found and closed: an overwriting move
148
+ called `rm(destination, {recursive: true, force: true})`, which destroyed every
149
+ file under an overwritten directory while the README claimed the server deletes
150
+ nothing; and a directory moved onto its own parent resolved its final path to
151
+ the source itself, so the same branch deleted the source outright. Overwriting
152
+ now moves the displaced item to the trash, and the self-move case is refused.
153
+ - `walkRoots` threw `RangeError` on any root over roughly 125,000 files — below
154
+ the 200,000-file cap the schema advertises — because it spread the per-root
155
+ array into `push()`. It appends in a loop, and `max_files` is now a budget
156
+ across all roots rather than per root.
157
+ - The hidden-entry check ran on the dirent before `lstat`, so a dot-named symlink
158
+ was counted as hidden and never reached the symlink branch.
159
+ - Files with a link count above one are counted and reported in scan warnings.
160
+ `realpath` resolves symlinks but not hardlinks, so containment cannot see a
161
+ second name for the same inode outside the roots.
162
+ - Request cancellation is plumbed through to the walk and to hashing. A cancelled
163
+ scan previously ran to completion.
164
+ - A cross-device directory move is transactional. It stages the copy beside the
165
+ target and renames it into place only once the whole tree has landed, so a
166
+ failure mid-walk leaves the source untouched and nothing at the destination.
167
+ Previously an interleaved copy+remove tore the source in half while the
168
+ already-removed destination was gone for good. A move that would both displace
169
+ an existing destination and carry a symlink in its tree is now refused before
170
+ anything is displaced, and if the replacement fails after a displacement the
171
+ displaced item is put back.
172
+ - Path arguments are capped at 4096 characters. An oversized path was reflected
173
+ verbatim into the error message and into the model's context.
174
+
175
+ ### Notes
176
+
177
+ - **This version cannot see a ShieldFive vault.** The vault API accepts only a
178
+ full account JWT, which also opens the wrapped-root-key route and every
179
+ content download, and cannot be scoped down. Holding one would make the
180
+ content boundary a matter of restraint instead of capability. Vault tools wait
181
+ for a scoped, metadata-only key. The reasoning is set out in
182
+ `docs/mcp-v1-step0-discovery.md` in `shieldfive/web`.
183
+ - No network module is imported, `fetch` is never called, no subprocess is
184
+ spawned, and `SHIELDFIVE_MCP_ROOTS` is the only environment variable read.
185
+ Each of those is asserted by a test rather than only claimed here. The
186
+ assertion covers this package's source, not its dependency tree, and
187
+ SECURITY.md says so.
188
+ - Reporting was corrected in several places where a result was quietly
189
+ incomplete: `storage_summary` omitted hidden files and build directories from
190
+ its totals with no warning at all; `find_old_files` was the one tool that kept
191
+ its warnings out of the summary line; the duplicate-hashing budget counted only
192
+ the 64 KiB head pass, leaving the whole-file pass unbounded, and abandoned
193
+ entire same-size groups when they did not fit — biased against the groups worth
194
+ the most, since a group is large precisely because it has many copies.
195
+ - `formatBytes` promoted units before rounding, so 999,999 bytes rendered as
196
+ "1000 KB".
197
+ - `storage_summary` credited each file only to its immediate parent, so a large
198
+ tree split across subfolders never appeared in `largest_directories`.
199
+ - Windows is untested. The code uses no POSIX-only API and paths go through
200
+ `node:path`, but nobody has run it there.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Cho Garcia
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
200
+ implied. See the License for the specific language governing permissions and
201
+ limitations under the License.