Skip to main content
Glama
Oraforge Linux MCP

Oraforge Linux MCP

by SK108045
README.md
# Oraforge Linux MCP

Remote Linux administration over the Model Context Protocol (MCP).

This service runs **on the Linux host it controls** and exposes a remote MCP endpoint over Streamable HTTP. It does not SSH back into the same machine and does not need an SSH private key. The `run_command` tool executes Bash commands as the operating-system account running the service.

> **Root means root.** When the systemd unit runs as `root`, every connected and authorized AI client can execute unrestricted root commands: read/write files, install packages, inspect processes, restart services, change firewall rules, and modify or delete the operating system. Connect only clients and accounts you trust.

## Features

- Full Bash command execution with stdout, stderr, exit code and elapsed time
- Configurable working directory and per-command timeout
- Process-group termination when a command times out
- Bounded command length and returned output size
- Host overview (OS, kernel, hostname, uptime, current service user, root status and disk space)
- Remote MCP over Streamable HTTP at `/mcp`
- OAuth 2.1 authorization with PKCE and Dynamic Client Registration (DCR)
- Owner-passphrase approval page; no static API key is required
- Access/refresh tokens stored as SHA-256 hashes in SQLite; refresh-token rotation and revocation
- Audit log records timestamp, OS user, working directory, exit code, duration and command hash — **not the command text or output**
- Local MCP stdio mode for development

## Important architecture detail

If you install this MCP directly on your target Linux server, the process already runs on that host. Calling `run_command` executes a local shell there. Your SSH private key is not needed by this application and must never be copied into this repository or its `.env` file.

If you later host this MCP on a different machine, that becomes a different architecture and should use a dedicated SSH identity with limited privileges. Do not reuse an exposed private key.

## Requirements

- Ubuntu or another Linux distribution with Bash
- Python 3.11+
- A public DNS hostname pointing to the server
- HTTPS reverse proxy (Nginx + Certbot is documented below)
- A persistent writable directory for OAuth state and audit logs

## Local setup

```bash
git clone https://github.com/SK108045/Linux_MCP.git
cd Linux_MCP
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
pip install -e ".[dev]"
cp .env.example .env
chmod 600 .env
```

Edit `.env`. Generate a dedicated OAuth owner passphrase:

```bash
openssl rand -base64 32
```

Set the public URL and allowed host to the DNS name you configure. Do not use the bare IP address for OAuth.

## Deploy on your server

