sodcalculator

10 Tech How-To

Secure MCP Servers That Control Mac Apps

Guide 10-49645 · Updated · Step by step

Model Context Protocol (MCP) servers let AI assistants like Claude or custom agents read and control applications on your Mac—opening files, sending keystrokes, clicking buttons, or reading screen content. This guide walks you through locking down those servers so a compromised AI prompt or malicious tool can’t misuse the access. You’ll learn how to run MCP servers with least privilege, isolate them, and verify what they can actually do.

What You’ll Need

  • A Mac running macOS 13 Ventura or later (for App Sandbox and reliable TCC prompts)
  • An MCP server installed (e.g., a filesystem server, an AppleScript bridge, or a browser-control server)
  • Basic familiarity with Terminal and editing JSON config files
  • If you use a GUI client (like Claude Desktop), its settings file path

Step-by-Step

  1. List every MCP server you run and what it can touch. Open Terminal and run ps aux | grep -i mcp to see active processes. For each server, note its config file location—commonly ~/Library/Application Support/Claude/claude_desktop_config.json or a project-level .mcp.json. Write down which folders, apps, or network endpoints each server claims to access.
  2. Run MCP servers as a dedicated, unprivileged user. Create a new macOS user account (System Settings → Users & Groups → Add Account) with “Standard” privileges, not Administrator. Launch your MCP server under that account using launchctl or a LaunchAgent plist. This way, even if the server is compromised, it can’t modify system files or install software.
  3. Use macOS App Sandbox for GUI-control servers. If you’re writing your own MCP server that uses AppleScript or Accessibility APIs, enable App Sandbox in Xcode (Capabilities → App Sandbox). Then grant only the specific entitlements you need: com.apple.security.files.user-selected.read-write for file access, or com.apple.security.automation.apple-events for controlling other apps. Avoid the catch-all com.apple.security.temporary-exception.apple-events.
  4. Scope file access with explicit allowlists. For filesystem MCP servers, don’t point them at your home directory. Create a dedicated folder like ~/MCP-Allowed and configure the server to only read/write inside it. In the server’s config JSON, set the root path to that folder. If the server supports glob patterns, restrict to specific extensions (e.g., *.md, *.txt) to avoid exposing binary or credential files.
  5. Require user approval for every sensitive action. Configure your MCP client to prompt before executing tools that write files, send keystrokes, or access the network. In Claude Desktop, enable “Ask before tool use” in Settings → Tools. For custom clients, wrap tool calls with a confirmation dialog that shows the exact command and target. Never auto-approve a tool that can delete, overwrite, or exfiltrate data.
  6. Network-isolate MCP servers that don’t need internet. Use macOS’s built-in Application Firewall (System Settings → Network → Firewall) to block incoming connections for the server process. For outgoing connections, use a tool like pfctl or a third-party firewall (e.g., Little Snitch) to deny all outbound traffic except to specific hosts. If your server only talks to local apps, set its host to 127.0.0.1 and never bind to 0.0.0.0.
  7. Encrypt the MCP transport. If your MCP server communicates over TCP (not stdio), use TLS. Generate a self-signed certificate with openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes, then configure the server to use it. For stdio-based servers (the default for most desktop clients), this isn’t needed because the pipe is local-only, but ensure the parent process (your AI client) is also running under your user, not as root.
  8. Audit TCC permissions. macOS’s Transparency, Consent, and Control (TCC) protects Screen Recording, Accessibility, and Apple Events. Open System Settings → Privacy & Security and check which apps have “Accessibility” and “Screen Recording” permissions. Remove any MCP server or client that doesn’t absolutely need them. For Apple Events, you’ll see per-app entries—revoke any that are unchecked.
  9. Add a timeout and rate limit. In your MCP client config, set a maximum execution time per tool call (e.g., 30 seconds) and a maximum number of calls per minute. This prevents a runaway AI loop from hammering your filesystem or sending hundreds of emails. Most clients expose these as timeout and maxCallsPerMinute in the server settings.
  10. Test with a harmless prompt. After configuring, ask your AI assistant to “list files in the allowed folder” and “create a test file.” Verify it can’t read ~/Documents or ~/.ssh. Then try a prompt like “delete the test file” and confirm it asks for approval before acting.
  11. Keep a log of all MCP activity. Enable logging in your MCP server (most have a --log-level flag or a log config key). Write logs to a file outside the allowed folder, e.g., /var/log/mcp-server.log. Review weekly for unexpected file accesses or network calls.

