Skip to main content

Module plain_mode

Module plain_mode 

Source
Expand description

Plain Mode — temporarily disable MCP servers by renaming .mcp.json files to .mcp.json.suspect and (optionally) writing an empty stub in their place.

§When to use it

User suspects a newly-installed MCP server is malicious and wants to start a clean Agent session right now, without manually editing configs. agentsec plain enable renames targets to .suspect; the Agent then starts with an empty MCP world. agentsec plain restore puts everything back.

§What gets renamed

Plain Mode only touches standalone .mcp.json files. It never edits .claude.json directly, because that file mixes MCP server config with hooks / permissions / per-project state that we don’t want to wipe.

Default target: <cwd>/.mcp.json. Callers can pass additional absolute paths (typically per-project .mcp.json discovered from a scan).

§Ledger

PLAIN_LEDGER_FILENAME under crate::Paths::home tracks which files were renamed so restore can put them back. The ledger existing with non-empty entries is the canonical signal that Plain Mode is active.

§Invariants

  • enable is idempotent within a session: if the target’s .suspect sibling already exists, enable skips that target (and reports the skip) rather than clobbering the prior backup.
  • restore removes the ledger on success. Repeat calls with an absent ledger are no-ops.
  • Dry-run mode performs zero filesystem mutation and returns the same shape of result so callers can preview.

Structs§

EnableOutcome
Outcome of enable.
EnableRow
One row of enable’s outcome.
LedgerEntry
One row in the persisted ledger.
PlainLedger
Full ledger persisted to PLAIN_LEDGER_FILENAME.
PlainStatus
Resolved Plain Mode status — what the on-disk ledger says right now.
RestoreOutcome
Outcome of restore.
RestoreRow
One row of restore’s outcome.

Enums§

EnableAction
Outcome variants for a single target.
RestoreAction
Outcome variants for restoring a single ledger entry.

Constants§

PLAIN_LEDGER_FILENAME
Filename of the ledger file under Paths::home.
PLAIN_STUB_BODY
Content of the stub written at the original path while Plain Mode is active. Empty MCP world; the Agent sees zero servers configured.
SUSPECT_SUFFIX
Suffix appended to a renamed file (so .mcp.json becomes .mcp.json.suspect).

Functions§

default_targets
Default Plain Mode targets — currently just <cwd>/.mcp.json. Callers can extend this list with their own absolute paths.
enable
Enable Plain Mode for the given target paths.
restore
Restore everything in the ledger.
status
Read PlainStatus from disk.