Skip to content

feat(mcp): register MCP servers with every supported CLI agent (Codex, Copilot, OpenCode, Droid, Devin) - #190

Closed
saryeljaramany wants to merge 5 commits into
secfoo-com:mainfrom
saryeljaramany:feat/mcp-every-agent
Closed

saryeljaramany wants to merge 5 commits into
secfoo-com:mainfrom
saryeljaramany:feat/mcp-every-agent

Conversation

@saryeljaramany

Copy link
Copy Markdown
Contributor

Fixes #124

Summary

claude stays per-run. gemini, agent (Cursor), codex, copilot, opencode, droid and devin are registered with secfoo mcp sync. secfoo agents has a new MCP column. The support matrix has one source of truth in code (CANONICAL_MCP_SUPPORT); only the test suite reads docs/REFERENCE.md, to catch drift.

Behaviour

  • secfoo mcp sync without --agent syncs only installed CLIs, so it never creates ~/.codex, ~/.copilot, ~/.factory or ~/.config/{opencode,devin} on machines without them.
  • Config files secfoo writes (including the Claude per-run config) are written atomically at 0600. A failed chmod logs a warning. gemini is registered through gemini mcp add, so Gemini's own CLI performs that write.
  • Codex: ~/.codex/config.toml is edited with tomlkit (comments, datetimes, empty tables and existing line endings preserved). Remote servers use url + http_headers with no transport key. SSE servers are reported as unsupported.
  • Cursor and the JSON-based agents never overwrite an existing same-named server (including disabled: true); they report "already configured, skipped". If agent mcp enable can't run, the file is still written and the result is marked failed.
  • Copilot maps sse to "type": "sse". Non-object JSON roots and non-table mcp_servers raise a clean error instead of a TypeError.

Per-run vs sync

Only claude is per-run. For the other agents, secfoo's adapters currently pass no MCP configuration per run. I did not evaluate upstream per-run mechanisms for Codex/Copilot/OpenCode/Droid/Devin. For Codex I deliberately avoided -c overrides because command, URL and header values would appear in the process table. Per-run support is a possible follow-up.

Verification status

Verified on a real CLI

  • claude 2.1.312 on Windows: detected as available (per-run) in secfoo agents and skipped cleanly by secfoo mcp sync since per-run --mcp-config is automatic on secfoo run.

Unit-tested only (shapes follow vendor docs; not exercised against the real CLI)

  • codex, copilot, opencode, droid, devin, agent (Cursor), gemini.
  • Not verified that synced servers load under opencode run --pure.
  • Devin's ~/.config/devin/mcp_config.json / %APPDATA%\devin\mcp_config.json path and Droid's ~/.factory/mcp.json shape are unverified.

Not supported

  • agy: no MCP mechanism is documented; not re-verified against a current release.
  • api: no tool loop.

A maintainer with these CLIs installed confirming that synced servers load would be very welcome.

Security notes

  • sync stores secrets in plaintext at rest (0600). On Windows, 0600 is a no-op, so the permission tests run on POSIX only.
  • Claude: --allowedTools mcp__<server> grants all tools on that server, including write tools. Use read-only tokens or per-tool allowlists.
  • Copilot: servers are synced with tools: ["*"] and non-interactive runs use --allow-all-tools, so read-only behaviour relies on the review prompt, not a sandbox.
  • Codex runs with --sandbox read-only; OpenCode permissions are set through its permission settings. For remote servers, use read-only credentials in every case.

Testing

ruff check clean on all changed Python files, ruff format --check clean on src/secfoo/mcp.py, tests/test_cli.py, and tests/test_mcp.py, and pytest tests/test_mcp.py tests/test_cli.py: 120 passed.

Review history

Re-implemented from clean main after the first attempt was closed, addressing each point of the earlier review.

AI assistance was used to draft parts of this; I reviewed the diff and ran the tests myself.

@vsn411

vsn411 commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator

Thanks for coming back to #124 with a rewrite. It's a clear improvement on #164:

  • sync without --agent only touches installed CLIs;
  • writes are atomic and 0600;
  • Codex edits go through tomlkit and use url + http_headers;
  • existing servers are never overwritten;
  • Copilot SSE servers get the right type;
  • the support matrix lives in code.

We're closing this PR without merging because it can't land in its current state. #124 stays open, and a fresh PR from current main is very welcome.

Blocking

  1. It conflicts with main in src/secfoo/mcp.py, tests/test_mcp.py and docs/agents.md.
  2. CI has never run. GitHub doesn't run checks on a conflicting branch, so the required Test (py3.10) / Test (py3.12) checks have no result.
  3. Codex, Copilot, OpenCode, Droid and Devin are unit-tested only.
    • Thanks for saying so plainly, but evidence from the real CLIs is what we asked for last time.
    • For each agent you add, please include its CLI version plus output showing the synced server loaded (for example codex mcp list, or a run that lists the server's tools).
    • An agent you can't verify can be left out of SYNC_SUPPORTED_AGENTS and added in a follow-up.
  4. os.replace() replaces a symlinked config with a regular file. Many people manage ~/.codex/config.toml or opencode.json as symlinks through a dotfile manager (stow, chezmoi, and so on). The sync would silently break that link. Please resolve the path first (path.resolve()) and write the temp file next to the real target.

Should fix

  1. Use the existing private writer. _write_private_file duplicates config.write_private_text. Please make that one atomic (and symlink-aware) and use it everywhere, so there's one place that handles 0600 secrets.
  2. A rotated key never reaches the agent config. A same-named server is always skipped, so after the secfoo-memory key is rotated, the agent configs keep the old key forever. Either offer an explicit update path (for example --update that replaces only servers secfoo wrote) or document clearly that the entry must be removed by hand.
  3. agy does have an MCP subcommand now. agy 1.5.3 shows an agy mcp subcommand in agy --help. The "no MCP mechanism is documented" wording needs checking against a current release.
  4. Inconsistent error handling. In _sync_json_mcp_config, invalid JSON returns a failed SyncResult, but a non-object root raises MCPSyncError. One behaviour for both would be easier to reason about; main returns a SyncResult for both in the Cursor path. The docstring also calls the helper "format-preserving", which it isn't for JSON.

Suggested way forward

Splitting this would make review much faster:

  1. One PR for Codex, which has the most value and needs tomlkit plus the symlink-safe writer, with real-CLI evidence.
  2. One PR per JSON-config agent, each with its own evidence.
  3. The matrix/secfoo agents column, which can land with the first of these.

Thanks again. The security notes in the description were especially useful, and we'd be glad to review the follow-up.

@vsn411 vsn411 closed this Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP for every CLI agent: secfoo mcp sync for Codex, Copilot, OpenCode, Droid and Devin, and per-run scoping where the CLI allows it

2 participants