Skip to content

feat(mcp): support Codex MCP sync and canonical MCP support matrix (#124) - #195

Open
saryeljaramany wants to merge 9 commits into
secfoo-com:mainfrom
saryeljaramany:feat/mcp-codex-support
Open

saryeljaramany wants to merge 9 commits into
secfoo-com:mainfrom
saryeljaramany:feat/mcp-codex-support

Conversation

@saryeljaramany

Copy link
Copy Markdown
Contributor

Part of #124 (Codex MCP sync, symlink-safe atomic writer, and canonical MCP support matrix).

Summary

Following maintainer feedback on closed PR #190, this PR starts cleanly from current main (509bd9b) and scopes Phase 1 to Codex MCP configuration sync backed by real CLI verification, alongside the symlink-safe atomic writer and the canonical MCP support matrix + secfoo agents MCP column. Remaining JSON-config agents (copilot, opencode, droid, devin) are left out of SYNC_SUPPORTED_AGENTS and documented as planned follow-ups so each can land with its own real-CLI evidence.

Addresses Feedback from #190

  • Cleanly based on main (0 conflicts): Built directly on top of _run_cli() (fix(mcp): report a missing agent CLI instead of crashing #181) and 0600 Cursor permissions (fix(mcp): write ~/.cursor/mcp.json owner-only (0600) #182) with zero merge conflicts so CI runs cleanly across all runners.
  • Symlink-safe, single atomic private writer (src/secfoo/config.py): Removed duplicate _write_private_file from src/secfoo/mcp.py. write_private_text() now resolves symlinks first (path.resolve()), creates a temporary file next to the real target in target.parent via os.O_CREAT | os.O_EXCL at 0o600 (plus os.fchmod), and replaces atomically via os.replace() so dotfile manager symlinks (stow, chezmoi) are never overwritten with regular files.
  • Format-preserving Codex sync via tomlkit (src/secfoo/mcp.py):
    • sync_codex() merges [mcp_servers.<name>] entries into ~/.codex/config.toml via tomlkit, preserving comments, whitespace, and existing tables.
    • Supports stdio servers (command, args, env) and streamable-HTTP servers (url, http_headers).
    • Rejects SSE transport with a descriptive failed SyncResult (Codex does not support SSE).
    • Returns failed SyncResult consistently for invalid TOML or non-table roots.
    • Tightens existing ~/.codex/config.toml permissions to 0o600 on POSIX when nothing new is added.
  • Canonical support matrix & CLI improvements (src/secfoo/mcp.py, src/secfoo/cli.py):
    • Added CANONICAL_MCP_SUPPORT in code as the single source of truth covering all 10 adapters in ADAPTERS.
    • Added an MCP column (per-run, sync, none) to secfoo agents.
    • Made --agent optional on secfoo mcp sync; when omitted, syncs only installed sync-supported agents found on PATH.
  • Documentation & key rotation guidance (docs/REFERENCE.md, docs/agents.md, README.md, src/secfoo/cli.py):
    • Documented that existing same-named servers are preserved/skipped and how to refresh credentials after key rotation (e.g. secfoo-memory).
    • Updated agy notes to reflect that agy 1.5.3 exposes an agy mcp subcommand.

Real CLI Evidence (codex-cli 0.172.0 on Windows)

$ codex --version
codex-cli 0.172.0

$ secfoo mcp sync
Syncing codex...
  ok secfoo-codex-verify: added to C:\Users\User\.codex\config.toml

$ codex mcp list
Name                 Command   Args                                          Env   Cwd  Status    Auth
secfoo-codex-verify  npx       -y mcp-remote@latest https://mcp.example.com  -     -    enabled   Unsupported

$ codex mcp get secfoo-codex-verify --json
{
  "name": "secfoo-codex-verify",
  "enabled": true,
  "disabled_reason": null,
  "transport": {
    "type": "stdio",
    "command": "npx",
    "args": [
      "-y",
      "mcp-remote@latest",
      "https://mcp.example.com"
    ],
    "env": null,
    "env_vars": [],
    "cwd": null
  },
  "enabled_tools": null,
  "disabled_tools": null,
  "startup_timeout_sec": null,
  "tool_timeout_sec": null
}

Verification

  • git merge-tree --write-tree HEAD main: 0 conflicts against upstream/main (509bd9b).
  • pytest tests/test_mcp.py tests/test_cli.py tests/test_store_privacy.py: 108 passed, 9 skipped (POSIX permission tests skipped on Windows).
  • Coverage (secfoo.mcp + secfoo.config): 93% (mcp.py), 83% (config.py), 91% combined.
  • secfoo sensor conformance -- python -m secfoo.sensor -m secfoo.runtime.conformance.sample_app: 6/6 checks passed.
  • secfoo skills validate examples/skills: 2 valid, 0 problem(s).
  • python scripts/check_pypi_version.py: __about__.py: 0.3.2.dev0 PyPI: 0.3.1 (exit 0).
  • ruff check: passed with 0 errors on all modified files (0 new findings in src/secfoo/cli.py).

Comment thread src/secfoo/mcp.py Fixed

@vsn411 vsn411 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this addresses the #190 review well:

  • it's scoped to Codex and built on _run_cli();
  • the shared write_private_text is now atomic and symlink-safe, instead of a second writer;
  • it uses tomlkit;
  • the support matrix lives in code, with a test against ADAPTERS;
  • it includes real codex-cli 0.172.0 output.

CI is green. Two things before we merge:

  1. Honour CODEX_HOME. Codex reads its config from $CODEX_HOME/config.toml when that variable is set, and falls back to ~/.codex otherwise. CODEX_CONFIG_PATH is hard-coded to ~/.codex/config.toml. For anyone who sets CODEX_HOME, the sync would report success while Codex never sees the server.
    • Please resolve the path at call time, e.g. Path(os.environ.get("CODEX_HOME", Path.home() / ".codex")) / "config.toml".
    • Please add a test that sets CODEX_HOME.
  2. Evidence for a remote server. The evidence shows a stdio server (npx mcp-remote). The case that matters most is a remote server with auth headers, written as url + http_headers, because that's how the default secfoo-memory server is synced. Please add codex mcp get <name> --json output for a url server with a header. It should show a streamable-HTTP transport with the header present (redact the value).

Nits (fine to fold in or leave):

  • When config.toml has no mcp_servers yet, tomlkit.table() writes an empty [mcp_servers] header above the [mcp_servers.<name>] tables. tomlkit.table(is_super_table=True) avoids that.
  • An inline mcp_servers = { ... } isn't handled. Returning a clear failed SyncResult for it is enough.
  • The new except OSError: pass around the chmod would trip ruff's try/except/pass rule (S110), which #168 is clearing elsewhere. A logger.debug(...) would avoid it.

Happy to merge once 1 and 2 are in.

vsn411 and others added 3 commits November 25, 2026 11:13
…or for an inline table

- codex_config_path() resolves $CODEX_HOME/config.toml at call time, the
  file Codex itself reads, falling back to ~/.codex.
- A new mcp_servers table is a super table, so only [mcp_servers.<name>]
  headers are written.
- An inline mcp_servers = { ... } returns a failed SyncResult and leaves
  the file untouched.
- The chmod fallback logs at debug level instead of a silent pass.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vsn411

vsn411 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Thanks for this. To get it merged sooner, I pushed the review items straight to your branch (14d9547):

  • codex_config_path() now reads $CODEX_HOME/config.toml when that is set, the same file Codex reads, and falls back to ~/.codex/config.toml. There are tests for both.
  • A new mcp_servers table is created as a super table, so the file gets only [mcp_servers.<name>] headers and no empty [mcp_servers] above them.
  • An inline mcp_servers = { ... } now returns a clear failed result and leaves the file untouched.
  • The chmod fallback logs at debug level instead of a silent pass.

I also merged current main. If you later get a chance to run codex mcp get <name> --json on a url server with a header, that output would still be welcome, but it no longer blocks this PR. I'll merge once CI is green.

@saryeljaramany

saryeljaramany commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for pushing 14d9547 and wrapping up the review items directly! I merged latest main (4fb374c) so the branch is up to date — all 9 CI checks (Test (py3.10), Test (py3.12), Test (py3.12, macos-15), Test (py3.12, windows-latest), Docs (links, version), CodeQL, and Analyze) are green on 7c9a204.

Here is the requested real-CLI verification for a remote streamable-http server with auth headers (url + http_headers) using $CODEX_HOME and codex-cli 0.172.0:

$ codex --version
codex-cli 0.172.0

$ secfoo mcp sync --agent codex
  ok secfoo-memory: added to C:\...\codex_home\config.toml

Generated $CODEX_HOME/config.toml (token redacted):

[mcp_servers.secfoo-memory]
url = "https://api.secfoo.com/mcp"

[mcp_servers.secfoo-memory.http_headers]
Authorization = "Bearer <REDACTED>"

Output of codex mcp get secfoo-memory --json (token redacted):

{
  "name": "secfoo-memory",
  "enabled": true,
  "disabled_reason": null,
  "transport": {
    "type": "streamable_http",
    "url": "https://api.secfoo.com/mcp",
    "bearer_token_env_var": null,
    "http_headers": {
      "Authorization": "Bearer <REDACTED>"
    },
    "env_http_headers": null,
    "http_headers_helper": null
  },
  "enabled_tools": null,
  "disabled_tools": null,
  "startup_timeout_sec": null,
  "tool_timeout_sec": null
}

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.

3 participants