linux-mcp-server

linux-mcp-server

An MCP server for managing Ubuntu/Linux systems, enabling AI assistants to execute commands, manage services, files, logs, and packages via local or SSH connection.

Category
访问服务器

README

linux-mcp-server

An MCP (Model Context Protocol) server for managing Ubuntu/Linux systems. Gives AI assistants like Claude direct access to system information, processes, services, files, logs, and package management — either on the local machine or a remote host via SSH.

License: MIT Version


What is this?

MCP is an open standard that lets AI assistants use tools — structured actions they can call to read data and take actions on real systems. Instead of copy-pasting terminal output into a chat window, an MCP server lets the AI query your system directly and act on what it finds.

linux-mcp-server exposes your Linux system as a set of MCP tools. You can point it at the machine it's running on (local mode) or at a remote host over SSH. Run one instance per host you want to manage.

Practical example: Rather than asking "how do I check if nginx is running?", your AI assistant can just check, see that it's failed, read the journal logs, and restart it — all without you copying a single line of output.


Features

Category Tools
Shell Run arbitrary commands, run with sudo
System Hostname/OS info, CPU usage, memory usage, disk usage, network interfaces
Processes List processes, get process details, top CPU/memory consumers, kill process
Services List systemd services, status, start, stop, restart, enable, disable
Files Read, write, list directory, file info, create directory, delete
Logs Journal logs (with filters), tail log files, search journal by pattern
Packages List installed, search, show details, install, remove, apt update, upgrade

Quick Start

Option 1 — Clone and build

git clone https://github.com/szoran53/linux-mcp-server.git
cd linux-mcp-server
npm install
npm run build

The built binary is at dist/index.js. You can also run it via:

node dist/index.js

Option 2 — Global install from source

npm install -g .
linux-mcp-server

Configuration

All configuration is via environment variables.

Core

Variable Default Description
LOCAL_MODE false Set to true to manage the local machine directly (no SSH)
TRANSPORT stdio Transport mode: stdio or http
MCP_HTTP_PORT 3300 HTTP port (when TRANSPORT=http)
MCP_HTTP_HOST 127.0.0.1 HTTP bind address (when TRANSPORT=http)
COMMAND_TIMEOUT_MS 30000 Max time (ms) for any single command
LOG_PATHS /var/log Comma-separated list of allowed log file path prefixes

SSH mode only

Variable Required Default Description
SSH_HOST Yes Remote host IP or hostname
SSH_USER Yes SSH username
SSH_PORT No 22 SSH port
SSH_KEY_PATH No ~/.ssh/id_rsa Path to private key
SSH_STRICT_HOST_CHECK No true Set to false to skip host key verification

Sudo

Variable Description
SUDO_PASSWORD Optional. Provide if the SSH user requires a password for sudo. Not needed if the user has passwordless sudo.

Modes

Local mode

Runs on the machine you want to manage. Commands execute directly — no SSH involved. Ideal for running as a systemd service on each host.

LOCAL_MODE=true TRANSPORT=http MCP_HTTP_PORT=3300 node dist/index.js

SSH mode

Connects to a remote host over SSH. Run the server anywhere (your workstation, a management box) and point it at a target.

SSH_HOST=192.168.1.50 \
SSH_USER=admin \
SSH_KEY_PATH=~/.ssh/id_ed25519 \
TRANSPORT=http \
MCP_HTTP_PORT=3301 \
node dist/index.js

Run multiple instances on different ports to manage multiple hosts simultaneously.


Running as a systemd service

The recommended approach for homelab use is a systemd user service — it runs under your user account, starts on boot, and restarts automatically.

1. Create the service file

Copy the example from the repo:

mkdir -p ~/.config/systemd/user
cp examples/mcp-linux-local.service ~/.config/systemd/user/

Or create ~/.config/systemd/user/mcp-linux-local.service:

[Unit]
Description=Linux MCP Server (local - this machine)
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/linux-mcp-server
Restart=always
RestartSec=5

Environment=LOCAL_MODE=true
Environment=TRANSPORT=http
Environment=MCP_HTTP_PORT=3300
Environment=MCP_HTTP_HOST=127.0.0.1

[Install]
WantedBy=default.target

Update ExecStart to match where your binary is (which linux-mcp-server).

2. Enable and start

systemctl --user daemon-reload
systemctl --user enable mcp-linux-local.service
systemctl --user start mcp-linux-local.service
systemctl --user status mcp-linux-local.service

3. Enable linger (survive logout/reboot)

User services stop when you log out unless linger is enabled:

loginctl enable-linger $USER

Verify

curl http://localhost:3300/health
# {"status":"ok","server":"linux-mcp-server","version":"0.1.0"}

Connecting to Claude Code

Claude Code is Anthropic's CLI for Claude. MCP servers are configured in ~/.claude.json (global) or per-project.

HTTP transport (recommended for persistent servers)

Add to ~/.claude.json under mcpServers at the global level, or under projects["/your/project"].mcpServers for project scope:

