Skip to main content

MCP server for managing BTRFS snapshots via Snapper

Project description

BTRFS Snapper MCP

Built with Claude Code

An MCP (Model Context Protocol) server for managing BTRFS snapshots via Snapper and monitoring BTRFS filesystem health. Exposes two unified tools with action-based dispatch to minimize tool proliferation while providing full snapshot management and disk health monitoring.

Features

  • Two-tool design: snapper for snapshots, btrfs_health for filesystem monitoring
  • Full Snapper support: list, create, delete, rollback, cleanup, diff, status
  • BTRFS health monitoring: usage, device stats, scrub status, balance status
  • Flexible configuration: Environment variables for cross-system portability
  • No hardcoded paths: Works with any Snapper configuration and mount points

Installation

Using uv (recommended)

cd /path/to/BTRFS-Snapper-MCP
uv venv
source .venv/bin/activate
uv pip install -e .

Using pip

pip install -e .

Configuration

The server is configured via environment variables, making it portable across systems:

Variable Default Description
SNAPPER_MCP_USE_SUDO true Set to false if user has direct permissions
SNAPPER_MCP_SNAPPER_PATH snapper Path to snapper binary
SNAPPER_MCP_BTRFS_PATH btrfs Path to btrfs binary
SNAPPER_MCP_SUDO_PATH sudo Path to sudo binary
SNAPPER_MCP_DEFAULT_CONFIG root Default snapper config name
SNAPPER_MCP_DEFAULT_MOUNT / Default BTRFS mount point
SNAPPER_MCP_TIMEOUT 60 Command timeout in seconds

MCP Client Configuration

Claude Code / Claude Desktop

Add to your MCP settings (e.g., ~/.claude/settings.json or Claude Desktop config):

{
  "mcpServers": {
    "btrfs-snapper": {
      "command": "/path/to/BTRFS-Snapper-MCP/.venv/bin/snapper-mcp",
      "env": {
        "SNAPPER_MCP_DEFAULT_CONFIG": "root",
        "SNAPPER_MCP_DEFAULT_MOUNT": "/",
        "SNAPPER_MCP_USE_SUDO": "true"
      }
    }
  }
}

With uvx (no local install)

{
  "mcpServers": {
    "btrfs-snapper": {
      "command": "uvx",
      "args": ["--from", "git+https://github.com/danielrosehill/BTRFS-Snapper-MCP", "snapper-mcp"],
      "env": {
        "SNAPPER_MCP_DEFAULT_CONFIG": "root",
        "SNAPPER_MCP_DEFAULT_MOUNT": "/"
      }
    }
  }
}

Tools

snapper - Snapshot Management

Manages BTRFS snapshots via Snapper.

Actions

Action Description Required Parameters
configs List available snapper configurations -
list Show all snapshots for a config config (optional)
create Create a new snapshot config, description (optional)
delete Remove a snapshot by number config, snapshot_id
rollback Restore to a previous snapshot config, snapshot_id
cleanup Prune snapshots using an algorithm config, cleanup_algorithm
diff Show file differences between snapshots config, snapshot_id, snapshot_id_end
status List changed files between snapshots config, snapshot_id, snapshot_id_end

Examples

// List configurations
{"action": "configs"}

// List snapshots
{"action": "list", "config": "root"}

// Create snapshot
{"action": "create", "config": "root", "description": "Before system update"}

// Delete snapshot
{"action": "delete", "config": "root", "snapshot_id": 5}

// Rollback (requires reboot)
{"action": "rollback", "config": "root", "snapshot_id": 3}

// Cleanup with algorithm
{"action": "cleanup", "config": "root", "cleanup_algorithm": "number"}

// Compare snapshots
{"action": "diff", "config": "root", "snapshot_id": 1, "snapshot_id_end": 5}

Cleanup algorithms:

  • number: Keep a fixed number of snapshots
  • timeline: Keep snapshots based on age (hourly, daily, weekly, monthly, yearly)
  • empty-pre-post: Remove empty pre/post snapshot pairs

btrfs_health - Filesystem Health Monitoring

Monitors BTRFS filesystem health and status.

Actions

Action Description Parameters
usage Comprehensive filesystem space usage mount_point (optional)
devices List devices in the BTRFS array mount_point (optional)
stats Device error statistics mount_point, device (optional)
scrub_status Status of scrub operation mount_point (optional)
balance_status Status of balance operation mount_point (optional)
df Space allocation by data type mount_point (optional)
filesystem_show Filesystem information mount_point (optional)

Examples

// Check filesystem usage
{"action": "usage", "mount_point": "/"}

// Check for device errors
{"action": "stats", "mount_point": "/"}

// Check scrub status
{"action": "scrub_status", "mount_point": "/"}

// Show data/metadata allocation
{"action": "df", "mount_point": "/"}

// Show filesystem info
{"action": "filesystem_show"}

Prerequisites

  • Linux with BTRFS filesystem
  • Snapper installed and configured (for snapshot management)
  • Python 3.10+
  • Sudo access (unless running as root or with appropriate permissions)

Installing Snapper

Ubuntu/Debian:

sudo apt install snapper

Fedora/openSUSE:

sudo dnf install snapper
# or
sudo zypper install snapper

Creating Snapper Configs

# For root filesystem
sudo snapper -c root create-config /

# For home partition
sudo snapper -c home create-config /home

Sudo Configuration

For passwordless operation, add to /etc/sudoers.d/btrfs-snapper:

yourusername ALL=(ALL) NOPASSWD: /usr/bin/snapper
yourusername ALL=(ALL) NOPASSWD: /usr/bin/btrfs

Or disable sudo if you have direct permissions:

{
  "env": {
    "SNAPPER_MCP_USE_SUDO": "false"
  }
}

Adapting for Other Systems

Different Snapshot Tools

The architecture can be adapted for other snapshot tools (e.g., Timeshift, ZFS snapshots) by:

  1. Replacing the run_snapper_command() function with your tool's CLI
  2. Adjusting the action handlers for your tool's command syntax
  3. Updating environment variables as needed

Different Filesystems

For ZFS or other filesystems:

  1. Replace run_btrfs_command() with your filesystem's CLI
  2. Update BtrfsAction enum with relevant actions
  3. Implement new handlers for your filesystem's commands

The action-dispatch pattern remains the same regardless of underlying tools.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

snapper_mcp-0.1.0.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

snapper_mcp-0.1.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file snapper_mcp-0.1.0.tar.gz.

File metadata

  • Download URL: snapper_mcp-0.1.0.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.8

File hashes

Hashes for snapper_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ee1032dd3c9a966205705a3415605dea2f4439fc2eaa124a2c45cfc70f578445
MD5 d7d6026c7c4b2726032c0cba46215e03
BLAKE2b-256 7c11b16d191a54c06d8881bee8d3fbc5057aee537f347b0184d864ceee3eaa56

See more details on using hashes here.

File details

Details for the file snapper_mcp-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for snapper_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b71bd7a2a8723c8e905d6c8781f8c05d60e151af5e7b5f4f41e76a665a478225
MD5 e2bb248a0e7a4dbc6125099aa6ca4fbc
BLAKE2b-256 689cd1a41705c693cda95d579ff1fefe2adc0484900d3a8d0d4171f801956e82

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page