DEV Community

Cover image for I Let AI Agents Move Files on a Mac. Here's How I Kept It Safe.
Md Ayan bag
Md Ayan bag

Posted on AI-assisted

I Let AI Agents Move Files on a Mac. Here's How I Kept It Safe.

Lessons from shipping an MCP server inside a Mac app: one tool that changes anything, eight that only look, and a human in the loop every time.

I build a Mac storage app called Tidy Mac. This year I added an MCP server to it, so AI agents like Claude Code can ask what’s filling a Mac and, with permission, move files to the Trash.

That’s a scary sentence to write. An agent with access to someone’s files can do real damage in a second.

Here’s how I designed it so that can’t happen, and what I’d tell anyone building an MCP server that touches real data.

(I wrote this with help from an AI assistant. The design decisions are mine. Full disclosure: it’s my app.)

1. Split looking from doing

The server has nine tools. Eight only read: disk overview, storage breakdown, biggest folders, large files, duplicates, junk, installed apps, and a plain-English file search.

One tool changes anything: move_to_trash.

MCP lets you mark this. Every tool carries a readOnlyHint or a destructiveHint, so the client knows which ones need more care. If your design has several tools that change things, ask whether they can collapse into one. One door is easier to guard than five.

2. Put a person in front of the one that acts

Every move_to_trash call opens a pop-up from the app itself. It lists exactly what will move. The person clicks Allow or the request fails. There’s no “always allow”.

A few details made this usable:

  • The pop-up drops from the top of the screen without taking focus from the agent’s window, so you’re not yanked out of what you’re doing.
  • It waits 60 seconds, then counts as a no. An unattended Mac never says yes.
  • If several agents ask at once, the pop-ups queue. One question at a time.

3. Make the dangerous thing undoable

Nothing is deleted. Files go to the Trash, and the app keeps a History with Undo.

That single choice changes the risk. A wrong approval is an annoyance, not a disaster. If your server can change data, look hard for the version of the action that can be reversed.

4. Refuse some things no matter what

Some locations are refused even if the person would click Allow: system folders, keychains, iCloud Drive, SSH keys, and data belonging to apps that are running.

The check runs on every path, after the path is cleaned up, so ~ and .. tricks don’t get around it. Requests are capped at 200 paths. Relative paths are refused outright.

5. Write refusals the agent can act on

This is the lesson I didn’t expect. When the server says no, the agent reads the reason and decides what to do next. A bare error makes it guess, retry or give up.

So every refusal says what to do instead. If the person turned agent actions off in Settings, the message tells the agent to show them the paths instead. If a path is protected, it says why. The agent passes that on, and the person understands what happened.

6. Keep stdout clean, and don’t block

Two plumbing lessons. The server talks JSON-RPC over stdin and stdout, so stdout must carry protocol messages and nothing else. Every log line goes to stderr. One stray print and the client can’t read the stream.

And because a pop-up can sit for up to a minute, requests are handled concurrently. A waiting approval doesn’t stop the agent from asking how big a folder is.

7. Tell the agent how to use you

An MCP server can send instructions when the connection starts. Mine are three sentences: what the tools measure, that removing files needs approval every time, and that files go to the Trash and can be put back.

Tool descriptions do the rest. I mark cheap ones as “Fast.” and slow ones with how long they take, so the agent picks the cheap one first.

The checklist

  • Separate reading tools from acting tools, and keep acting tools few.
  • Put a human approval in your own UI in front of anything that changes data.
  • Make the action reversible.
  • Hard-refuse the places that must never be touched.
  • Write refusals as next steps.
  • Logs to stderr. Don’t let one slow call block the rest.

Agents are getting good at deciding what to do. The server’s job is to make sure the worst thing they can decide is still easy to undo.


I build Tidy Mac, a Mac storage app with this MCP server inside. If you run Claude Code or Cursor on a Mac, claude mcp add tidymac -- "/Applications/Tidy Mac.app/Contents/MacOS/tidymac-mcp" lets your agent see what's filling the disk. Questions about the design are welcome in the comments.

Top comments (1)

Collapse
 
diskbee profile image
DiskBee(NTFS for Mac) •

The canonical-path check is the part I would keep testing adversarially. Cleaning up ~ and .. does not itself resolve a symlink inside an allowed directory that points into ~/.ssh, and a path can potentially change between validation and the move.

Does move_to_trash call resolvingSymlinksInPath() and revalidate the resolved URL at the moment of the move? The approval dialog and Trash fallback are useful boundaries; the refusal tests could also include a symlinked parent and a path replaced after the preview appears.