# ClusterControl MCP Server — /etc/default/cmon-mcp
# Edit this file then run: systemctl restart cmon-mcp
#
# MODE: root-only 0600, because this file holds CMON_PASSWORD and MCP_AUTH_TOKEN and the
# unit declares no User= — anyone who can read it has root on the controller. Every install
# and upgrade re-applies it, including over a mode you widened deliberately, and including
# to any .dpkg-old / .rpmsave copy the package manager leaves behind. A non-root reader that
# genuinely needs controller access should get its own CMON_KEY_FILE with an ACL of its own
# rather than this file being opened up.
#
# WHICH VARIABLES THIS FILE SPELLS IS LOAD-BEARING, so weigh commenting one out or adding one.
# systemd resolves EnvironmentFile= over Environment= whatever order the two appear in, so an
# assignment here — an EMPTY one included — replaces the same variable set by any systemd
# drop-in, while a variable this file only mentions in a comment leaves a drop-in's value
# intact. CMON_PASSWORD below is spelled empty and so defeats a drop-in that sets it;
# CMON_KEY_FILE and MCP_AUTH_TOKEN are commented and so do not. Uncommenting one silently
# flips it, and the operator's drop-in stops working with nothing to say so.

# CMON Controller connection (required)
CMON_ENDPOINT=https://127.0.0.1:9501
CMON_USERNAME=admin
CMON_PASSWORD=
# RSA key auth alternative (leave CMON_PASSWORD empty):
# CMON_KEY_FILE=/etc/clustercontrol/id_rsa

# HTTP listen address (required for systemd service mode)
# 127.0.0.1:3000 = local access only; 0.0.0.0:3000 = remote access
# Exposes two MCP transports on the same port:
#   /sse + /message  — SSE transport (Claude Desktop, Claude Code)
#   /mcp             — Streamable HTTP transport (Codex / OpenAI)
MCP_BIND_ADDRESS=127.0.0.1:3000

# Advertised base URL — set when clients connect via hostname or remote IP
# MCP_BASE_URL=http://your-cc-host:3000

# Bearer token required on all incoming connections (optional but recommended for remote access)
# Applies to both /sse and /mcp endpoints.
# Generate with: openssl rand -hex 32
# MCP_AUTH_TOKEN=

# Global read-only mode (optional)
# When enabled, the 29 write tools are hidden from tools/list AND a direct
# tools/call on any of them is refused before it runs, so no CMON request is
# issued and no local file is written. Read tools are unaffected.
# Accepted values: 1, t, true, 0, f, false. Anything else is a startup error.
# MCP_READ_ONLY=1

# Per-tool and resource scoping (optional)
# Comma-separated tool names. MCP_TOOL_ALLOW exposes ONLY those tools;
# leave it unset to expose all 84. MCP_TOOL_DENY removes tools and wins
# over MCP_TOOL_ALLOW. Both hide the tool from tools/list AND refuse a
# direct tools/call with the TOOL_NOT_IN_SCOPE code.
# Resource surfaces follow their tools: a resource or template whose
# manifest-mapped tool is out of scope disappears from resources/list and
# resources/templates/list, and a resources/read of it is refused.
# A name that matches no tool is a startup error, not a silent no-op —
# check the "tool scope:" line in the journal after a restart.
#
# Prefer MCP_TOOL_ALLOW when the requirement is "only these tools".
# MCP_TOOL_DENY names what to REMOVE, so it is not upgrade-safe: a tool
# added in a later release is exposed until you add it to the list.
#
# And a deny removes a TOOL, not a data class. Other tools read the same
# CMON data — denying list_backups leaves get_latest_backup serving the
# same rows, denying list_alarms leaves list_all_alarms. Deny every tool
# in the class, or use MCP_TOOL_ALLOW. The server prints a
# "tool scope: WARNING:" line for the overlaps it can derive; see the
# full overlap table in the README.
# MCP_TOOL_ALLOW=list_clusters,get_cluster,list_jobs
# MCP_TOOL_DENY=drop_db_user,drop_cmon_user

# Job command policy (optional)
# Comma-separated CMON job commands create_job and the dedicated job tools may
# submit (ALLOW) or must not (DENY). Deny wins; empty or unset is unrestricted.
# It governs job submission, not effects: scope config and maintenance tools
# with MCP_TOOL_DENY. Check the "job command policy:" line after a restart.
# MCP_JOB_COMMAND_ALLOW=verify_backup,stage_replication_slave
# MCP_JOB_COMMAND_DENY=remove_cluster

