Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ the target's own `.mcp.json` is not loaded). The `api` agent (the GitHub
Action's default) connects to the same servers itself and offers their
read-only tools to the model, within a budget of 20 calls per run
(`[agents.api].tool_call_budget`) and a cap on the tokens resent. For Gemini
CLI and Cursor run `secfoo mcp sync --agent <agent>` once. Codex and
Antigravity cannot use MCP servers yet. Details in
CLI, Cursor and Codex run `secfoo mcp sync --agent <agent>` (or
`secfoo mcp sync`) once. Antigravity cannot use MCP servers yet. Details in
[docs/REFERENCE.md](https://github.com/secfoo-com/secfoo/blob/main/docs/REFERENCE.md#configuration-secfooconfigtoml).

## A 30-second look at the dashboard
Expand Down
13 changes: 8 additions & 5 deletions docs/REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1067,9 +1067,11 @@ How MCP servers reach each agent varies by what its CLI actually supports:
|---|---|
| `claude` | Automatic on every `secfoo run` (`--mcp-config`, scoped to that invocation only — your global Claude config is never touched). These are the only MCP servers loaded during a scan (`--strict-mcp-config`): servers from your global Claude config or from the target's `.mcp.json` are not started |
| `api` | Automatic on every `secfoo run`: secfoo connects to each server itself (stdio, HTTP or SSE) and offers its tools to the model as function tools. Only tools the server annotates `readOnlyHint: true` are offered, unless the server's entry lists tools by name in `tools = [...]`, which then offers exactly those. At most 20 tool calls per run (`[agents.api].tool_call_budget`; `0` turns tools off) and 5 minutes of tool use, counted from the first tool call. Because every model turn resends the whole conversation, target source included, the tool phase also ends once the input tokens sent so far reach 4× those of the first call, and the model is asked to batch independent lookups into one turn. When any of these limits is reached the model is told the budget is spent and asked to finish the report. `stderr.log` records the number of tool rounds, the input tokens sent in total and which limit ended the tool phase. Results count toward `--max-input-tokens`, and a result over 40,000 characters is cut with a visible marker. Every call (server, tool, arguments, bytes returned) is logged to the run's `stderr.log`, and the log is shown to the model, so the coverage section can only claim pages a tool actually returned |
| `gemini`, `agent` (Cursor) | Run `secfoo mcp sync --agent <agent>` once to register persistently in that tool's own config |
| `codex` | Not wired up yet — Codex reads MCP servers from its own `~/.codex/config.toml` |
| `agy` (Antigravity) | Not supported yet — its CLI has no MCP configuration mechanism as of this writing |
| `gemini`, `agent` (Cursor), `codex` | Run `secfoo mcp sync --agent <agent>` (or `secfoo mcp sync` to sync all installed agents) once to register persistently in that tool's own config |
| `agy` (Antigravity) | `agy 1.5.3` has an `agy mcp` subcommand, but secfoo does not yet automate syncing with agy's configuration |
| `copilot`, `opencode`, `droid`, `devin` | Not yet automated in `secfoo mcp sync` (planned for follow-up) |

Existing same-named servers are preserved and skipped to prevent overwriting user edits or credentials. When rotating API keys or tokens (such as `secfoo-memory`), remove the server entry from the agent's config, then run sync again.

```bash
secfoo mcp list # show what's configured
Expand All @@ -1093,8 +1095,9 @@ secfoo memory logout

Once a key is saved, secfoo registers `secfoo-memory` as a default MCP
server. `secfoo mcp list` shows it next to your own servers. `claude` picks
it up on every run, and so does the `api` agent. For `gemini` or Cursor
(`agent`), run `secfoo mcp sync --agent <agent>` once. When memory is on, the prompt tells the
it up on every run, and so does the `api` agent. For `gemini`, Cursor
(`agent`) or `codex`, run `secfoo mcp sync --agent <agent>` (or `secfoo mcp sync`)
once. When memory is on, the prompt tells the
agent when to use the three tools (`lookup_patterns`, `get_remediation`,
`check_false_positive`) and how to phrase a query.

Expand Down
3 changes: 1 addition & 2 deletions docs/agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ brackets indicate optional arguments. All CLI processes run in `WORKDIR`.

| `--agent` | Setup and command | Models |
| --- | --- | --- |
| `--agent` | Setup and command | Models |
| `claude` | Install via `npm install -g @anthropic-ai/claude-code` or `curl -fsSL https://claude.ai/install.sh \| bash` ([docs](https://docs.anthropic.com/en/docs/claude-code/setup)). Authenticate with `claude auth login`. For non-interactive use, set `ANTHROPIC_API_KEY`, or with a Claude subscription run `claude setup-token` once and set the token it prints as `CLAUDE_CODE_OAUTH_TOKEN` (verified `2.1.329 (Claude Code)` on 2026-11-21, macOS Darwin arm64). `claude [--model MODEL] -p --output-format json --allowedTools TOOLS --permission-mode default --setting-sources user --strict-mcp-config --no-session-persistence [--mcp-config PATH]` (prompt on stdin). `TOOLS` starts with `Read,Grep,Glob,Bash(git log:*),Bash(git diff:*)` and includes configured MCP servers when present. The tool grant is read-only, not an OS sandbox. | `secfoo models --agent claude`. Examples: `claude-sonnet-4-6`, `sonnet`. Live via `ANTHROPIC_API_KEY` (Anthropic models API), else curated. |
| `agent` (Cursor) | Install via `curl https://cursor.com/install -fsS \| bash` ([docs](https://cursor.com/docs/cli/overview)). Authenticate with `agent login` or set `CURSOR_API_KEY` for non-interactive use (login and `CURSOR_API_KEY` confirmed in `agent --help` for `2026.08.11-e8db854` on 2026-11-21, macOS arm64; install command from the official docs). `agent [--model MODEL] -p PROMPT` | `secfoo models --agent agent`. Examples: `auto`, `claude-4.5-sonnet`. Live via CLI if supported, else curated. |
| `agy` (Antigravity) | Install the `agy` CLI from the Antigravity distribution ([docs](https://antigravity.google)), then run `agy install` to add it to `PATH`. The CLI has no login subcommand: sign in through Antigravity before headless runs (checked against `agy --help` for `1.5.3` on 2026-11-21, macOS arm64). `agy --print PROMPT --print-timeout Ns` (`N` is the effective timeout in seconds). Headless mode denies tool calls requiring approval. | Not supported (`--model` fails fast). |
| `gemini` | Install via `npm install -g @google/gemini-cli` ([docs](https://github.com/google-gemini/gemini-cli)). Authenticate interactively with `gemini` or set `GEMINI_API_KEY` for non-interactive use (verified `0.38.1` on 2026-11-21, macOS Darwin arm64). `gemini [--model MODEL] -p PROMPT --output-format json --skip-trust`. No `--yolo` write auto-approval is passed. | `secfoo models --agent gemini`. Examples: `gemini-2.5-pro`, `gemini-2.5-flash`. Live via `GEMINI_API_KEY`, else curated. |
| `codex` | Install via `npm install -g @openai/codex` ([docs](https://github.com/openai/codex)). Authenticate with `codex login` or set `OPENAI_API_KEY` for non-interactive use (verified `codex-cli 0.159.0` on 2026-11-21, macOS Darwin arm64). `codex exec [--model MODEL] --sandbox read-only [-c windows.sandbox="unelevated"] --skip-git-repo-check --ephemeral --color never --cd WORKDIR -` (prompt on stdin; `-c` is Windows-only). | `secfoo models --agent codex`. Examples: `gpt-5.4`, `o4-mini`. Live via `OPENAI_API_KEY` (or CLI), else curated. |
| `codex` | Install via `npm install -g @openai/codex` ([docs](https://github.com/openai/codex)). Authenticate with `codex login` or set `OPENAI_API_KEY` for non-interactive use (verified `codex-cli 0.159.0` on 2026-11-21, macOS Darwin arm64; `codex-cli 0.172.0` on Windows). `codex exec [--model MODEL] --sandbox read-only [-c windows.sandbox="unelevated"] --skip-git-repo-check --ephemeral --color never --cd WORKDIR -` (prompt on stdin; `-c` is Windows-only). MCP servers are registered into `$CODEX_HOME/config.toml` (default `~/.codex/config.toml`) via `secfoo mcp sync --agent codex` (or `secfoo mcp sync`). | `secfoo models --agent codex`. Examples: `gpt-5.4`, `o4-mini`. Live via `OPENAI_API_KEY` (or CLI), else curated. |
| `copilot` | Install via `npm install -g @github/copilot` ([docs](https://docs.github.com/en/copilot/how-tos/use-copilot-agents/use-copilot-cli)). Authenticate by running `copilot` and using its `/login` command, or set `GH_TOKEN` / `GITHUB_TOKEN` (a fine-grained token with the Copilot Requests permission) for non-interactive use (verified against the real CLI 1.0.117 on 2026-11-29, Windows: `gh auth login` plus `GH_TOKEN` from `gh auth token` worked; see the matrix below). `copilot [--model MODEL] --output-format json --allow-all-tools --usage-output-file PATH` (prompt on stdin). Token counts come from the usage file; premium requests / AI credits are not USD, so `cost_usd` stays unknown. Tools, including writes, are auto-approved: read-only behavior relies on review instructions, not a sandbox. | `secfoo models --agent copilot`. Examples: `claude-sonnet-4.5`, `gpt-5`. Curated (live via CLI if supported). |
| `droid` | Install via `curl -fsSL https://app.factory.ai/cli \| sh` ([docs](https://docs.factory.ai/cli/getting-started/overview)). Set `FACTORY_API_KEY` for non-interactive use or run `droid` to sign in interactively (checked against official docs on 2026-11-21, not on an installed CLI). `droid exec [-m MODEL] --output-format json --cwd WORKDIR -- PROMPT`. Droid defaults to read-only; a full authenticated secfoo run was not verified in the adapter. | `secfoo models --agent droid`. Examples: `claude-sonnet-4-5-20250929`, `gpt-5`. Curated (live via CLI if supported). |
| `devin` | Install via `brew install --cask devin-cli` ([docs](https://docs.devin.ai)). Authenticate beforehand with `devin auth login`; credential reuse for headless runs is unverified (install and login checked against official docs on 2026-11-21, not on an installed CLI). `devin -p PROMPT --respect-workspace-trust false --permission-mode auto`. The combined command and an authenticated end-to-end run are unverified; `auto` is documented by the CLI as approving read-only tools. | Not supported (`--model` fails fast). |
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ dependencies = [
"markdown-it-py>=4.3.0",
"python-multipart>=0.0.32",
"tomli>=2.0; python_version < '3.11'",
"tomlkit>=0.13.0",
# Pure-Python text extraction for uploaded third-party vendor documents
# (docext.py) -- deliberately no system-level binaries (no poppler, no
# LibreOffice) so the Docker/Kubernetes image stays lean and doesn't
Expand Down
63 changes: 54 additions & 9 deletions src/secfoo/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1155,17 +1155,31 @@ def serve_key_revoke(key_id: Annotated[int, typer.Argument(help="Key id from `se

@app.command()
def agents() -> None:
"""List known agent adapters and whether their CLI is installed."""
"""List known agent adapters, whether their CLI is installed, and their MCP support."""
table = Table(title="Agent adapters")
table.add_column("Agent ID")
table.add_column("Binary")
table.add_column("Available")
table.add_column("MCP")

for agent_id in ADAPTERS:
adapter = get_adapter(agent_id)
available = adapter.is_available()
style = "green" if available else "red"
table.add_row(agent_id, adapter.binary, f"[{style}]{'yes' if available else 'no'}[/]")
avail_style = "green" if available else "red"
mcp_support = mcp_module.CANONICAL_MCP_SUPPORT.get(agent_id)
mechanism = mcp_support.mechanism if mcp_support else "none"
if mechanism == "per-run":
mcp_style = "green"
elif mechanism == "sync":
mcp_style = "cyan"
else:
mcp_style = "dim"
table.add_row(
agent_id,
adapter.binary,
f"[{avail_style}]{'yes' if available else 'no'}[/]",
f"[{mcp_style}]{mechanism}[/]",
)
console.print(table)


Expand Down Expand Up @@ -3041,19 +3055,27 @@ def mcp_list() -> None:
console.print(table)
console.print(
"\n[bold]claude[/] picks these up automatically on every run (--mcp-config, "
"scoped to that run only).\nFor [bold]gemini[/] or [bold]agent[/] (Cursor), run "
"scoped to that run only).\nFor [bold]gemini[/], [bold]agent[/] (Cursor) or [bold]codex[/], run "
"[bold]secfoo mcp sync --agent <agent>[/] once to register them persistently."
)


@mcp_app.command(name="sync")
def mcp_sync(
agent: AgentId = typer.Option(..., "--agent", "-a", help="Which agent's MCP config to update."),
agent: AgentId | None = typer.Option(
None,
"--agent",
"-a",
help="Which agent's MCP config to update. If omitted, syncs all installed sync-supported agents.",
),
) -> None:
"""Register configured MCP servers persistently into gemini's or Cursor's own
config. claude doesn't need this -- it picks up ~/.secfoo/config.toml
automatically on every run. agy isn't supported (its CLI has no MCP
configuration mechanism yet).
"""Register configured MCP servers persistently into gemini, Cursor or Codex config.
claude doesn't need this -- it picks up ~/.secfoo/config.toml automatically on every run.
Other agents are not yet supported for automated sync.

Existing same-named servers are preserved and skipped to prevent overwriting user edits.
To update credentials after rotating keys (e.g. secfoo-memory), remove the server entry
from the agent's config, then run sync again.
"""
try:
cfg = load_config()
Expand All @@ -3066,6 +3088,29 @@ def mcp_sync(
console.print(f"No MCP servers configured in {CONFIG_PATH} -- nothing to sync.")
return

if agent is None:
targets = [
aid for aid in sorted(mcp_module.SYNC_SUPPORTED_AGENTS)
if get_adapter(aid).is_available()
]
if not targets:
console.print("[yellow]No sync-supported agent CLIs are installed on PATH.[/]")
return
any_failed = False
for aid in targets:
console.print(f"\n[bold]Syncing {aid}...[/]")
results = mcp_module.sync(aid, servers)
for result in results:
style = "green" if result.ok else "red"
console.print(
f" [{style}]{'ok' if result.ok else 'failed'}[/] {result.server_name}: {result.message}"
)
if not result.ok:
any_failed = True
if any_failed:
raise typer.Exit(code=1)
return

if agent.value == "claude":
console.print("[yellow]claude doesn't need syncing[/] -- it loads MCP servers automatically on every run.")
return
Expand Down
22 changes: 17 additions & 5 deletions src/secfoo/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import os
import time
from pathlib import Path

STORE_DIR = Path(os.environ.get("SECFOO_HOME", Path.home() / ".secfoo"))
Expand Down Expand Up @@ -40,19 +41,30 @@ def _make_private(directory: Path) -> None:


def write_private_text(path: Path, text: str) -> None:
"""Write a secret-bearing file that is never readable by others, not even
between creation and a later chmod (and tighten an existing file first)."""
path.parent.mkdir(parents=True, exist_ok=True)
fd = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
"""Write a secret-bearing file atomically and symlink-safely so it is never
readable by others, not even between creation and replacement.

Resolves symlinks first so that dotfile managers (e.g. stow, chezmoi)
do not have their symlink replaced with a regular file, and writes via a
temporary file in the target directory before atomically replacing it.
"""
target = path.resolve()
target.parent.mkdir(parents=True, exist_ok=True)
tmp_path = target.with_name(f".{target.name}.tmp.{os.getpid()}.{time.time_ns()}")
fd = os.open(tmp_path, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600)
try:
if hasattr(os, "fchmod"): # POSIX; O_CREAT's mode does not apply to an existing file
# POSIX: O_CREAT's mode does not apply to an existing file
if hasattr(os, "fchmod"):
os.fchmod(fd, 0o600)
with os.fdopen(fd, "w", encoding="utf-8") as handle:
fd = -1
handle.write(text)
os.replace(tmp_path, target)
finally:
if fd != -1:
os.close(fd)
if tmp_path.exists():
tmp_path.unlink(missing_ok=True)


def run_dir(run_uuid: str) -> Path:
Expand Down
Loading
Loading