Skip to content

feat: MCP for every CLI agent via sync and per-run scoping (#124) - #164

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

saryeljaramany wants to merge 1 commit into
secfoo-com:mainfrom
saryeljaramany:feat/mcp-every-agent

Conversation

@saryeljaramany

Copy link
Copy Markdown
Contributor

Problem

[[mcp_servers]] in ~/.secfoo/config.toml reached claude automatically via ephemeral --mcp-config and gemini/agent via secfoo mcp sync, but all other adapters had no MCP handling (codex.py noted it as a follow-up, and copilot, opencode, droid, devin, and agy did not handle MCP at all). As a result, Confluence, Jira, and enterprise context sources could not be reached across most CLI agents.

Solution

Fixes #124.

  1. Persistent Sync Adapters (src/secfoo/mcp.py):

    • Codex: Merges [mcp_servers.<name>] tables into ~/.codex/config.toml (stdio command/args/env and remote url/transport/headers), preserving existing settings without leaking secrets into process argv via -c.
    • Copilot CLI: Merges into ~/.copilot/mcp-config.json with "type": "local"|"http" and tools: ["*"].
    • OpenCode: Merges into ~/.config/opencode/opencode.json with "type": "local"|"remote", array command format, and environment mapping.
    • Droid: Merges into ~/.factory/mcp.json following the standard mcpServers schema.
    • Devin: Merges into ~/.config/devin/mcp_config.json (%APPDATA%\devin\mcp_config.json on Windows).
    • All sync_* functions write safely, preserve existing unrelated top-level keys and user-defined servers, and are strictly idempotent.
    • secfoo mcp sync supports --agent <id> or running without --agent to sync all supported agents.
  2. Single Source of Truth (docs/REFERENCE.md):

    • The MCP support table in docs/REFERENCE.md serves as the single source of truth for agent capabilities.
    • secfoo mcp sync --agent <unsupported> prints the exact support table and guidance from docs/REFERENCE.md rather than a hardcoded error.
    • secfoo agents displays an MCP column (per-run, sync, or none).
    • Added automated consistency test (test_reference_md_mcp_matrix_consistency) to ensure code and documentation never drift.
  3. Documentation:

    • Updated docs/REFERENCE.md, docs/agents.md, and README.md ("Context, not just code") with the full 10-agent support matrix, verified CLI versions, and notes as of 2026-11-20 (including Antigravity CLI 2.0 note).

Verification

  • Targeted unit & CLI tests: 111 passed (tests/test_mcp.py & tests/test_cli.py).
  • Adapter test suite: 139 passed (tests/test_agents).
  • Full test suite: 1873 passed (0 regressions against main baseline).
  • ruff check: 0 lint errors.

@vsn411

vsn411 commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

Thanks for taking on #124. The adapter coverage and the docs matrix are a useful start. We're closing this PR without merging because several issues need a different approach rather than small fixes. #124 stays open, and a new PR that addresses the points below is very welcome.

Blocking

  1. Secrets are written to readable files. mcp sync uses effective_servers(), which includes the default secfoo-memory server and its bearer key, plus any user env/headers. write_claude_mcp_config sets 0600 on purpose. The five new sync_* functions create files at the default permissions (usually 0644). Any file that holds env/headers should be 0600.

  2. secfoo mcp sync without --agent will fail for most users. It now targets all 7 agents whether or not their CLIs are installed:

    • sync_gemini and sync_cursor call gemini / agent via subprocess.run and don't handle FileNotFoundError, so a missing CLI produces a traceback.
    • Before that, it creates ~/.codex, ~/.copilot, ~/.factory and ~/.config/{opencode,devin} and writes credentials into tools the user may not use.

    Please limit the "all" mode to agents where adapter.is_available() is true, or keep --agent required.

  3. Codex sync rewrites the user's whole ~/.codex/config.toml. It parses with tomllib and re-serializes with a custom _dumps_toml, which:

    • drops all comments;
    • raises an uncaught TypeError on TOML datetimes;
    • drops empty tables such as [features];
    • writes in place with no temp file + os.replace and no backup.

    That conflicts with "without clobbering other settings". Please use a format-preserving editor (e.g. tomlkit) and write atomically.

  4. The Codex remote server shape looks wrong. The PR writes transport and headers. Codex's streamable-HTTP config uses url with http_headers / bearer_token_env_var, has no transport key, and doesn't support SSE. Please check this against the Codex config reference. As written, authenticated remote servers (including secfoo-memory) would likely fail.

Should fix

  1. Cursor behavior changes. Existing same-named entries used to be skipped. Now they're overwritten if they differ at all, which drops user fields like disabled, and the result is still reported as "added". User-defined servers need to be preserved (or the update reported clearly as an update).

  2. Copilot maps sse to "type": "http". Copilot has its own "sse" type.

  3. get_mcp_support_matrix() parses docs/REFERENCE.md at runtime.

    • In an installed wheel that path doesn't exist, so the code always falls back to CANONICAL_MCP_SUPPORT, but the error still says "from docs/REFERENCE.md".
    • secfoo agents re-reads and re-parses the file once per agent.

    Please make the code the source of truth and keep the parser only in the consistency test, which already prevents drift.

  4. A JSON root that isn't an object (e.g. []) makes every JSON sync_* crash with TypeError on existing_root["mcpServers"] = ....

  5. We need evidence from the real CLIs. All tests mock the CLIs. Please include evidence (CLI version + output) that each agent actually loads the synced servers during a secfoo run. Specifically: does opencode run --pure still load MCP servers, and is ~/.config/devin/mcp_config.json the path Devin CLI reads?

Security consideration

copilot runs with --allow-all-tools, and the sync sets tools: ["*"]. Many enterprise MCP servers (Jira, Confluence) expose write tools, so a review that's meant to be read-only could create or edit tickets. Claude avoids this with its per-run --allowedTools list. A new PR should explain how write-capable MCP tools are restricted for each agent, or at least document the risk.

Nits

  • sync_cursor/copilot/opencode/droid/devin are near-duplicates. One helper taking (path, root_key, shape_fn) would remove most of the repetition.
  • Silently swallowing OSError on the Claude config chmod hides a failure to protect a secrets file. Please log a warning at least.
  • The branch currently conflicts with main, so a new PR should start from current main.

Thanks again for the work here. We'd be glad to review a follow-up.

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