Skip to main content

Production-ready MCP server for TrueNAS Core - Control your NAS through natural language

Project description

TrueNAS MCP Server

Python Version MCP Version License PyPI Version

A production-ready Model Context Protocol (MCP) server for TrueNAS Core systems. Control and manage your TrueNAS storage through natural language with Claude or other MCP-compatible clients.

๐Ÿš€ Features

Core Capabilities

  • User Management - Create, update, delete users and manage permissions
  • Storage Management - Manage pools, datasets, volumes with full ZFS support
  • File Sharing - Configure SMB, NFS, and iSCSI shares
  • Snapshot Management - Create, delete, rollback snapshots with automation
  • System Monitoring - Check system health, pool status, and resource usage

Enterprise Features

  • Type-Safe Operations - Full Pydantic models for request/response validation
  • Comprehensive Error Handling - Detailed error messages and recovery guidance
  • Production Logging - Structured logging with configurable levels
  • Connection Pooling - Efficient HTTP connection management with retry logic
  • Rate Limiting - Built-in rate limiting to prevent API abuse
  • Environment-Based Config - Flexible configuration via environment variables

๐Ÿ“ฆ Installation

From PyPI (Recommended)

pip install truenas-mcp-server

From Source

git clone https://github.com/vespo92/TrueNasCoreMCP.git
cd TrueNasCoreMCP
pip install -e .

๐Ÿ”ง Configuration

Environment Variables

Create a .env file or set environment variables:

# Required
TRUENAS_URL=https://your-truenas-server.local
TRUENAS_API_KEY=your-api-key-here

# Optional
TRUENAS_VERIFY_SSL=true                    # Verify SSL certificates
TRUENAS_LOG_LEVEL=INFO                     # Logging level
TRUENAS_ENV=production                     # Environment (development/staging/production)
TRUENAS_HTTP_TIMEOUT=30                    # HTTP timeout in seconds
TRUENAS_ENABLE_DESTRUCTIVE_OPS=false      # Enable delete operations
TRUENAS_ENABLE_DEBUG_TOOLS=false          # Enable debug tools

Getting Your API Key

  1. Log into TrueNAS Web UI
  2. Go to Settings โ†’ API Keys
  3. Click Add and create a new API key
  4. Copy the key immediately (it won't be shown again)

Claude Desktop Configuration

  1. Install the package via pip (in Claude Desktop's Python environment):
pip install truenas-mcp-server
  1. Add to your Claude Desktop config (claude_desktop_config.json):
{
  "mcpServers": {
    "truenas": {
      "command": "python",
      "args": ["-m", "truenas_mcp_server"],
      "env": {
        "TRUENAS_URL": "https://your-truenas-server.local",
        "TRUENAS_API_KEY": "your-api-key-here",
        "TRUENAS_VERIFY_SSL": "false"
      }
    }
  }
}

Note: Make sure to install the package in the same Python environment that Claude Desktop uses.

๐Ÿ“š Usage Examples

With Claude Desktop

Once configured, you can interact with TrueNAS using natural language:

"List all storage pools and their health status"
"Create a new dataset called 'backups' in the tank pool with compression"
"Set up an SMB share for the documents dataset"
"Create a snapshot of all datasets in the tank pool"
"Show me users who have sudo privileges"

As a Python Library

from truenas_mcp_server import TrueNASMCPServer

# Create server instance
server = TrueNASMCPServer()

# Run the server
server.run()

Programmatic Usage

import asyncio
from truenas_mcp_server.client import TrueNASClient
from truenas_mcp_server.config import Settings

async def main():
    # Initialize client
    settings = Settings(
        truenas_url="https://truenas.local",
        truenas_api_key="your-api-key"
    )
    
    async with TrueNASClient(settings) as client:
        # List pools
        pools = await client.get("/pool")
        print(f"Found {len(pools)} pools")
        
        # Create a dataset
        dataset = await client.post("/pool/dataset", {
            "name": "tank/mydata",
            "compression": "lz4"
        })
        print(f"Created dataset: {dataset['name']}")

asyncio.run(main())

๐Ÿ› ๏ธ Available Tools

User Management

  • list_users - List all users with details
  • get_user - Get specific user information
  • create_user - Create new user account
  • update_user - Modify user properties
  • delete_user - Remove user account

Storage Management

  • list_pools - Show all storage pools
  • get_pool_status - Detailed pool health and statistics
  • list_datasets - List all datasets
  • create_dataset - Create new dataset with options
  • update_dataset - Modify dataset properties
  • delete_dataset - Remove dataset

File Sharing

  • list_smb_shares - Show SMB/CIFS shares
  • create_smb_share - Create Windows share
  • list_nfs_exports - Show NFS exports
  • create_nfs_export - Create NFS export
  • list_iscsi_targets - Show iSCSI targets
  • create_iscsi_target - Create iSCSI target

Snapshot Management

  • list_snapshots - Show snapshots
  • create_snapshot - Create manual snapshot
  • delete_snapshot - Remove snapshot
  • rollback_snapshot - Revert to snapshot
  • clone_snapshot - Clone to new dataset
  • create_snapshot_task - Setup automated snapshots

Debug Tools (Development Mode)

  • debug_connection - Check connection settings
  • test_connection - Verify API connectivity
  • get_server_stats - Server statistics

๐Ÿ—๏ธ Architecture

truenas_mcp_server/
โ”œโ”€โ”€ __init__.py           # Package initialization
โ”œโ”€โ”€ server.py             # Main MCP server
โ”œโ”€โ”€ config/               # Configuration management
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ””โ”€โ”€ settings.py       # Pydantic settings
โ”œโ”€โ”€ client/               # HTTP client
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ””โ”€โ”€ http_client.py    # Async HTTP with retry
โ”œโ”€โ”€ models/               # Data models
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ base.py          # Base models
โ”‚   โ”œโ”€โ”€ user.py          # User models
โ”‚   โ”œโ”€โ”€ storage.py       # Storage models
โ”‚   โ””โ”€โ”€ sharing.py       # Share models
โ”œโ”€โ”€ tools/                # MCP tools
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ base.py          # Base tool class
โ”‚   โ”œโ”€โ”€ users.py         # User tools
โ”‚   โ”œโ”€โ”€ storage.py       # Storage tools
โ”‚   โ”œโ”€โ”€ sharing.py       # Share tools
โ”‚   โ””โ”€โ”€ snapshots.py     # Snapshot tools
โ””โ”€โ”€ exceptions.py         # Custom exceptions

๐Ÿงช Development

Setup Development Environment

# Clone repository
git clone https://github.com/vespo92/TrueNasCoreMCP.git
cd TrueNasCoreMCP

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install in development mode
pip install -e ".[dev]"

Running Tests

# Run all tests
pytest

# With coverage
pytest --cov=truenas_mcp_server

# Specific test file
pytest tests/test_client.py

Code Quality

# Format code
black truenas_mcp_server

# Lint
flake8 truenas_mcp_server

# Type checking
mypy truenas_mcp_server

๐Ÿค Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ”’ Security

  • Never commit API keys or credentials
  • Use environment variables for sensitive data
  • Enable SSL verification in production
  • Restrict destructive operations by default
  • Report security issues to vespo21@gmail.com

๐Ÿ“ž Support

๐Ÿ™ Acknowledgments


Made with โค๏ธ for the TrueNAS community

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

truenas_mcp_server-3.0.0.tar.gz (55.9 kB view details)

Uploaded Source

Built Distribution

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

truenas_mcp_server-3.0.0-py3-none-any.whl (37.0 kB view details)

Uploaded Python 3

File details

Details for the file truenas_mcp_server-3.0.0.tar.gz.

File metadata

  • Download URL: truenas_mcp_server-3.0.0.tar.gz
  • Upload date:
  • Size: 55.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for truenas_mcp_server-3.0.0.tar.gz
Algorithm Hash digest
SHA256 53ff85b4392f02bddfadfc9720d2825c93aa6dac3ac45443a9d2b2228902deee
MD5 dfdd2bf564bb1e31ee64faef9e18c75a
BLAKE2b-256 7e85652e3fbb16b0b5853a84444b888e27cd27d504bcb15ac81723aed2f77dac

See more details on using hashes here.

File details

Details for the file truenas_mcp_server-3.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for truenas_mcp_server-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 922baeb30091236501051889a98344546d108371ff53861e1a2cb9dec72848f6
MD5 42b92519aa560aac461e2ad724cf1a97
BLAKE2b-256 caef1b347858f4930d29b75b777d9e843fc08d78bd33656e61511e1d8b9a6ef4

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