@t2nagi/filebrowser-quantum-mcp 0.0.0-stage → 0.1.0-rc.1

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.
Files changed (49) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +21 -0
  3. package/README.ja.md +335 -0
  4. package/README.md +328 -2
  5. package/dist/client/api.js +222 -0
  6. package/dist/client/errors.js +120 -0
  7. package/dist/client/http.js +172 -0
  8. package/dist/client/types.js +2 -0
  9. package/dist/config.js +168 -0
  10. package/dist/core/approvals.js +75 -0
  11. package/dist/core/confirm.js +66 -0
  12. package/dist/core/content.js +28 -0
  13. package/dist/core/display.js +65 -0
  14. package/dist/core/inspect.js +180 -0
  15. package/dist/core/lock.js +54 -0
  16. package/dist/core/messages.js +131 -0
  17. package/dist/core/names.js +114 -0
  18. package/dist/core/paths.js +41 -0
  19. package/dist/core/reads.js +39 -0
  20. package/dist/core/recovery.js +55 -0
  21. package/dist/core/replace.js +131 -0
  22. package/dist/core/shares.js +46 -0
  23. package/dist/core/sources.js +18 -0
  24. package/dist/core/state.js +154 -0
  25. package/dist/core/text.js +44 -0
  26. package/dist/core/writeflow.js +497 -0
  27. package/dist/index.js +83 -0
  28. package/dist/log.js +32 -0
  29. package/dist/server.js +117 -0
  30. package/dist/tools/archive.js +159 -0
  31. package/dist/tools/common.js +68 -0
  32. package/dist/tools/create-folder.js +94 -0
  33. package/dist/tools/delete.js +195 -0
  34. package/dist/tools/find-duplicates.js +59 -0
  35. package/dist/tools/get-info.js +53 -0
  36. package/dist/tools/index.js +45 -0
  37. package/dist/tools/list-dir.js +68 -0
  38. package/dist/tools/list-sources.js +45 -0
  39. package/dist/tools/move-copy.js +231 -0
  40. package/dist/tools/read-file.js +69 -0
  41. package/dist/tools/rename.js +99 -0
  42. package/dist/tools/search.js +93 -0
  43. package/dist/tools/shares.js +219 -0
  44. package/dist/tools/unarchive.js +147 -0
  45. package/dist/tools/write-common.js +89 -0
  46. package/dist/tools/write-file.js +160 -0
  47. package/dist/version.js +5 -0
  48. package/npm-shrinkwrap.json +2657 -0
  49. package/package.json +57 -4