{
  "mcpServers": {
    "linux-local": {
      "type": "http",
      "url": "http://localhost:3300/mcp"
    }
  }
}

For a remote host running in SSH mode on port 3301:

{
  "mcpServers": {
    "linux-local": {
      "type": "http",
      "url": "http://localhost:3300/mcp"
    },
    "linux-myserver": {
      "type": "http",
      "url": "http://localhost:3301/mcp"
    }
  }
}

stdio transport

If you prefer stdio (no persistent process), use the claude mcp add command:

# Local mode
claude mcp add linux-local \
  -e LOCAL_MODE=true \
  -- node /path/to/linux-mcp-server/dist/index.js

# SSH mode
claude mcp add linux-myserver \
  -e SSH_HOST=192.168.1.50 \
  -e SSH_USER=admin \
  -e SSH_KEY_PATH=~/.ssh/id_ed25519 \
  -- node /path/to/linux-mcp-server/dist/index.js

Verify in Claude Code

/mcp

You should see linux-local (or your server name) listed as connected.


Other MCP Clients

Claude Desktop

Add to ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows):

{
  "mcpServers": {
    "linux-local": {
      "command": "node",
      "args": ["/path/to/linux-mcp-server/dist/index.js"],
      "env": {
        "LOCAL_MODE": "true"
      }
    }
  }
}

Cline (VS Code)

In VS Code settings (cline.mcpServers):

{
  "linux-local": {
    "command": "node",
    "args": ["/path/to/linux-mcp-server/dist/index.js"],
    "env": {
      "LOCAL_MODE": "true"
    }
  }
}

Cursor

Add to .cursor/mcp.json in your project or ~/.cursor/mcp.json globally:

{
  "mcpServers": {
    "linux-local": {
      "command": "node",
      "args": ["/path/to/linux-mcp-server/dist/index.js"],
      "env": {
        "LOCAL_MODE": "true"
      }
    }
  }
}

Continue.dev

Add to ~/.continue/config.json under experimental.modelContextProtocolServers:

{
  "experimental": {
    "modelContextProtocolServers": [
      {
        "transport": {
          "type": "stdio",
          "command": "node",
          "args": ["/path/to/linux-mcp-server/dist/index.js"],
          "env": {
            "LOCAL_MODE": "true"
          }
        }
      }
    ]
  }
}

Tool Reference

Shell

Tool Description
run_command Execute an arbitrary shell command. 30s timeout, 1MB output limit.
run_command_sudo Execute a shell command with sudo. Same limits.

System

Tool Description
get_system_info Hostname, OS version, kernel, uptime, architecture.
get_cpu_usage Load averages, core count, top process snapshot.
get_memory_usage RAM and swap usage.
get_disk_usage Disk usage per mount point and block device layout.
get_network_interfaces All interfaces with IPs and link state.

Processes

Tool Description
list_processes List running processes (ps aux), sortable by cpu/memory/pid. Returns top 60.
get_process Get details for a specific process by PID or name.
get_top_processes Top N processes by CPU or memory.
kill_process Send a signal to a process by PID. Default SIGTERM, use SIGKILL to force.

Services

Tool Description
service_list List systemd services. Filter by scope (system/user) and state.
service_status Get systemctl status for a service.
service_start Start a system service (sudo).
service_stop Stop a system service (sudo).
service_restart Restart a system service (sudo).
service_enable Enable a service to start at boot (sudo).
service_disable Disable a service from starting at boot (sudo).

Files

Tool Description
read_file Read file contents. 1MB limit.
write_file Write text to a file (create or overwrite).
list_directory List directory contents (ls -la).
get_file_info File metadata: permissions, owner, size, timestamps.
make_directory Create a directory (mkdir -p).
delete_file Delete a file or directory. Set recursive=true for non-empty dirs.

Logs

Tool Description
get_journal_logs Fetch systemd journal logs with filters (unit, since/until, lines, priority).
tail_file Tail a log file. Path must be under an allowed prefix (default: /var/log).
search_logs Search journal logs for a pattern. Optional unit filter. Returns last 200 matches.

Packages (apt)

Tool Description
apt_list_installed List installed packages. Optional name filter.
apt_search Search available packages by name or description.
apt_show Show detailed package information.
apt_install Install one or more packages (sudo).
apt_remove Remove packages, leaving config files (sudo).
apt_update Run apt-get update to refresh package index (sudo).
apt_upgrade Upgrade installed packages (sudo). Supports dry_run=true.

Roadmap

  • [ ] npm publish
  • [ ] SSH multi-host: multiple named SSH targets in a single server instance
  • [ ] ZFS module: pool status, scrub, snapshot management
  • [ ] GPU host support: nvidia-smi integration for CUDA hosts
  • [ ] README in other languages

Contributing

PRs welcome. The codebase is straightforward TypeScript — each tool category is a self-contained module in src/tools/. Tests use Vitest.

npm test

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选