# Export directory (optional)
# The one directory the three tools that write local files —
# download_error_report, export_cluster_log and unpack_error_report — may write
# into. Their output_path / output_dir / path arguments are resolved inside it
# and may not leave it: ".." and symlinks pointing outside are refused, and
# every write lands through a rename so a symlink at the destination is never
# written through and a failed write leaves a pre-existing file untouched.
#
# This matters because the unit above declares no User=, so cmon-mcp runs as
# root. Without the directory, granting an agent any one of those three tools
# would be the same as granting it root write anywhere on this host.
#
# Unset uses /var/lib/cmon-mcp/exports, which the server creates at 0700 on
# start. Set it to "off" to refuse local filesystem writes entirely. A
# directory you name here that cannot be created or opened is a startup error —
# check the "export dir:" line in the journal after a restart.
#
# UPGRADING: this is a breaking change, and it is on by default. Before this
# release these three tools wrote to any path they were given, so a caller
# passing output_path=/tmp/report.tar.gz succeeded; it is now refused, and this
# file being left untouched does not opt you out the way MCP_READ_ONLY does.
# Nor do the governance settings: on a FRESH install they are switched on from
# a separate file (see GOVERNED MODE at the end of this file), and leaving this
# one untouched leaves them on. A caller that passed an absolute path outside the
# directory was relying on the behaviour this closes. To keep it working, set
# MCP_EXPORT_DIR to the directory it already writes to.
#
# Point it somewhere only root can write. The confinement is only as good as
# the directory it is aimed at: the path's final component and every parent are
# followed, so anyone who can write one of them chooses where the boundary
# lands. A symlinked, group-writable or foreign-owned directory produces an
# "export dir: WARNING:" line at startup rather than a refusal.
# MCP_EXPORT_DIR=/var/lib/cmon-mcp/exports
# MCP_EXPORT_DIR=off

# ── GOVERNED MODE ─────────────────────────────────────────────────────────────
#
# This template ASSIGNS no governance setting, deliberately: it is a conffile an
# upgrade may replace, and a template that assigned one could govern a host that
# never asked to be. Every governance line below is commented out, and the
# comment marker is the whole of the difference — systemd reads an assignment
# and ignores a comment, and so does the package's own migration, which counts a
# host as configured only where one of these is spelled live. Do not read any of
# this as "a packaged install is ungoverned".
#
# A FRESH install IS governed, from a file this template is not:
#
#   /etc/cmon-mcp/governed.env   MCP_AUDIT_LOG, MCP_DIGEST_HMAC_KEY_FILE
#   /etc/cmon-mcp/digest.key     the HMAC key those records are signed under
#
# The unit reads that file BEFORE this one, and for EnvironmentFile= the later
# file wins — so anything you set here overrides it. To un-govern a fresh
# install, set the line below in THIS file rather than editing or deleting a
# file the package wrote:
#
# MCP_AUDIT_LOG=off
#
# An UPGRADE provisions neither of those files. A host that has never been
# governed comes back from an upgrade running exactly as it did, and a host you
# governed yourself keeps the key and the settings you chose.
#
# If you point MCP_DIGEST_HMAC_KEY_FILE at a key of your own on a host that was
# installed fresh, every record already written stops verifying: verification
# resolves the key_id a record names and does not fall back. Add your entry to
# the installed file as `active` and leave the `install-...` one listed instead.
#
# The two controls below are the only settings here that are OFF until you
# switch them ON, and this file is the only place to do it: the package
# provisions neither, on a fresh install or an upgrade. That inverts what is at
# stake in an upgrade — losing one of the settings above turns a protection off,
# and losing one of these does too, so the package's migration counts both.
#
# READ THIS BEFORE UNCOMMENTING EITHER ON AN UPGRADED HOST. Both put the server
# into governed mode, which requires a digest key, and an upgrade provisions
# none — so a host that has never been governed will refuse to start until you
# write a key and name it in MCP_DIGEST_HMAC_KEY_FILE. A host installed fresh
# already has both.
#
# MCP_EXECUTION_GUARD makes every destructive call a two-step: a preview mints a
# single-use confirmation this server holds IN MEMORY, and the execution has to
# carry it back, so a restart revokes every one outstanding. A preview is never
# refused. Unset, empty or "off" is off; anything else is on, a typo included.
#
# MCP_HUMAN_APPROVAL adds an approval above that: every destructive EXECUTION is
# put to the calling session, and a call that cannot be asked at all — no bound
# identity, or a client that cannot receive the prompt — is refused rather than
# admitted. It is a person's decision only if that session's client shows the
# request to a person the caller cannot answer for; the server cannot tell.
# Same on/off semantics.
#
# MCP_EXECUTION_GUARD=enforced
# MCP_HUMAN_APPROVAL=elicitation