package/README.md CHANGED
@@ -1,3 +1,329 @@
1
- # Temporary Holding Version
1
+ # filebrowser-quantum-mcp
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **English** | [日本語](README.ja.md)
4
+
5
+ > **Unofficial.** This project is not affiliated with or endorsed by the FileBrowser Quantum project.
6
+
7
+ An **MCP (Model Context Protocol) server** that lets AI agents such as Claude browse, search, and manage files on a [FileBrowser Quantum](https://filebrowserquantum.com/) server.
8
+
9
+ > **Use at your own risk.** This server lets an AI assistant change and delete files. It is provided "as is", without warranty, and the authors are not liable for any data loss or damage. Back up your data and read the [Disclaimer](#disclaimer) before use.
10
+
11
+ > **Status: release candidate.** `0.1.0-rc.1` is published for testing (npm dist-tag `next`, image tag `0.1.0-rc.1`). The examples below use `0.1.0`, which is not released yet: until then, use `0.1.0-rc.1` in their place (`@0.1.0-rc.1`, `:0.1.0-rc.1`) or [run it from source](#running-from-source-before-a-release-is-published).
12
+
13
+ ---
14
+
15
+ ## Features
16
+
17
+ - List sources (storage backends registered in FileBrowser) and directories
18
+ - Get file and folder metadata, and read text files
19
+ - Search files using the server index
20
+ - Create, write, move, copy, rename, and delete files and folders
21
+ - Create and extract archives on the server (zip / tar.gz)
22
+ - List, create, and delete share links
23
+ - Find duplicate files
24
+ - Safe by default: nothing is overwritten or deleted without your confirmation in a prompt, delete and share tools are off unless you enable them, and a read-only mode is available
25
+
26
+ ---
27
+
28
+ ## Compatibility
29
+
30
+ filebrowser-quantum-mcp follows its own [Semantic Versioning](https://semver.org/), independent of FileBrowser Quantum's version numbers. Breaking changes are signaled by the major version: renaming or removing tools, arguments, or output fields, changing environment variables, and changing safety-related defaults. While in `0.x`, minor releases may contain breaking changes. The full rules are in [docs/release.md](docs/release.md) (in Japanese).
31
+
32
+ | filebrowser-quantum-mcp | FileBrowser Quantum | Tested with |
33
+ |---|---|---|
34
+ | 0.1.x | 2.1.x | v2.1.0-stable |
35
+
36
+ Only the latest stable line of FileBrowser Quantum is supported. The supported range is also declared in `package.json` as `filebrowserCompat`. The server does not check the FileBrowser version at runtime, because FileBrowser does not report it through the API.
37
+
38
+ ---
39
+
40
+ ## Setup
41
+
42
+ ### 1. Create an API token
43
+
44
+ 1. As an admin, create a **non-admin** user for MCP in FileBrowser's user management, with only the permissions it needs. In the user's global permissions, turn on **API** (and **Share** if you want the share tools) and leave **Admin** off. Without the API permission the user cannot create tokens: *API Management* is not available to them. Limit its scope to a directory you are happy to let the assistant touch, and keep that directory out of anything served on the web or synced elsewhere. The server refuses to start with an admin user's token, because an admin token can see every user's share links and all of that user's other tokens.
45
+ 2. Sign out, sign in as that user, and create a token in **Settings → API Management**. Give the token the `api` permission (`api` and `share` for the share tools). Do not create a *minimal* token: it carries every permission the user has.
46
+
47
+ What the MCP server can do is limited by that user's per-source permissions (`view` / `download` / `modify` / `create` / `delete`) and by the token's permissions.
48
+
49
+ ### 2. Configure your MCP client
50
+
51
+ filebrowser-quantum-mcp runs locally over stdio. You can start it with `npx` (requires Node.js 24+) or with Docker.
52
+
53
+ **npx**
54
+
55
+ ```json
56
+ {
57
+ "mcpServers": {
58
+ "filebrowser": {
59
+ "command": "npx",
60
+ "args": ["-y", "@t2nagi/filebrowser-quantum-mcp@0.1.0"],
61
+ "env": {
62
+ "npm_config_ignore_scripts": "true",
63
+ "FILEBROWSER_URL": "https://files.example.com",
64
+ "FILEBROWSER_TOKEN": "<your-api-token>",
65
+ "FILEBROWSER_READ_ONLY": "true"
66
+ }
67
+ }
68
+ }
69
+ }
70
+ ```
71
+
72
+ **Docker**
73
+
74
+ ```json
75
+ {
76
+ "mcpServers": {
77
+ "filebrowser": {
78
+ "command": "docker",
79
+ "args": [
80
+ "run", "-i", "--rm",
81
+ "-e", "FILEBROWSER_URL",
82
+ "-e", "FILEBROWSER_TOKEN",
83
+ "-e", "FILEBROWSER_READ_ONLY",
84
+ "ghcr.io/t2nagi/filebrowser-quantum-mcp:0.1.0"
85
+ ],
86
+ "env": {
87
+ "FILEBROWSER_URL": "https://files.example.com",
88
+ "FILEBROWSER_TOKEN": "<your-api-token>",
89
+ "FILEBROWSER_READ_ONLY": "true"
90
+ }
91
+ }
92
+ }
93
+ }
94
+ ```
95
+
96
+ Pass each environment variable you use with `-e NAME` (the name only) and put the values in `env`. This keeps the token out of the command line, where other processes could see it. Use `-i` and do not add `-t`; a TTY breaks the stdio protocol.
97
+
98
+ The examples above are read-only. To let the assistant write and delete, drop `FILEBROWSER_READ_ONLY` and turn on what you need. With Docker, every variable must appear twice: as `-e NAME` in `args` and with its value in `env`; a variable listed in only one place does not reach the server.
99
+
100
+ ```json
101
+ "args": [
102
+ "run", "-i", "--rm",
103
+ "-e", "FILEBROWSER_URL",
104
+ "-e", "FILEBROWSER_TOKEN",
105
+ "-e", "FILEBROWSER_WRITABLE_SOURCES",
106
+ "-e", "FILEBROWSER_ALLOW_DELETE",
107
+ "ghcr.io/t2nagi/filebrowser-quantum-mcp:0.1.0"
108
+ ],
109
+ "env": {
110
+ "FILEBROWSER_URL": "https://files.example.com",
111
+ "FILEBROWSER_TOKEN": "<your-api-token>",
112
+ "FILEBROWSER_WRITABLE_SOURCES": "<source-name>",
113
+ "FILEBROWSER_ALLOW_DELETE": "true"
114
+ }
115
+ ```
116
+
117
+ Always pin a version as in the examples above (`@0.1.0`, `:0.1.0`, or an image digest) instead of running the latest release automatically. Releases are built and published only by the [release workflow](.github/workflows/release.yml) on GitHub Actions: the npm package includes an `npm-shrinkwrap.json` so that its dependencies are pinned too, and is published with npm provenance; the image is multi-architecture (`linux/amd64`, `linux/arm64`), signed with cosign, and carries an SBOM. `npm_config_ignore_scripts` keeps install scripts from running while your token is in the environment.
118
+
119
+ To check that an image was built by this repository's release workflow, verify its signature with [cosign](https://docs.sigstore.dev/):
120
+
121
+ ```bash
122
+ cosign verify ghcr.io/t2nagi/filebrowser-quantum-mcp:0.1.0 --certificate-oidc-issuer https://token.actions.githubusercontent.com --certificate-identity-regexp '^https://github\.com/t2nagi/filebrowser-quantum-mcp/\.github/workflows/release\.yml@refs/tags/v'
123
+ ```
124
+
125
+ ### Running from source (before a release is published)
126
+
127
+ Until the npm package and the image are published, build it from this repository.
128
+
129
+ **Docker** (no Node.js needed on the host):
130
+
131
+ ```bash
132
+ git clone https://github.com/t2nagi/filebrowser-quantum-mcp.git
133
+ cd filebrowser-quantum-mcp
134
+ docker build -t filebrowser-quantum-mcp:dev .
135
+ ```
136
+
137
+ Then use the Docker configuration above with the image `filebrowser-quantum-mcp:dev` instead of `ghcr.io/t2nagi/filebrowser-quantum-mcp:0.1.0`. Rebuild the image after pulling new commits.
138
+
139
+ **Node.js 24+**:
140
+
141
+ ```bash
142
+ git clone https://github.com/t2nagi/filebrowser-quantum-mcp.git
143
+ cd filebrowser-quantum-mcp
144
+ npm ci --ignore-scripts
145
+ npm run build
146
+ ```
147
+
148
+ Then set `"command": "node"` and `"args": ["/absolute/path/to/filebrowser-quantum-mcp/dist/index.js"]`, with the same `env` as above. If your client cannot find `node` or `docker`, use the absolute path (`which node`, `which docker`).
149
+
150
+ ### Environment variables
151
+
152
+ | Variable | Required | Default | Description |
153
+ |---|---|---|---|
154
+ | `FILEBROWSER_URL` | ✓ | — | Base URL of FileBrowser (e.g. `https://files.example.com`, or with a subpath such as `https://example.com/files`). Plain `http://` is refused unless the host is `localhost`, `127.0.0.1`, `[::1]`, or listed in `FILEBROWSER_ALLOW_INSECURE_HTTP_HOSTS`. Redirects are not followed, so use the final API address |
155
+ | `FILEBROWSER_TOKEN` | ✓ | — | API token of a non-admin user |
156
+ | `FILEBROWSER_DEFAULT_SOURCE` | | — | Source used when a tool call omits `source`. If unset and you can access exactly one source, that source is used |
157
+ | `FILEBROWSER_READ_ONLY` | | `false` | When `true`, only read tools are available. Takes precedence over the two settings below |
158
+ | `FILEBROWSER_ALLOW_DELETE` | | `false` | Delete tools are available only when `true` |
159
+ | `FILEBROWSER_ALLOW_SHARE` | | `false` | Share tools (listing, creating, and deleting share links) are available only when `true` |
160
+ | `FILEBROWSER_ALLOW_FOLDER_SHARE` | | `false` | Allow share links for folders. Off by default because hidden files inside a shared folder (such as `.env`) can be fetched by anyone who knows their path |
161
+ | `FILEBROWSER_MAX_READ_BYTES` | | `65536` (64 KiB) | Maximum bytes `fb_read_file` returns per call. Read the rest with `offset` |
162
+ | `FILEBROWSER_MAX_WRITE_BYTES` | | `1048576` (1 MiB) | Maximum bytes accepted by `fb_write_file` |
163
+ | `FILEBROWSER_TIMEOUT_MS` | | `30000` | Request timeout in milliseconds |
164
+ | `FILEBROWSER_LONG_TIMEOUT_MS` | | `300000` | Timeout for move, copy, rename, archive, extract, and duplicate search |
165
+ | `FILEBROWSER_LOG_LEVEL` | | `warn` | `error`, `warn`, `info`, or `debug`. Logs go to stderr |
166
+ | `FILEBROWSER_LANG` | | `en` | Language of confirmation prompts: `en` or `ja` |
167
+ | `FILEBROWSER_CONFIRM_POLICY` | | `strict` | Either `strict` or `trust-client`. How operations that can lose data (overwrite, delete) or send files elsewhere are confirmed. `strict`: only after you confirm in a prompt; clients without prompt support can never overwrite or delete. `trust-client`: on clients that do not support prompts, run after a two-step approval instead (see below) and rely on your client's own tool approval (**risk of data loss**). It has no effect on clients that support prompts. Share links always need a prompt either way |
168
+ | `FILEBROWSER_ELICITATION` | | `auto` | Either `auto` or `off`. `auto`: use confirmation prompts when the client says it supports them. `off`: never use prompts, as if the client did not support them. Only for clients that claim prompt support but never show the prompt. **Read the caution below before setting `off`** |
169
+ | `FILEBROWSER_CONFIRM_TIMEOUT_MS` | | `300000` | How long to wait for your answer to a confirmation prompt before cancelling |
170
+ | `FILEBROWSER_MAX_SHARE_DAYS` | | `7` | Longest allowed share link expiry, in days |
171
+ | `FILEBROWSER_ALLOWED_SOURCES` | | — | Comma-separated list of sources the server may use. Unset means every source the user can access |
172
+ | `FILEBROWSER_WRITABLE_SOURCES` | | — | Comma-separated list of sources the server may write to. Unset means the same as `FILEBROWSER_ALLOWED_SOURCES` |
173
+ | `FILEBROWSER_ALLOW_ADMIN_USER` | | `false` | Start even with an admin user's token (not recommended) |
174
+ | `FILEBROWSER_ALLOW_INSECURE_HTTP_HOSTS` | | — | Comma-separated host names that may be reached over plain `http://`. The token and file contents are sent unencrypted |
175
+
176
+ Boolean values accept `true` / `false` / `1` / `0` / `yes` / `no`. An invalid value (for example `FILEBROWSER_CONFIRM_POLICY=client`) stops the server at startup; the reason is in your MCP client's server log.
177
+
178
+ > [!CAUTION]
179
+ > **`FILEBROWSER_ELICITATION=off` together with `FILEBROWSER_CONFIRM_POLICY=trust-client` removes every confirmation prompt.**
180
+ >
181
+ > - Overwrites, deletions, and writes to other sources or shared folders use a **two-step approval** instead: the first call changes nothing and returns the list of changes with a one-time `approvalCode`; only a second call with that code runs. The assistant is told to show you the list and wait for your "yes" in the chat, but **the server cannot check that you approved**: in testing, an assistant deleted without asking. Deleted files cannot be recovered: FileBrowser has no trash.
182
+ > - The only thing left between the assistant and your data is your MCP client's own tool approval. **Never set the write and delete tools to be approved automatically** ("always allow", auto-approve modes, agent hooks).
183
+ > - A file the assistant reads can contain instructions written by someone else. With the prompts gone, read every tool approval request before you accept it.
184
+ > - Use it only on test data or data you have backed up, and remove both settings as soon as you no longer need them.
185
+ >
186
+ > Prefer a client that shows the prompts (for example Claude Code in the terminal). With `off` and the default `strict`, nothing is lost: overwriting, deleting, and share links are simply refused.
187
+
188
+ For a server with a self-signed certificate, add the CA with `NODE_EXTRA_CA_CERTS`. Do not disable certificate checks with `NODE_TLS_REJECT_UNAUTHORIZED=0`.
189
+
190
+ At startup, the server writes one line to stderr with the enabled write features and a reminder that it comes without warranty. It also writes a warning for each risky setting in use, such as `FILEBROWSER_ALLOW_DELETE`, `FILEBROWSER_ALLOW_SHARE`, `FILEBROWSER_ALLOW_FOLDER_SHARE`, or `FILEBROWSER_CONFIRM_POLICY=trust-client`. Check your MCP client's server log after changing settings. These lines are hidden only when `FILEBROWSER_LOG_LEVEL=error`. The combination of `FILEBROWSER_ELICITATION=off` and `trust-client` is reported as an error-level line starting with `!!! DANGER`, which is never hidden.
191
+
192
+ ### Troubleshooting
193
+
194
+ - **The server does not start, or the client cannot connect to it.** Look at the MCP server log in your client. A message such as `FILEBROWSER_CONFIRM_POLICY must be one of strict, trust-client` names the setting to fix.
195
+ - **"The startup checks against FileBrowser have not passed yet".** The server cannot reach FileBrowser. Check `FILEBROWSER_URL` and that FileBrowser is running. With Docker, a host name that only your local DNS knows may not resolve inside the container (`ENOTFOUND` in `details.cause`); add `"--add-host", "<host>:<ip-address>"` to `args`.
196
+ - **"The API token belongs to an admin user".** Create a token for a non-admin user (see [Setup](#1-create-an-api-token)).
197
+ - **Every overwrite or delete is cancelled although you saw no prompt.** Your client claims to support prompts but does not show them. Use a client that shows them; see the client notes in [Limitations](#limitations). `FILEBROWSER_ELICITATION=off` is a last resort: read the caution under [Environment variables](#environment-variables) first.
198
+
199
+ ---
200
+
201
+ ## Tools
202
+
203
+ Tools take a `source` (see `FILEBROWSER_DEFAULT_SOURCE`) and a `path`, an absolute path within the source such as `/docs/readme.md`. Tools that write somewhere new take `toSource` and `toPath` for the destination. Use `fb_list_sources` to see which sources you can access and write to.
204
+
205
+ **Name rules.** New file and folder names must be valid on Windows, macOS, and Linux alike. These are rejected:
206
+
207
+ - names containing `< > : " / \ | ? *`, control characters, or invisible characters that can disguise a name (bidirectional controls, zero-width characters, and similar; the full-width space U+3000 is allowed)
208
+ - Windows device names such as `CON` or `nul.txt`
209
+ - names ending with a space or a dot, and names longer than 255 bytes
210
+ - names that differ from an existing one only by letter case
211
+
212
+ New names are normalized to Unicode NFC. Existing files with other names can still be read, moved, and deleted.
213
+
214
+ **Confirmation before data loss.** Nothing is overwritten or deleted unless you confirm it in a prompt.
215
+
216
+ - When a destination already exists and your MCP client supports *elicitation*, the server asks you to choose **cancel**, **rename** (save with a new name such as `report(1).txt`), or **overwrite**. Cancel is listed first and marked as the default, so clients that preselect an option land on it. The prompt shows the size and modified time of the existing item and of what replaces it (for new text, its size), and warns you if the new content is much smaller or if the assistant has not read the whole file.
217
+ - If the assistant asks for `onConflict: "rename"`, the file is saved under a new name without a prompt, since nothing is lost.
218
+ - Deleting (`fb_delete`) shows a prompt (with the default `strict` policy; see below for `trust-client`). Hidden files inside a deleted folder are removed too, and FileBrowser has no trash, so deletion cannot be undone.
219
+ - Overwrites never leave a half-written file in place. Writing, copying, and archiving go to a temporary name next to the target (such as `report.mcp-tmp-….txt`) and replace the target only after succeeding; moving and renaming within one source replace the target in a single step. Overwriting by moving to a *different* source is not offered. If a temporary file is left behind (for example after a timeout), the result names it and tells you whether it holds the new content; do not delete it before checking.
220
+ - Closing the prompt, declining, or not answering in time cancels the whole operation. If the assistant's request is interrupted while the prompt is open, nothing is done even if you confirm later.
221
+ - Overwriting a folder, replacing a file with a folder (or the reverse), extracting into an existing folder, and overwriting by a move to another source are never offered; only saving under a new name or cancelling is. FileBrowser merges a copied folder into an existing one and silently replaces same-named files inside it, including hidden ones.
222
+ - Archiving and extracting never delete the originals. To remove them, check the result first, then use `fb_delete`.
223
+ - If your client does not support elicitation, overwriting and deleting are refused by default (`FILEBROWSER_CONFIRM_POLICY=strict`), even if the assistant asks for them. You can still save under a new name. With this combination you cannot edit an existing file in place, and `fb_delete` is hidden. With `trust-client`, they run after a two-step approval instead: the first call returns the list of changes and a one-time `approvalCode` (valid for `FILEBROWSER_CONFIRM_TIMEOUT_MS`, bound to the same arguments and an unchanged state), and only a second call with that code runs. The assistant should ask you in between, but the server cannot verify that it did.
224
+
225
+ **Confirmation before files leave.**
226
+
227
+ - Creating a share link always asks for your confirmation, whatever `FILEBROWSER_CONFIRM_POLICY` says. Clients without prompt support cannot create share links (`fb_create_share` is hidden).
228
+ - Writing to a different source, or into a folder or onto a file that is shared, also asks for confirmation. Under `strict`, clients without prompt support cannot do it.
229
+ - Only shares created by the MCP user itself are detected, and only when the token has the `share` permission. Shares you made with your usual account are not visible to it, so keep shared folders out of the MCP user's scope.
230
+ - When folder sharing is off (the default), archives (`.zip`, `.tar.gz`, …) cannot be shared either, because an archive of a folder contains its hidden files, and links that point to folders are treated as folders.
231
+
232
+ ### Read
233
+
234
+ | Tool | Description |
235
+ |---|---|
236
+ | `fb_list_sources` | List the sources you can access, your permissions on them, whether each is writable, and whether the token can share |
237
+ | `fb_list_dir` | List the files and folders in a directory, with paging (`limit`, `offset`). Hidden and excluded files may not be listed |
238
+ | `fb_get_info` | Get file or folder metadata (size, type, modified time, etc.) |
239
+ | `fb_read_file` | Read a UTF-8 text file, up to `FILEBROWSER_MAX_READ_BYTES` per call. Use `offset` to read the rest. Also returns the modified time |
240
+ | `fb_search` | Search by file name, with wildcards, date ranges, and result limits |
241
+ | `fb_find_duplicates` | Find duplicate files |
242
+
243
+ ### Write (unavailable when `FILEBROWSER_READ_ONLY=true`)
244
+
245
+ | Tool | Description |
246
+ |---|---|
247
+ | `fb_create_folder` | Create a folder |
248
+ | `fb_write_file` | Create a text file. Overwriting needs your confirmation; pass the `modified` time from `fb_read_file` as `expectedModified` so that a file changed in the meantime is not overwritten. A file the assistant has not read in full gets a warning |
249
+ | `fb_move` | Move one or more items |
250
+ | `fb_copy` | Copy one or more items (the originals stay) |
251
+ | `fb_rename` | Rename one item in place (takes only the new name) |
252
+ | `fb_archive` | Compress files and folders into a zip / tar.gz on the server |
253
+ | `fb_unarchive` | Extract an archive into a new folder on the server |
254
+
255
+ ### Delete (available only when `FILEBROWSER_ALLOW_DELETE=true`)
256
+
257
+ | Tool | Description |
258
+ |---|---|
259
+ | `fb_delete` | Delete up to 20 files or folders after you confirm |
260
+
261
+ ### Share (available only when `FILEBROWSER_ALLOW_SHARE=true`)
262
+
263
+ Share links make files reachable from outside FileBrowser, so these tools are off by default. Share URLs use the host set in FileBrowser's `http.externalUrl`; set it so that links point to your public address.
264
+
265
+ | Tool | Description |
266
+ |---|---|
267
+ | `fb_list_shares` | List the share links the MCP user created. Returns an id for each, not the link itself |
268
+ | `fb_create_share` | Create a share link after you confirm and return its URL. An expiry (up to `FILEBROWSER_MAX_SHARE_DAYS`) is required; a password and download limit are optional. Sharing a whole source is refused, and sharing a folder or an archive needs `FILEBROWSER_ALLOW_FOLDER_SHARE=true` |
269
+ | `fb_delete_share` | Delete one of your share links by its id |
270
+
271
+ ---
272
+
273
+ ## Limitations
274
+
275
+ - User, group, and access-rule management is not supported.
276
+ - **Client support for prompts varies.** Claude Code in the terminal (CLI) shows the prompts. The Claude Code extension for VS Code was found to cancel them without showing anything, so overwriting, deleting, and creating share links all end as cancelled there; nothing is changed. Use the CLI for these operations (it also runs in VS Code's integrated terminal). `trust-client` alone does not help, because the extension reports that it supports prompts. Adding `FILEBROWSER_ELICITATION=off` makes the extension work without any prompt, which is **dangerous** (see the caution under [Environment variables](#environment-variables)).
277
+ - Binary files cannot be read, uploaded, or downloaded yet.
278
+ - Public share links (`/public/...`) cannot be used as a source.
279
+ - File sizes are reported as the server returns them. Unless the source has `useLogicalSize: true` in the FileBrowser config, sizes are disk usage (for example, `4096` for a tiny file).
280
+ - The checks before a write run just before it, so a change made by someone else in between can still be overwritten. A change that keeps the same size and modified time (to the second) is not noticed.
281
+ - Names inside a copied folder or an extracted archive are not checked against the name rules. FileBrowser also strips trailing spaces when extracting, so two entries can collide.
282
+ - `fb_read_file` reads UTF-8 text up to 10 MiB. Binary files and text in other encodings (such as Shift_JIS) are refused.
283
+ - If a request times out or is interrupted, FileBrowser keeps running it on the server. Check the state before trying again.
284
+ - Writes (including move, copy, archive, and extract) send progress notifications while they run and while their confirmation prompt is open. Delete and share-link prompts and the duplicate search do not yet. Some clients give up on a tool call after their own timeout (often 60 seconds).
285
+ - **What the server cannot prevent:**
286
+ - The assistant can read a file and write its content somewhere else, or send it out with another tool in your MCP client. Narrow what it can reach with the user's scope, `FILEBROWSER_WRITABLE_SOURCES`, and your client's settings.
287
+ - New files are created without a prompt. Do not give the MCP user a scope that is served on the web or synced to other machines.
288
+ - Repeated copies or large extractions can fill the disk. Use quotas on the server.
289
+ - If your client answers prompts automatically (for example an agent SDK hook or an auto-approve mode), the confirmations no longer protect you. The server cannot tell whether a person answered.
290
+ - Too many prompts make it easy to approve without reading. The server only asks when something can be lost or leave FileBrowser, but please read each prompt.
291
+ - Shares made by other users are not detected. Sources that point to overlapping locations on disk cannot be told apart, and `FILEBROWSER_ALLOWED_SOURCES` matches source names only.
292
+
293
+ ---
294
+
295
+ ## Development
296
+
297
+ Design notes and the Docker-based development environment (in Japanese): [docs/design.md](docs/design.md), [docs/development.md](docs/development.md). The release procedure is in [docs/release.md](docs/release.md) (in Japanese).
298
+
299
+ ---
300
+
301
+ ## Security
302
+
303
+ To report a vulnerability, follow [SECURITY.md](SECURITY.md). Please do not open a public issue for it.
304
+
305
+ ---
306
+
307
+ ## Disclaimer
308
+
309
+ This software is provided "as is", without warranty of any kind. See sections 7 and 8 of the [Apache License, Version 2.0](LICENSE) for the full terms.
310
+
311
+ - The authors and contributors are not liable for any loss or damage arising from the use of this software, including data loss, corruption, overwriting, deletion, unintended disclosure (such as through share links), or service interruption.
312
+ - AI assistants can misread instructions and take actions you did not intend. The safety features (confirmation prompts, read-only mode, disabled delete and share tools) reduce risk but do not eliminate it, and some risks cannot be prevented by this server at all (see [Limitations](#limitations)).
313
+ - You are responsible for which operations you allow, which confirmations you approve, and the settings and permissions you give the MCP user.
314
+ - Keep independent backups of any data the server can reach, and try it on test data before using it on important files.
315
+ - This project is unofficial. Do not report problems caused by this server to the FileBrowser Quantum project.
316
+
317
+ ---
318
+
319
+ ## License
320
+
321
+ Licensed under the [Apache License, Version 2.0](LICENSE). See [NOTICE](NOTICE) for attribution of third-party material, including the bundled FileBrowser Quantum API spec.
322
+
323
+ ---
324
+
325
+ ## References
326
+
327
+ - [FileBrowser Quantum documentation](https://filebrowserquantum.com/en/docs/)
328
+ - [FileBrowser Quantum on GitHub](https://github.com/gtsteffaniak/filebrowser)
329
+ - [Model Context Protocol](https://modelcontextprotocol.io/)
@@ -0,0 +1,222 @@
1
+ // FileBrowser API endpoints used by the tools. Tools depend on this class, not on fetch.
2
+ // Server quirks are absorbed here, so callers always get absolute paths and real content.
3
+ import { toAbsolutePath } from "../core/paths.js";
4
+ import { errorFromHttp } from "./errors.js";
5
+ /** What v2.1.0-stable returns as `content` for a 0-byte file (verified). */
6
+ const EMPTY_FILE_PLACEHOLDER = "empty-file-x6OlSil";
7
+ export class FileBrowserClient {
8
+ http;
9
+ longTimeoutMs;
10
+ constructor(http, longTimeoutMs) {
11
+ this.http = http;
12
+ this.longTimeoutMs = longTimeoutMs;
13
+ }
14
+ getSelf(opts = {}) {
15
+ return this.http.json({
16
+ method: "GET",
17
+ path: "/api/users",
18
+ query: { username: "self" },
19
+ signal: opts.signal,
20
+ });
21
+ }
22
+ /** Used at startup to find out whether the token has the "share" permission (403 if not). */
23
+ async probeShareList(opts = {}) {
24
+ // Only the status matters: the body (possibly every user's shares) is not parsed.
25
+ await this.http.request({ method: "GET", path: "/api/share/list", signal: opts.signal });
26
+ }
27
+ getResource(source, path, opts = {}) {
28
+ return this.http.json({
29
+ method: "GET",
30
+ path: "/api/resources",
31
+ query: { source, path, skipExtendedAttrs: "true" },
32
+ signal: opts.signal,
33
+ errorContext: { source, path },
34
+ });
35
+ }
36
+ async getText(source, path, opts = {}) {
37
+ const res = await this.http.json({
38
+ method: "GET",
39
+ path: "/api/resources",
40
+ // Do not add skipExtendedAttrs here: with it the server omits `content` entirely (verified).
41
+ query: { source, path, content: "true" },
42
+ signal: opts.signal,
43
+ errorContext: { source, path },
44
+ });
45
+ if (res.type === "directory")
46
+ return { kind: "directory" };
47
+ if (res.content === undefined)
48
+ return { kind: "missing" };
49
+ if (res.content === null)
50
+ return { kind: "unreadable", type: res.type };
51
+ const text = res.size === 0 && res.content === EMPTY_FILE_PLACEHOLDER ? "" : res.content;
52
+ return { kind: "text", text, type: res.type, size: res.size, modified: res.modified };
53
+ }
54
+ /** Search results with absolute paths and a filled-in source (the server returns scope-relative paths). */
55
+ async search(params, opts = {}) {
56
+ const single = params.sources.length === 1 ? params.sources[0] : undefined;
57
+ const scope = params.path !== undefined && single !== undefined ? params.path : undefined;
58
+ const result = await this.http.json({
59
+ method: "GET",
60
+ path: "/api/tools/search",
61
+ query: {
62
+ query: params.query,
63
+ terms: params.terms,
64
+ termJoin: params.termJoin === "and" ? "and" : undefined,
65
+ useWildcard: params.useWildcard ? "true" : undefined,
66
+ ...(scope !== undefined
67
+ ? { scope: `${single}:${scope}` }
68
+ : { sources: params.sources.join(",") }),
69
+ limit: params.limit,
70
+ newerThan: params.newerThan,
71
+ olderThan: params.olderThan,
72
+ },
73
+ signal: opts.signal,
74
+ });
75
+ const raw = result ?? [];
76
+ const wanted = new Set(params.sources);
77
+ const results = raw.flatMap((r) => {
78
+ const source = r.source ?? single;
79
+ if (source === undefined || !wanted.has(source))
80
+ return [];
81
+ return [{ ...r, source, path: toAbsolutePath(r.path, scope ?? "/") }];
82
+ });
83
+ return { results, serverCount: raw.length };
84
+ }
85
+ async findDuplicates(source, scope, minSizeMb, opts = {}) {
86
+ const res = await this.http.json({
87
+ method: "GET",
88
+ path: "/api/tools/duplicate-finder",
89
+ query: { source, scope, minSizeMb },
90
+ timeoutMs: this.longTimeoutMs,
91
+ signal: opts.signal,
92
+ errorContext: { source, path: scope },
93
+ });
94
+ return {
95
+ groups: (res.groups ?? []).map((g) => {
96
+ // Paths start with "/" but are relative to `scope`, not the source root (verified).
97
+ const files = (g.files ?? []).map((f) => ({ ...f, path: toAbsolutePath(f.path, scope) }));
98
+ return { count: g.count ?? files.length, size: g.size, files };
99
+ }),
100
+ incomplete: res.incomplete === true,
101
+ reason: res.reason || null,
102
+ };
103
+ }
104
+ // ---- Writes -------------------------------------------------------------
105
+ /** POST a new file (no override: 409 if something already exists). */
106
+ async createFile(source, path, content, opts = {}) {
107
+ await this.http.request({
108
+ method: "POST",
109
+ path: "/api/resources",
110
+ query: { source, path },
111
+ body: content,
112
+ contentType: "application/octet-stream",
113
+ timeoutMs: opts.timeoutMs,
114
+ signal: opts.signal,
115
+ errorContext: { source, path },
116
+ });
117
+ }
118
+ /** POST ?isDir=true. The server creates missing parents. 409 if it exists. */
119
+ async createFolder(source, path, opts = {}) {
120
+ await this.http.request({
121
+ method: "POST",
122
+ path: "/api/resources",
123
+ query: { source, path: path.endsWith("/") ? path : `${path}/`, isDir: "true" },
124
+ signal: opts.signal,
125
+ errorContext: { source, path },
126
+ });
127
+ }
128
+ async deleteResource(source, path, opts = {}) {
129
+ await this.http.request({
130
+ method: "DELETE",
131
+ path: "/api/resources",
132
+ query: { source, path },
133
+ signal: opts.signal,
134
+ errorContext: { source, path },
135
+ });
136
+ }
137
+ /**
138
+ * PATCH /api/resources (copy / move / rename). The server overwrites existing
139
+ * destinations unconditionally, so callers must have checked for conflicts.
140
+ * 200 / 207 / 500 all carry {succeeded, failed}.
141
+ */
142
+ async moveCopy(action, items, opts = {}) {
143
+ const { status, body } = await this.http.jsonWithStatus({
144
+ method: "PATCH",
145
+ path: "/api/resources",
146
+ body: JSON.stringify({ action, items }),
147
+ contentType: "application/json",
148
+ timeoutMs: this.longTimeoutMs,
149
+ signal: opts.signal,
150
+ okStatuses: [207, 500],
151
+ });
152
+ if (!Array.isArray(body.succeeded) && !Array.isArray(body.failed)) {
153
+ // A plain {status, message} error (for example a 500 before any item ran).
154
+ throw errorFromHttp(status, typeof body.message === "string" ? body.message : "");
155
+ }
156
+ return { succeeded: body.succeeded ?? [], failed: body.failed ?? [] };
157
+ }
158
+ async archive(req, opts = {}) {
159
+ await this.http.request({
160
+ method: "POST",
161
+ path: "/api/resources/archive",
162
+ body: JSON.stringify({ ...req, deleteAfter: false }),
163
+ contentType: "application/json",
164
+ timeoutMs: this.longTimeoutMs,
165
+ signal: opts.signal,
166
+ errorContext: { source: req.toSource, path: req.destination },
167
+ });
168
+ }
169
+ async unarchive(req, opts = {}) {
170
+ await this.http.request({
171
+ method: "POST",
172
+ path: "/api/resources/unarchive",
173
+ body: JSON.stringify({ ...req, deleteAfter: false }),
174
+ contentType: "application/json",
175
+ timeoutMs: this.longTimeoutMs,
176
+ signal: opts.signal,
177
+ errorContext: { source: req.toSource, path: req.destination },
178
+ });
179
+ }
180
+ /** DELETE /api/resources/bulk. The body is a bare array. 200 / 207 carry {succeeded, failed}. */
181
+ async bulkDelete(items, opts = {}) {
182
+ const { status, body } = await this.http.jsonWithStatus({
183
+ method: "DELETE",
184
+ path: "/api/resources/bulk",
185
+ body: JSON.stringify(items),
186
+ contentType: "application/json",
187
+ timeoutMs: this.longTimeoutMs,
188
+ signal: opts.signal,
189
+ okStatuses: [207, 500],
190
+ });
191
+ if (!Array.isArray(body.succeeded) && !Array.isArray(body.failed)) {
192
+ throw errorFromHttp(status, typeof body.message === "string" ? body.message : "");
193
+ }
194
+ return { succeeded: body.succeeded ?? [], failed: body.failed ?? [] };
195
+ }
196
+ /** POST /api/share. */
197
+ createShare(body, opts = {}) {
198
+ return this.http.json({
199
+ method: "POST",
200
+ path: "/api/share",
201
+ body: JSON.stringify(body),
202
+ contentType: "application/json",
203
+ signal: opts.signal,
204
+ errorContext: { source: String(body.source), path: String(body.path) },
205
+ });
206
+ }
207
+ /** DELETE /api/share?hash. 400 "share not found" means not_found. */
208
+ async deleteShare(hash, opts = {}) {
209
+ await this.http.request({
210
+ method: "DELETE",
211
+ path: "/api/share",
212
+ query: { hash },
213
+ signal: opts.signal,
214
+ errorContext: { shareDelete: true },
215
+ });
216
+ }
217
+ listShares(opts = {}) {
218
+ return this.http
219
+ .json({ method: "GET", path: "/api/share/list", signal: opts.signal })
220
+ .then((list) => list ?? []);
221
+ }
222
+ }