# filesystem — allowlisted filesystem MCP connector for SCORPIOX BOT `plugin_filesystem` is a clean-room, zero-dependency **pure C99** rewrite of the tool surface of [`modelcontextprotocol/servers` → `src/filesystem`](https://github.com/modelcontextprotocol/servers/tree/main/src/filesystem), reshaped as a **SCORPIOX BOT connector plugin**: one binary, four modes, no shared-library requirements, and a sandbox you can actually read. It is deliberately **not** the read-only `files` browser. `files` lets a human look at files; `filesystem` lets an **agent** change them — inside a list of directories you approve, and nowhere else. | | | |---|---| | Slug | `filesystem` | | Binary | `plugin_filesystem` (`plugin_filesystem.exe` on Windows) | | `--meta` | `{"name":"filesystem","desc":"Allowlist FS","kind":"mcp","mcp":true,"daemon":false,"menus":false,"verified":"live"}` | | Category | `devtools` | | Kind | MCP connector (`--mcp`, stdio JSON-RPC 2.0) | | License | MIT | ## Modes | Mode | Trigger | Who calls it | |---|---|---| | Discovery | `--meta` / `SX_PLUGIN_META=1` | `scorpiox-bot-api` `/plugins`, `scorpiox-cli-botplugin`, `sx-connector-mcp` | | MCP tools | `--mcp` | `sx-connector-mcp` (the single MCP router) or any MCP client over stdio | | Control API | `?action=…` / `?format=json` | the plugin page (behind `require_node_auth()`) | | Setup page | `GET` | the browser, via the hub or the node directly | ```sh ./plugin_filesystem --meta printf '%s\n' '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' | ./plugin_filesystem --mcp make && make test && make e2e ``` ## Tools (11, matching the upstream subset) | Tool | Parameters | | |---|---|---| | `read_text_file` | `path`, `head?`, `tail?` | read | | `read_multiple_files` | `paths[]` | read | | `write_file` | `path`, `content` | write (atomic) | | `edit_file` | `path`, `edits[{oldText,newText}]`, `dryRun?` | write | | `create_directory` | `path` | write | | `list_directory` | `path` | read | | `directory_tree` | `path`, `maxDepth?`, `excludePatterns?` | read | | `move_file` | `source`, `destination` | write | | `search_files` | `path`, `pattern`, `excludePatterns?` | read | | `get_file_info` | `path` | read | | `list_allowed_directories` | — | read (never disableable) | Behaviour worth knowing before you point an agent at it: * **`write_file` is atomic** — content goes to `.tmp-`, is flushed, then renamed. A crash mid-write leaves the old file or the new one, never a half-written file. `tests/run.sh` proves this by `SIGKILL`ing the process mid-request. * **`edit_file` is all-or-nothing.** Edits apply in order, each replacing the first match of its `oldText`. An exact match wins; failing that, a run of whole lines matches when each line is equal ignoring leading and trailing whitespace. If *any* edit fails to match, **nothing** is written and the reply shows the closest numbered lines so the agent can re-copy `oldText`. The file's own LF/CRLF choice is preserved. * **`move_file` will not overwrite.** It refuses, because silently replacing an operator's file is the one thing an unattended agent must not get. A cross-device move falls back to copy-then-delete. * **`read_text_file` refuses binary** rather than returning mojibake, and says what to call instead. ## The sandbox Every path — from a tool call or an HTTP request — goes through the same gate: 1. **Shape.** Absolute, no NUL or control bytes, and no `..` segment anywhere. `%2e%2e` and `%2f` are decoded before this check, so encoding does not help. 2. **Canonicalise.** `realpath()` on POSIX; `GetFullPathNameA()` then `GetFinalPathNameByHandleA()` on Windows. The check happens **after** symlink resolution, which is the only order that means anything. 3. **Prefix-check against every root.** Each root is stored in **two forms** — the path the operator configured *and* its `realpath`. That is what makes a configured `/tmp` work on macOS, where the real path is `/private/tmp` (lesson `(cc)`/`(ah)` from the upstream reference). 4. **Deny list.** `/proc`, `/sys`, `/dev` are refused even under an allowed root; operator `denied` entries are refused on top of that. 5. **Write mode additionally checks the resolved parent** and refuses a symlinked leaf, so a link pointing out of the sandbox cannot be used as a handle to write through. ```sh # symlink escape is refused on read, write, edit and move ln -s /etc/passwd ~/data/notes.txt ./plugin_filesystem --mcp <<< '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"write_file","arguments":{"path":"'$HOME'/data/notes.txt","content":"x"}}}' # → isError: /root/data/notes.txt: path is outside the allowed directories ``` ## Configuration State lives outside the binary so it survives reinstalls: ``` ~/.scorpiox/connectors/plugin_filesystem/roots.json /workspace/.scorpiox/connectors/plugin_filesystem/roots.json (BotCloud) %LOCALAPPDATA%\scorpiox\connectors\plugin_filesystem\roots.json (Windows) ``` ```json { "roots": ["/data/reports", "/srv/site"], "denied": ["/srv/site/.env"], "permissions": { "write_file": false, "move_file": false } } ``` * `$FS_ALLOWED_ROOTS` (colon-separated, `;` on Windows) overrides the file — that is how the test suite points the plugin at a fixture tree. * With neither configured the defaults are `/workspace` and `$HOME` (POSIX) or `%USERPROFILE%` and `D:\codebases` (Windows). * **Permissions are enforced by `--mcp`, not just displayed by the page.** A disabled tool answers with a refusal that says where to switch it back on, so the agent gets an explanation instead of a missing tool. `list_allowed_directories` cannot be disabled — it is how you debug a refusal. ## Setup page `GET /plugin_filesystem` (or `/plugins?plugin=plugin_filesystem` through the hub) serves the Allowed Roots & Permissions page: add and remove directories, see each root's canonical form when it has drifted onto a symlink or a mount, toggle each tool, and **test a path against the sandbox** before blaming a tool for it. Bot theme tokens, `?embed=1`, `sx-theme` handoff, zero CDN, zero `