Recommended hostname: `linux-mcp.oraforgetech.com` (create an A record pointing to your server's public IP). You can use another domain, but `MCP_PUBLIC_URL`, `MCP_ALLOWED_HOSTS`, Nginx and the OAuth redirect allowlist must agree.

### 1. Install the application

The deployment below uses a native systemd service, not Docker. This is intentional: the MCP must run in the host namespace to administer the host itself.

```bash
sudo git clone https://github.com/SK108045/Linux_MCP.git /opt/linux-mcp
cd /opt/linux-mcp
sudo python3 -m venv .venv
sudo .venv/bin/python -m pip install --upgrade pip
sudo .venv/bin/pip install .
```

Copy and protect the environment file:

```bash
sudo cp .env.example .env
sudo chmod 600 .env
sudo nano .env
```

Set at least:

```env
MCP_TRANSPORT=streamable-http
MCP_HOST=127.0.0.1
MCP_PORT=5000
MCP_PUBLIC_URL=https://linux-mcp.oraforgetech.com
MCP_ALLOWED_HOSTS=linux-mcp.oraforgetech.com
OAUTH_OWNER_PASSWORD=<output from openssl rand -base64 32>
OAUTH_ALLOWED_REDIRECT_HOSTS=chatgpt.com,chat.openai.com,platform.openai.com,claude.ai,localhost,127.0.0.1,gemini.google.com,aistudio.google.com
OAUTH_DB_PATH=/opt/linux-mcp/data/oauth.sqlite3
COMMAND_AUDIT_LOG=/opt/linux-mcp/data/command_audit.jsonl
```

The owner passphrase is separate from Linux, SSH and GitHub credentials. Never commit `.env`.

### 2. Install systemd service

```bash
sudo cp deploy/linux-mcp.service /etc/systemd/system/linux-mcp.service
sudo systemctl daemon-reload
sudo systemctl enable --now linux-mcp
sudo systemctl status linux-mcp
sudo journalctl -u linux-mcp -f
```

The included unit runs as root so the shell tool has root permissions. The service binds to `127.0.0.1:5000`; it is not directly exposed to the internet.

### 3. Configure Nginx and TLS

```bash
sudo cp deploy/nginx-linux-mcp.conf /etc/nginx/sites-available/linux-mcp
sudo ln -s /etc/nginx/sites-available/linux-mcp /etc/nginx/sites-enabled/linux-mcp
sudo nginx -t
sudo systemctl reload nginx
sudo certbot --nginx -d linux-mcp.oraforgetech.com
```

Allow inbound ports 80 and 443. Do **not** open port 5000 publicly. Nginx forwards HTTPS requests to the local application port and preserves streaming responses.

Check:

```bash
curl -fsS https://linux-mcp.oraforgetech.com/health
curl -fsS https://linux-mcp.oraforgetech.com/.well-known/oauth-authorization-server
```

Expected health response:

```json
{"status":"ok","service":"ora-forge-linux-mcp"}
```

MCP endpoint:

`https://linux-mcp.oraforgetech.com/mcp`

## Connect AI clients

All clients connect to the same remote MCP endpoint and receive the same two tools. Each client completes OAuth independently. Approving a client grants it the ability to run unrestricted commands with the service's Linux permissions.

### ChatGPT

1. Open ChatGPT's custom MCP server / connector settings.
2. Add the server URL shown above, including `/mcp`.
3. Choose OAuth authentication.
4. Complete the owner-passphrase approval page.
5. Confirm the tools `get_host_info` and `run_command` appear.

### Claude

1. Open **Customize → Connectors → Add custom connector** (the menu can vary by plan).
2. Enter the remote MCP URL ending in `/mcp`.
3. Select OAuth.
4. Choose **Register automatically (DCR)** / automatic registration.
5. Complete the owner-passphrase approval page.

For a manually registered Claude OAuth client, add `https://claude.ai/api/mcp/auth_callback` as its redirect URI and ensure `claude.ai` is in `OAUTH_ALLOWED_REDIRECT_HOSTS`.

### Gemini CLI

Gemini CLI supports OAuth discovery for remote MCP servers over HTTP. Add this server to `~/.gemini/settings.json` under `mcpServers`:

```json
{
  "mcpServers": {
    "linux-server": {
      "url": "https://linux-mcp.oraforgetech.com/mcp"
    }
  }
}
```

Restart Gemini CLI, inspect `/mcp`, and complete the browser OAuth flow when prompted. OAuth browser callbacks need a browser-capable local environment; a headless shell without a browser callback may not complete the interactive flow.

**Gemini CLI is the confirmed Google client path documented here.** Do not assume that every Gemini web/app surface currently exposes arbitrary custom remote MCP connectors.

## Tool reference

### `get_host_info()`

Returns hostname, OS, kernel, Python version, uptime, current OS user, whether the process is root, and filesystem usage for `/`.

### `run_command(command, working_directory="", timeout_seconds=120)`

Runs the supplied command through Bash login-shell mode.

Parameters:

- `command` (required): complete Bash command or script
- `working_directory` (optional): absolute or relative directory on the server; defaults to the process working directory
- `timeout_seconds` (optional): defaults to 120; maximum controlled by `COMMAND_MAX_TIMEOUT_SECONDS`

The response includes `exit_code`, `stdout`, `stderr`, `timed_out`, `duration_seconds` and `output_truncated`. A non-zero exit code is a command failure; the tool returns the result rather than hiding it.

Examples:

- `whoami && id`
- `df -h && free -h`
- `systemctl status nginx --no-pager`
- `journalctl -u linux-mcp -n 100 --no-pager`
- `find /var/log -maxdepth 2 -type f`
- `apt update`

Commands execute non-interactively; commands that require a password prompt or TTY need a non-interactive equivalent.

## Operational notes

- The OAuth login is intentionally single-owner. Anyone who knows the owner passphrase can approve a client. All approved clients receive equivalent shell permissions.
- OAuth access tokens expire; refresh tokens rotate. The OAuth database must persist across restarts.
- Revoke a client by disconnecting it in the AI client and/or using OAuth token revocation. Deleting `data/oauth.sqlite3` revokes all registered clients and sessions.
- `COMMAND_AUDIT_LOG` records command hashes and metadata, not raw command contents, to avoid recording embedded secrets. Protect this file because it reveals administrative activity.
- Keep the application port private behind HTTPS. Never expose unauthenticated shell execution.
- The command timeout is a limit on the foreground process group, not a security sandbox. A command can intentionally launch detached processes.
- This is a superuser administration interface, not a multi-tenant product. Do not expose it to customers or share the owner passphrase.
- Review every command and its output. An AI can be manipulated by malicious content it reads from the server; prompt injection can cause it to suggest or execute dangerous commands.

## Development and tests

```bash
python -m pip install -e ".[dev]"
ruff check src tests
pytest
```

CI runs Ruff and Pytest on Python 3.11 and 3.12.

## License

MIT