A security-focused MCP server for performing safe operations on an Ubuntu system, featuring robust security controls and audit logging.
๐ Security-First Model Context Protocol server for safe Ubuntu system operations
A hardened, production-ready Model Context Protocol (MCP) server that provides AI assistants with secure, controlled access to Ubuntu system operations. Built with comprehensive security controls, audit logging, and defense-in-depth principles.
# Clone the repository
git clone https://github.com/yourusername/secure-ubuntu-mcp.git
cd secure-ubuntu-mcp
# Create and activate virtual environment
python3 -m venv .venv
source .venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Verify installation with built-in tests
python main.py --test
# Start with secure policy (recommended)
python main.py --policy secure
# Start with development policy (more permissive)
python main.py --policy dev
# Test security measures
python main.py --security-test
Official Support: Claude Desktop doesn't officially support Linux, but the community has created solutions!
Recommended Method: Use the community Debian package by @aaddrick:
# Download and install Claude Desktop for Linux
wget https://github.com/aaddrick/claude-desktop-debian/releases/latest/download/claude-desktop_latest_amd64.deb
sudo dpkg -i claude-desktop_latest_amd64.deb
sudo apt-get install -f # Fix any dependency issues
For other methods and troubleshooting, see: https://github.com/aaddrick/claude-desktop-debian
Once Claude Desktop is installed, add to your configuration (~/.config/claude-desktop/claude_desktop_config.json
):
{
"mcpServers": {
"secure-ubuntu": {
"command": "/path/to/secure-ubuntu-mcp/.venv/bin/python3",
"args": ["/path/to/secure-ubuntu-mcp/main.py", "--policy", "secure"],
"env": {
"MCP_LOG_LEVEL": "INFO"
}
}
}
}
โ ๏ธ Important: Use absolute paths and the virtual environment Python interpreter
Verification: After restarting Claude Desktop, you should see "secure-ubuntu" listed as a connected server, and Claude will have access to system control tools.
The server implements the standard MCP protocol and works with any MCP-compatible client:
# Example with mcp Python client
import asyncio
from mcp.client import ClientSession
async def example():
# Connect to the server
# Implementation depends on your MCP client
pass
Recommended for production and untrusted environments:
~/
, /tmp
, /var/tmp
/etc
, /root
, /boot
, /sys
, /proc
, /dev
, /usr
, /bin
, /sbin
ls
, cat
, echo
, pwd
, whoami
, date
, find
, grep
, apt
(search only)More permissive for development environments:
/opt
, /usr/local
Create your own security policy:
from main import SecurityPolicy
custom_policy = SecurityPolicy(
allowed_paths=["/your/custom/paths"],
forbidden_paths=["/sensitive/areas"],
allowed_commands=["safe", "commands"],
forbidden_commands=["dangerous", "commands"],
max_command_timeout=30,
allow_sudo=False, # Use with extreme caution
audit_actions=True
)
list_directory(path)
- List directory contents with metadataread_file(file_path)
- Read file contents with size validationwrite_file(file_path, content, create_dirs=False)
- Write with atomic operationsexecute_command(command, working_dir=None)
- Execute shell commands safelyget_system_info()
- Get OS, memory, and disk informationsearch_packages(query)
- Search APT repositoriesinstall_package(package_name)
- Check package availability (listing only)Path Traversal Prevention:
# These are all blocked:
../../../etc/passwd
/etc/passwd
/tmp/../etc/passwd
symlinks_to_sensitive_files
Command Injection Prevention:
# These are all blocked:
echo hello; rm -rf /
echo `cat /etc/passwd`
echo $(whoami)
ls | rm -rf /
Resource Exhaustion Protection:
All operations are logged with:
# Test core functionality
python main.py --test
# Run comprehensive security tests
python main.py --security-test
# Test MCP protocol directly
python test_client.py --simple
Once integrated with an AI assistant:
System Monitoring:
"Check my system status and disk space"
File Management:
"List the files in my home directory and show me the largest ones"
Development Tasks:
"Check if Python is installed and show me the version"
Log Analysis:
"Look for any error files in my project directory"
MCP_LOG_LEVEL
- Logging level (DEBUG, INFO, WARNING, ERROR)MCP_POLICY
- Security policy (secure, dev)MCP_CONFIG_PATH
- Path to custom configuration fileCreate config.json
for custom settings:
{
"server": {
"name": "secure-ubuntu-controller",
"version": "1.0.0",
"log_level": "INFO"
},
"security": {
"policy_name": "secure",
"allowed_paths": ["~/", "/tmp"],
"max_command_timeout": 30,
"allow_sudo": false,
"audit_actions": true
}
}
@mcp.tool("your_tool_name")
async def your_tool(param: str) -> str:
"""Tool description for AI assistant"""
try:
# Use controller methods for safe operations
result = controller.safe_operation(param)
return json.dumps(result, indent=2)
except Exception as e:
return json.dumps({"error": str(e)}, indent=2)
def create_custom_policy() -> SecurityPolicy:
"""Create a custom security policy"""
return SecurityPolicy(
allowed_paths=["/your/paths"],
forbidden_commands=["dangerous", "commands"],
# ... other settings
)
"Server appears to hang"
"ModuleNotFoundError: No module named 'mcp'"
.venv/bin/python3
"SecurityViolation" errors
/tmp/ubuntu_mcp_audit.log
"Permission denied" errors
ls -la
# Enable verbose logging
python main.py --log-level DEBUG --policy secure
# Check audit logs
tail -f /tmp/ubuntu_mcp_audit.log
We welcome contributions! Please see our Contributing Guidelines for details.
git checkout -b feature/amazing-feature
python main.py --test && python main.py --security-test
This project is licensed under the MIT License - see the LICENSE file for details.
If you discover a security vulnerability, please email [radjackbartok@proton.me] instead of creating a public issue. We take security seriously and will respond promptly.
Made for the security-conscious AI community
๐ก Pro Tip: Start with the secure policy and gradually increase permissions as needed. It's easier to add permissions than to recover from a security incident!
Interact with the Eyevinn Open Source Cloud API. Requires a Personal Access Token (OSC_ACCESS_TOKEN).
APISIX Model Context Protocol (MCP) server is used to bridge large language models (LLMs) with the APISIX Admin API, supporting querying and managing all resources in Apache APISIX.
An MCP server for interacting with the Kayzen Analytics API, requiring credentials configured via environment variables.
A self-hostable MCP server for Cloudflare Workers with OAuth login support, using Cloudflare KV for storage.
Official Hostinger API MCP server for services managment.
Interact with your AWS environment using natural language to query and manage resources. Requires local AWS credentials.
A remote MCP server deployable on Cloudflare Workers without authentication.
Query OpenAI models directly from Claude using MCP protocol
Connect to Kubernetes cluster and manage pods, deployments, services.
An MCP server for processing payments using stdio transport, configured via environment variables.