Skip to content

fix(mcp): report a missing agent CLI instead of crashing - #181

Merged
vsn411 merged 3 commits into
secfoo-com:mainfrom
cnYui:fix/mcp-missing-agent-cli
Nov 20, 2026
Merged

vsn411 merged 3 commits into
secfoo-com:mainfrom
cnYui:fix/mcp-missing-agent-cli

Conversation

@cnYui

@cnYui cnYui commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Closes #169

What does this change, and why?

secfoo mcp sync --agent gemini and --agent agent call the gemini / agent CLI through subprocess.run without checking that it is installed. When the binary is missing, the sync crashes with a FileNotFoundError traceback instead of the one-line failure the CLI already knows how to print.

This change checks shutil.which first and returns a single failed SyncResult that names the missing CLI, so the command exits 1 with a clear message. For agent, the check runs before the Cursor mcp.json is created or written, so nothing is changed when the CLI is absent.

Scope is limited to these two entry points. The gemini and agent code paths are otherwise unchanged. PR #180 also edits sync_cursor (non-object mcp.json); the two changes touch different lines and may need a trivial rebase.

Testing

  • pytest tests/test_mcp.py: 15 passed, including two new tests (test_sync_gemini_reports_missing_cli_instead_of_crashing, test_sync_cursor_reports_missing_cli_before_writing_config). An autouse fixture makes the existing sync tests assume the CLIs are on PATH, so they keep exercising the same behavior.
  • ruff check src/secfoo/mcp.py tests/test_mcp.py: the same 3 PLW1510 findings (subprocess.run without check=) as on main; no new findings.
  • Full pytest tests on Windows: 1904 passed, 18 failed, 4 skipped. I ran the failing modules on an unmodified main checkout and they fail there too (skill packs, memory, port guard, web dashboards, adversarial eval). One adversarial-eval test is flaky: it passed alone on this branch and failed alone on main. None of these failures relate to mcp.py.

🤖 Generated with Claude Code

`secfoo mcp sync` called `gemini` or `agent` through subprocess without
checking that the binary exists, so a missing CLI raised FileNotFoundError
and printed a traceback. Check PATH first and return one failed SyncResult
that names the missing CLI. For `agent`, this happens before the Cursor
config is written.

Co-Authored-By: Claude Haiku 5.5 <[email protected]>
@cnYui
cnYui requested a review from vsn411 as a code owner November 20, 2026 21:19
Satyanarayana Vuppala and others added 2 commits November 20, 2026 23:09
On Windows npm installs gemini/agent as a .cmd shim. shutil.which finds
it via PATHEXT, but subprocess.run with a bare "gemini" does not, so the
new installed-check passed and sync still raised FileNotFoundError.
Route the three CLI calls through _run_cli(), which launches the
resolved path (same approach as BaseAdapter.run).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vsn411
vsn411 merged commit 1a9586a into secfoo-com:main Nov 20, 2026
7 checks passed
@github-actions

Copy link
Copy Markdown

Leaderboard update

cnYui now has 3 points (rank #11). 22 more to reach Bronze.

Full leaderboard

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.

Bug: secfoo mcp sync shows a traceback when gemini or Cursor's agent CLI isn't installed

2 participants