# Filesystem MCP server security: what it can access

> The Filesystem MCP server reads, writes and moves files in the folders you allow. See its tools, the --read-only flag and how to limit it.

The Filesystem MCP server is a local server from the `modelcontextprotocol/servers` repository. It gives an AI agent tools to read, write, edit, move and copy files, but only inside the directories you pass when you start it. Start it with `--read-only` and it registers only the read tools. The risk is the folder you choose: everything inside it is open to the agent, including secrets stored there.

## What it is

The code lives at [modelcontextprotocol/servers](https://github.com/modelcontextprotocol/servers/tree/main/src/filesystem) under `src/filesystem`. The README does not name individual maintainers. It runs on your machine, so no file contents pass through a server of its own. They still go to the model provider your agent uses.

There is no sign-in. Access is set by the allowed directories. The README recommends passing them as command-line arguments, which it says is the only method that works on every protocol version. A client that supports MCP Roots can replace the list at runtime, though the README says Roots are deprecated as of protocol version 2026-07-28. The `--confine-roots` flag keeps client Roots inside the directories you passed, so they can only narrow the list.

## What the tools can do

| Group | Tools |
| --- | --- |
| Read | `read_text_file`, `read_media_file`, `read_multiple_files`, `list_directory`, `list_directory_with_sizes`, `directory_tree`, `search_files`, `get_file_info`, `list_allowed_directories` |
| Write | `create_directory`, `write_file`, `append_file`, `edit_file` |
| Move and copy | `move_file`, `copy_file` |

`write_file` overwrites an existing file. `move_file` removes its source, so it can destroy a file by moving it over another path. The README lists no tool named for deleting, but overwriting and moving can have the same effect. Every read tool is annotated `readOnlyHint: true` and every write, move and copy tool is annotated false.

## Limit it at the server

```json
{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "--read-only", "/Users/you/project"]
    }
  }
}
```

The README’s own example uses this package name and says options may come before, between or after the directories. The documented options are:

- `--read-only` registers only tools annotated `readOnlyHint: true`. Write tools are withheld, so calling one fails as an unknown tool.
- `--read-only-dir <path>` protects specific directories while others stay writable. Write tools stay listed but refuse targets inside those directories.
- In Docker, mount a folder under `/projects` with `ro` to make it read-only to the server.

The README also recommends OS-level read-only permissions as a second layer.

## Risks that remain

- Allowing your home folder exposes `~/.ssh`, `~/.aws` and every `.env` file under it. Allow a project folder.
- File contents are untrusted input. A README, a downloaded document or a log can contain instructions, and the server reads it into the agent’s context.
- Symlinks and hard links need thought. The README says paths are checked on macOS and Linux and writes are anchored to the validated directory, but a write through a hard link can change the file at its other names.
- Over HTTP the server listens on `127.0.0.1:3001` by default. Setting `HOST=0.0.0.0` exposes it to the network.

## Limit it in Claude Code and Codex

Claude Code already has built-in file tools with their own rules. This server adds a second path to the same files, so the built-in `Read` and `Edit` deny rules do not cover it. Write rules for the MCP names too. Rules are checked deny, then ask, then allow.

```json
{
  "permissions": {
    "deny": ["mcp__filesystem__write_file", "mcp__filesystem__move_file", "mcp__filesystem__edit_file"]
  }
}
```

Put them in `.claude/settings.json` for a project or `~/.claude/settings.json` for all projects. `mcp__filesystem__*` matches every tool from a server named `filesystem`.

In Codex, add the server in `~/.codex/config.toml` and filter tools:

```toml
[mcp_servers.filesystem]
command = "npx"
args = ["-y", "@modelcontextprotocol/server-filesystem", "--read-only", "/Users/you/project"]
enabled_tools = ["read_text_file", "list_directory", "search_files"]
```

## Checklist

1. Pass one project folder, never your home folder.
2. Add `--read-only` unless the task writes files.
3. Keep secrets, keys and `.env` files outside the allowed folder.
4. Deny `write_file`, `edit_file` and `move_file` in the agent’s settings if you want a second layer.
5. Commit or back up first, so an overwrite is recoverable. See [what to do when an agent deletes files on a Mac](https://www.excellent.so/guides/ai-agent-deleted-files-on-mac).

Checked against the vendor documentation on November 25, 2026. [Filesystem server README](https://github.com/modelcontextprotocol/servers/tree/main/src/filesystem) · [Claude Code permissions](https://code.claude.com/docs/en/permissions) · [Claude Code MCP](https://code.claude.com/docs/en/mcp) · [Codex MCP](https://learn.chatgpt.com/docs/extend/mcp?surface=cli)

## Where Excellent fits

Excellent’s free scan reads supported logs on the Mac and reports findings for review. It reads the session logs of Claude Code, Codex, Grok Build, GitHub Copilot CLI, Gemini CLI and Qwen Code. It does not inspect MCP servers themselves. For a local report without installing an app, [run the free scan](https://www.excellent.so/scan). [See a sample report](https://www.excellent.so/r/sample).

With Pro, it blocks or asks before the risky actions it checks for, such as deleting protected folders or reading key files. Pro can also configure Claude Code and Codex’s native Mac sandboxes from your file and folder rules, with a plan to review first. [Sandbox setup](https://www.excellent.so/docs/sandbox) · [pricing](https://www.excellent.so/pricing). Pro is US-only for now.

Source: https://www.excellent.so/guides/filesystem-mcp-server
