The server directly connects to systemd via its C API and so doesn't need systemctl to run.
Compile directly with
go build systemd-mcp.go
or
make build
A manual installation can be done with
cp systemd-mcp /usr/local/bin/systemd-mcp
cp ./configs/org.opensuse.systemdmcp.conf /etc/dbus-1/system.d/
cp ./configs/org.opensuse.systemdmcp.policy /etc/polkit-1/actions/
or
make install
Interacting with systemd requires root privileges. systemd-mcp is designed with a security model based on polkit to control access to potentially dangerous operations.
-
Privilege Escalation: When you start
systemd-mcp, it will check if it is running as root. If not, it will usepkexecto request administrator privileges. You will be prompted for your password to allow the application to run as root. -
Restricted by Default: Once running as root, the daemon starts in a restricted mode. By default, it is not allowed to perform read or write operations on
systemd. -
Granting Permissions: To grant permissions, you need to run a second
systemd-mcpcommand in another terminal.- To receive authorization prompts for operations, run:
This will register a process to handle authorization requests from the main daemon. When a tool needs permissions, a
systemd-mcp --auth-registerpolkitdialog will appear asking for your confirmation. You should keep this terminal window open. - On
sshsessions, you can use the--internal-agentflag which is a convenience wrapper around--auth-registerandpkttyagent.
- To receive authorization prompts for operations, run:
-
Pre-authorizing Permissions: You can also pre-authorize permissions when starting the daemon, or for a daemon that is already running:
- To start the daemon with read access pre-authorized:
systemd-mcp --allow-read - To start the daemon with write access pre-authorized:
systemd-mcp --allow-write - To grant read access to an already running daemon:
systemd-mcp --allow-read - To grant write access to an already running daemon:
systemd-mcp --allow-write
- To start the daemon with read access pre-authorized:
-
Disabling Authorization: For development or in trusted environments, you can disable the
polkitauthorization entirely:systemd-mcp --noauth[!CAUTION] Using
--noauthgives any client with access tosystemd-mcpfull control oversystemdas root. Use this with extreme caution.
| Flag | Shorthand | Description | Default |
|---|---|---|---|
--http |
If set, use streamable HTTP at this address, instead of stdin/stdout. | "" |
|
--logfile |
If set, log to this file instead of stderr. | "" |
|
--verbose |
-v |
Enable verbose logging. | false |
--debug |
-d |
Enable debug logging. | false |
--log-json |
Output logs in JSON format (machine-readable). | false |
|
--list-tools |
List all available tools and exit. | false |
|
--allow-write |
-w |
Authorize write access to systemd. Can be used when starting the daemon or to authorize a running daemon. | false |
--allow-read |
-r |
Authorize read access to systemd. Can be used when starting the daemon or to authorize a running daemon. | false |
--auth-register |
-a |
Register to handle authorization requests from a running daemon via polkit. | false |
--internal-agent |
Starts pkttyagent to handle authorization requests. A convenience wrapper around --auth-register. |
false |
|
--enabled-tools |
A comma-separated list of tools to enable. | all | |
--timeout |
Set the timeout for authentication in seconds. | 5 |
|
--noauth |
Disable polkit authorization and always allow read and write access. |
false |
Following tools are provided:
list_systemd_units_by_statewhich lists the units in the given state, also all states can be listedlist_systemd_units_by_namewhich lists the units given by their patternrestart_reload_unitwhich restarts or reloads a unitstart_unitstarts a unitstop_unitstops a unitcheck_restart_reloadcheck the state of reload or restartenable_or_disable_unitenables or disables a unitlist_unit_fileswhich lists the unit files known to systemdlist_logwhich has access to the system log, with various filters
You can test the functions with mcptools, with e.g.
mcptools shell go run systemd-mcp.go