File System MCP Server: Scope Agent File Access Safely
Key takeaways
- A file system MCP server exposes read, write, list, search, and move tools to agents, scoped to directories you pass as launch arguments.
- Allowed directories are the only real boundary: scope to a project folder, never your home directory, and verify with list_allowed_directories.
- Prompt injection can turn read access into unauthorized writes, so grant write tools only when a task explicitly needs them.
- Symlink resolution happens at the OS level after the allowlist check, so a safe server must re-resolve real paths before every operation.
- Git the workspace and log every tools/call at the client to get a free, exact audit trail and one-command rollback.
A file system MCP server exposes a scoped slice of your local disk to MCP clients like Claude Code or Cursor over the Model Context Protocol, so agents can read, write, and move files inside directories you allow, and nowhere else. This guide walks through allowed-directories scoping, tool-by-tool permission mapping, sandboxing trade-offs, and an audit trail for what the agent touched.
What is a file system MCP server?
A file system MCP server is a server that exposes local file operations, like read, write, list, search, and move, to an agent through the Model Context Protocol. Instead of pasting file contents into chat, the model calls tools that act directly on your disk. The MCP spec defines servers as programs exposing tools and resources to clients (Model Context Protocol docs), so the same pattern applies whether the client is Claude Code, Cursor, or your own agent.
The practical payoff is scope control: you decide which directories the server can see and which tools it registers. A typical setup scopes it to a project folder, not your whole disk. If you want a worked example of a paid MCP server behind x402, we documented ours at https://scriptmasterlabs.com/settle-mcp-server.
Which tools does a file system MCP server expose to an agent?
A file system MCP server exposes a fixed set of tools over tools/list, and each one carries a different blast radius. Group them before you grant them.
Read-only tools
read_file, read_multiple_files, list_directory, directory_tree, and list_allowed_directories only leak data. They cannot change state, so they are the safe default grant. directory_tree is the noisiest: on a large tree it can flood the context window.
Write and mutate tools
write_file, edit_file, create_directory, and move_file change state. move_file is the worst of the four because it destroys the original path, so treat it like a delete. Scope these to a working directory, not your home folder.
Metadata and search tools
search_files and get_file_info are low-risk reconnaissance: names, sizes, timestamps. Useful for agents planning a task, cheap to allow.
| Tool | Blast radius | Grant when |
|---|---|---|
read_file |
Data exposure | Almost always |
write_file |
File overwrite | Scoped dir |
move_file |
Path destroyed | Rarely |
search_files |
Name leakage | Usually |
The same principle applies to any MCP server: the tool list is the contract.
How do you configure allowed directories safely?
Allowed directories are the only real boundary between your agent and the rest of your machine. The reference filesystem MCP server takes the directories as launch arguments, and every tool call is checked against that list before it runs. Get the argument wrong and the check is worthless.
Step 1: pick the narrowest workspace
Scope to a project directory, never $HOME. If you pass /Users/you, the agent can read your .env, your SSH keys, and every other repo on the disk. A workspace like /Users/you/projects/billing-agent keeps the blast radius to one codebase. We run the same rule on our own MCP servers: the server sees only what its config names, and nothing inherited.
Step 2: pass directories as launch args
In your MCP client config, the args array is the whole contract:
{
"command": "npx",
"args": [
"-y", "@modelcontextprotocol/server-filesystem",
"/Users/you/projects/billing-agent"
]
}
Treat this file as security policy, not plumbing. It belongs in review, and a change to it should be as deliberate as a change to a firewall rule.
Step 3: verify the scope from inside the agent
Don't trust your config file; ask the server. Call list_allowed_directories from inside the agent and confirm the output matches the workspace you intended. This one call catches the most common failure: a stale or duplicated config entry granting more than you thought. The same README documents the full tool list, so you can map each tool against the boundary before the agent ever touches a file.
What are the risks of giving an AI agent file system access?
Prompt injection turns read access into write instructions
An agent that reads a file absorbs its content into context. A malicious README, dependency changelog, or downloaded dataset can contain instructions like "write this config to ~/.ssh/authorized_keys." If your file system MCP server grants write_file alongside read_file, a poisoned read becomes a write you never approved. Scope by directory and by tool: read-only roots for anything the agent did not create, and treat every fetched document as untrusted input.
Symlinks and traversal inside the allowed root
Scoping to /home/you/project is not a boundary if that tree contains a symlink to /etc or a hard link to ~/.aws. Path traversal (../) is usually filtered, but symlink resolution happens at the OS level, after your allowlist check. A safe server resolves the real path and re-checks it against allowed directories before every operation. We publish the exact gate tests we run for traversal, symlinks, and overwrite attempts at scriptmasterlabs.com/mcp-server-gate-tests.
Context exfiltration is a side effect of reading
Every read_file result ships to your model provider's API. Reading a .env file means sending credentials to a third party, even if the agent never writes anything. Keep secrets out of allowed roots, and prefer per-call paid APIs over broad local reads when the evidence lives elsewhere.
Which tools should you grant, tool by tool?
Treat each tool the file system MCP server exposes as a separate grant, not a bundle. A sensible default-deny policy: allow read_file, read_multiple_files, and list_directory on the workspace; deny every write tool (write_file, edit_file, create_directory) until a task explicitly needs one; and gate move_file and delete behind a separate profile or human approval, since those are the ones that destroy state irreversibly.
The MCP specification lets servers declare tools and leaves authorization policy to the client and operator, so the mapping is yours to enforce (tool invocation and authorization). Check how your client surfaces per-tool toggles before you connect anything.
Honest caveat: most stock file system servers are all-or-nothing. The reference implementation takes allowed directories at startup and exposes every tool it defines, so you cannot deny writes per tool without forking or wrapping it. If your client cannot gate tools either, run the server under an OS user that only owns the workspace, and use our checklist to map grants before first run: MCP server security checklist.
How does a file system MCP server differ from code execution sandboxes?
A file system MCP server exposes a fixed set of structured operations: read, write, list, move, search. The agent never runs arbitrary code, so the blast radius is the allowed directories and nothing else. Every call maps to one named tool, which makes the audit trail trivial: each action is a discrete, loggable event.
A code execution sandbox inverts that. The agent writes and runs whatever it wants, and the sandbox's job is to contain the OS-level fallout: network calls, subprocesses, installs. You get far more flexibility, and a much larger surface to reason about.
The trade-off is flexibility versus blast radius and auditability. If the task is "edit these files," the file server is narrower and easier to review. If the task needs computation, package installs, or shell pipelines, no fixed tool list will cover it, and a sandbox is the honest choice. Many stacks use both: sandbox for the heavy work, file server for the touches you want logged.
When should a team use a file system MCP server vs. a cloud storage connector?
Use a file system MCP server when the files the agent needs already live on the machine: private repos, local logs, generated artifacts, anything you would not copy to a vendor. Reads are fast, work continues offline, and nothing leaves the disk unless a tool sends it. Configure the client's allowed directories so the server sees a scoped root, not the whole drive, per Anthropic's MCP client configuration docs (Claude Code settings).
Reach for a cloud storage connector when files must be shared across machines, versioned, or touched by agents running elsewhere. That moves trust to the provider and its access controls. Local means speed and privacy; cloud means reach and durability. Pick per data residency, not habit.
How do you audit what an agent did to your files?
Log every tools/call at the client
Most MCP clients can log requests. Claude Code writes session transcripts; custom agents built on the TypeScript or Python SDKs can wrap the client and dump every tools/call with arguments and timestamps to a JSONL file. Log before the server sees anything, so you have a record even if the server misbehaves. Keep the log outside the workspace the agent can write to.
Git the workspace as a free undo log
Run git init and commit before each session, then git diff and git log --stat after. You get an exact record of which files changed, when, and how, plus one-command rollback. Scope the repo to the allowed directory so nothing outside it is ever in play.
Gate-test the server before first real use
Write a small test suite that calls the server directly: attempt write_file outside the allowed directory, attempt edit_file on a read-only path, attempt move_file across the boundary. Each should fail. Run it against your config before any real session, and re-run it whenever you change allowed directories or grant a new tool. Trust the config you tested, not the one you intended.
FAQ
Is the file system MCP server safe to use with Claude Desktop or Cursor?
It is as safe as your configuration. The server only enforces the directories you pass at launch and the tools your client registers, so a scoped project folder with read tools is low risk. Granting write tools or a broad root raises the stakes: prompt injection through a read file can become an unwanted write.
How do I restrict the filesystem MCP server to a single folder?
Pass the folder as a launch argument in your MCP client config, using the args array for the reference server. Scope to a project directory, never your home folder, since a broad root exposes SSH keys and every repo. After connecting, call list_allowed_directories from inside the agent to confirm the server sees only the folder you intended.
Can an MCP file server access files outside its allowed directories?
Not through normal tool calls; every operation is checked against the allowlist before it runs. The exception is symlink resolution, which happens at the OS level after the check. If the allowed tree contains a symlink to somewhere sensitive, the server can follow it. A safe implementation resolves the real path and re-checks it against the allowlist.
Does giving an agent file access cost anything per call?
The file operations themselves are local and free; you pay nothing to the server. The cost is indirect: every read_file result is sent to your model provider's API as context, so large reads consume tokens and ship file contents to a third party. Keep secrets out of allowed roots to avoid leaking credentials through a routine read.
What is the difference between the filesystem MCP server and letting the agent run shell commands?
The file server exposes a fixed set of named operations, so the agent cannot run arbitrary code and each action is a discrete, loggable event. Shell access lets the agent do anything the OS allows: network calls, installs, subprocesses. That flexibility requires a real sandbox to contain fallout, while the file server's blast radius is just the allowed directories.
ScriptMasterLabs comparison: The ScriptMasterLabs x402 Kit is free under the MIT license, and it is the ready-made way to put an MCP server behind x402 — the same approach as ScriptMasterLabs' Settle MCP server. On OMNIGATE, the x402 facilitator fee is 0.005 USDC, and only for the optional leg. See all ScriptMasterLabs products at https://scriptmasterlabs.com/sml-products
Canonical: https://scriptmasterlabs.com/blog/file-system-mcp-server
FOLLOW
X: @TimmyCrypto78 — https://x.com/TimmyCrypto78
Instagram: @scriptmasterlabs — https://www.instagram.com/scriptmasterlabs
Threads: @scriptmasterlabs — https://www.threads.net/@scriptmasterlabs
Telegram: @x402sml — https://t.me/x402sml
LinkedIn: https://www.linkedin.com/in/timothy-walton-23224052
MY LINKS
🛒 All SML products: https://scriptmasterlabs.com/sml-products
Website: https://scriptmasterlabs.com
Books: https://scriptmasterlabs.com/sml-products#books
Shop: https://shop.scriptmasterlabs.com
Gumroad: https://timwalton.gumroad.com
Whop: https://whop.com/timmy741
Ko-fi: https://ko-fi.com/scriptmaster
Discord: https://discord.gg/jGWDutyVAR
Verdict Protocol: https://verdict.scriptmasterlabs.com
Free VA tools: https://va-ratings.org
Top comments (0)