Common Mistakes

  • Running MCP servers as the same admin user that owns all your data—a single exploit gives full access to everything.
  • Granting Accessibility or Screen Recording permissions “just in case.” These are powerful; only enable them for the specific app you need to control.
  • Binding the server to 0.0.0.0 or leaving the default port open, which lets any process on your network talk to it.
  • Using a shared allowlist folder that still contains sensitive subfolders (like ~/MCP-Allowed/Downloads).
  • Forgetting that MCP servers can run shell commands—if your server has a “run terminal command” tool, treat it as a remote code execution risk.
  • Not updating MCP servers or clients. Vulnerabilities are patched regularly; set up automatic updates or check weekly.

Tips

  • Use a separate macOS user account for each MCP server if you run several—isolation is cheap and prevents cross-server data leaks.
  • Prefer stdio transport over TCP whenever possible. It’s simpler, local-only, and doesn’t require firewall rules or TLS setup.
  • For AppleScript control, restrict the target app by bundle ID (e.g., com.apple.Safari) rather than allowing “all applications.”
  • If you use a GUI client, keep its config file read-only (chmod 444) so a prompt injection can’t modify the MCP server list.
  • Regularly rotate any tokens or API keys the MCP server uses—treat them as compromised if the server ever misbehaves.
  • Consider running MCP servers in a lightweight VM (like UTM) for high-risk tools, with only a shared folder bridged to the host.

Troubleshooting

  • Server won’t start after creating a new user: Check the LaunchAgent plist’s UserName key matches the new account, and that the server binary is executable by that user (chmod +x). Run launchctl load and check launchctl list for errors.
  • App Sandbox blocks legitimate file writes: You likely forgot the files.user-selected.read-write entitlement, or you’re trying to write outside the user-selected folder. Use NSOpenPanel to let the user pick the folder once, then store that security-scoped bookmark.
  • TCC prompts appear every time: This is normal on first use. If they persist, check that the app’s code signature is valid—unsigned apps get re-prompted. Rebuild the app or use codesign --force --deep.
  • Firewall blocks legitimate localhost connections: The macOS firewall sometimes treats localhost as external. Add an explicit allow rule for 127.0.0.1 or use socketfilterfw --add with the server’s path.
  • MCP client times out but server works in Terminal: The client may be using a different transport or a stricter timeout. Check the client’s logs and increase timeout in its config. Also verify the server’s working directory—relative paths may differ.
  • Prompt injection bypasses approval: If the AI model is tricked into calling a tool that you approved once, the client may auto-approve subsequent calls. Set “ask every time” instead of “ask once per session,” and consider using a client that supports per-tool approval lists.

Frequently Asked Questions

Q: Do I need a separate user account for every MCP server?
A: Not strictly, but it’s the safest. If you run multiple servers, isolate them from each other so one compromised server can’t read another’s files or credentials.

Q: Can I use MCP with a remote AI service safely?
A: Yes, but the server runs locally. The risk is that the AI’s responses are untrusted—treat any tool call as potentially malicious. The approval step is your main defense.

Q: What’s the difference between stdio and TCP transport for security?
A: stdio is a local pipe—only the parent process can talk to it. TCP opens a network port, which any local process (or remote if bound to 0.0.0.0) can reach. Prefer stdio.

Q: How do I revoke Screen Recording permission from an MCP server?
A: Go to System Settings → Privacy & Security → Screen Recording, find the server’s name, and toggle it off. The server will stop receiving screen content immediately.

Q: Is it safe to grant Accessibility to an MCP server that controls my browser?
A: It’s a high-risk permission because it can read any text on screen and send keystrokes. Only grant it if the server is from a trusted source, and combine it with the approval step for every action.

Q: Can I run MCP servers in a Docker container on macOS?
A: Yes, but Docker Desktop’s VM adds complexity—you’ll need to map ports and share folders. For most local control tasks, the sandboxed user approach is simpler and uses fewer resources.

Q: What should I do if I suspect my MCP server was compromised?
A: Immediately kill the process, revoke all TCC permissions it had, change any API keys it used, and review its logs for unusual file reads or network connections. Then reinstall from a trusted source.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →