Production-ready MCP server for TrueNAS Core - Control your NAS through natural language
Project description
TrueNAS MCP Server
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
- Log into TrueNAS Web UI
- Go to Settings โ API Keys
- Click Add and create a new API key
- Copy the key immediately (it won't be shown again)
Claude Desktop Configuration
- Install the package via pip (in Claude Desktop's Python environment):
pip install truenas-mcp-server
- 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 detailsget_user- Get specific user informationcreate_user- Create new user accountupdate_user- Modify user propertiesdelete_user- Remove user account
Storage Management
list_pools- Show all storage poolsget_pool_status- Detailed pool health and statisticslist_datasets- List all datasetscreate_dataset- Create new dataset with optionsupdate_dataset- Modify dataset propertiesdelete_dataset- Remove dataset
File Sharing
list_smb_shares- Show SMB/CIFS sharescreate_smb_share- Create Windows sharelist_nfs_exports- Show NFS exportscreate_nfs_export- Create NFS exportlist_iscsi_targets- Show iSCSI targetscreate_iscsi_target- Create iSCSI target
Snapshot Management
list_snapshots- Show snapshotscreate_snapshot- Create manual snapshotdelete_snapshot- Remove snapshotrollback_snapshot- Revert to snapshotclone_snapshot- Clone to new datasetcreate_snapshot_task- Setup automated snapshots
Debug Tools (Development Mode)
debug_connection- Check connection settingstest_connection- Verify API connectivityget_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.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - 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
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: vespo21@gmail.com
๐ Acknowledgments
- Anthropic for the MCP specification
- TrueNAS for the excellent storage platform
- MCP Python SDK contributors
Made with โค๏ธ for the TrueNAS community
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53ff85b4392f02bddfadfc9720d2825c93aa6dac3ac45443a9d2b2228902deee
|
|
| MD5 |
dfdd2bf564bb1e31ee64faef9e18c75a
|
|
| BLAKE2b-256 |
7e85652e3fbb16b0b5853a84444b888e27cd27d504bcb15ac81723aed2f77dac
|
File details
Details for the file truenas_mcp_server-3.0.0-py3-none-any.whl.
File metadata
- Download URL: truenas_mcp_server-3.0.0-py3-none-any.whl
- Upload date:
- Size: 37.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
922baeb30091236501051889a98344546d108371ff53861e1a2cb9dec72848f6
|
|
| MD5 |
42b92519aa560aac461e2ad724cf1a97
|
|
| BLAKE2b-256 |
caef1b347858f4930d29b75b777d9e843fc08d78bd33656e61511e1d8b9a6ef4
|