Skip to content

feat(mcp): add secfoo mcp serve stdio server, single-source plugin builder, and server.json - #229

Open
SriRamkunamsetty wants to merge 1 commit into
secfoo-com:mainfrom
SriRamkunamsetty:feat/mcp-serve-foundation-224
Open

SriRamkunamsetty wants to merge 1 commit into
secfoo-com:mainfrom
SriRamkunamsetty:feat/mcp-serve-foundation-224

Conversation

@SriRamkunamsetty

Copy link
Copy Markdown
Contributor

Part of #224

Summary

  • Added stdio MCP server (src/secfoo/mcp_server.py) wired via secfoo mcp serve [--root PATH ...] exposing 7 tools (list_skills, submit_report,
    un_skill, list_findings, get_run, export_findings, cloud_status) and one MCP prompt per built-in skill from load_all_skills().
  • Enforced strict local-first defaults and key isolation: unconfigured or view-only keys (sfc_view_) never upload and never leave the machine; only ingest keys (sfc_ingest_ from SECFOO_CLOUD_API_KEY or ~/.secfoo/cloud.toml) upload via sync_run; secrets never appear in tool payloads or configs.
  • Enforced workspace root scoping (--root / Path.cwd()) and output contract validation (�alidate_report) before storing runs in SQLite.
  • Added scripts/build_plugins.py (--target all|claude|cursor, --check, --mcpb) to generate platform plugin skills from src/secfoo/skills/definitions/*.md without prompt duplication, plus official MCP Registry manifest server.json.

Verification

  • pytest -p no:langsmith -p no:hypothesis tests/test_mcp_server.py tests/test_plugins.py tests/test_docs_consistency.py -q -> 26 passed, 92% combined coverage (src/secfoo/mcp_server.py 90%, scripts/build_plugins.py 97%).
  • Live stdio MCP handshake (python -m secfoo.cli mcp serve --root .) -> initialized cleanly, enumerated 7 tools & 9 skill prompts.

uff check . & �andit -c .bandit -ll -r src/secfoo -q -> passed.

  • git merge-tree --write-tree HEAD upstream/main -> zero conflicts.

Comment thread src/secfoo/mcp_server.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 is a strong foundation for #224. The workspace-root check, view keys never uploading, keys never appearing in tool output, and the --check drift test for generated skills are exactly what we wanted.

Before we merge (#230 and #231 are stacked on this, so they'll pick up the fixes):

  1. Failing test on all 4 platforms. test_mcp_serve_cli_help_and_root_forwarding looks for --root in Rich-formatted help, and the color codes split the string. Invoke with env={"NO_COLOR": "1", "TERM": "dumb"} (or strip ANSI) before asserting.
  2. Version pins. server.json (and the plugin/mcpb manifests in #230/#231) pin 0.3.2, which is the latest on PyPI and has no mcp serve, so the MCP Registry entry would install a version that can't start. Use the release that will ship this (0.3.3), and add a test that the manifest versions equal secfoo.__about__.__version__ without the .devN suffix, so they can't drift again.
  3. run_skill blocks the server, and the host agent can spend money with it. execute_runs is synchronous inside an async def, so the stdio server stops answering (pings included) for the length of a run. Please:
    • run it with anyio.to_thread.run_sync (or make the tool sync so FastMCP offloads it);
    • pass a timeout;
    • add a max_cost_usd argument with a conservative default, enforced the same way as the CLI's --max-cost. The host agent, which reads untrusted repo text, chooses when to call this tool.
  4. SECFOO_CLOUD_API_KEY only works for submit_report. Runs started by run_skill sync through runner._try_cloud_sync → cloud.load_cloud_config(), which reads only cloud.toml. Either teach cloud.load_cloud_config() the env var (one place, so the CLI, runner and MCP server agree), or drop the env var and document secfoo cloud login only. Then _read_raw_cloud_credentials can go, along with the use of the private cloud._portal_origin.

Small: submit_report doesn't store overall_rating for Responsible AI reports (the runner does). Copy rai_report.overall_rating into complete_run.

@SriRamkunamsetty
SriRamkunamsetty force-pushed the feat/mcp-serve-foundation-224 branch from 8cab13a to a4ca93a Compare December 1, 2026 12:15
Copilot AI balanced review requested due to automatic review settings December 1, 2026 12:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@SriRamkunamsetty

Copy link
Copy Markdown
Contributor Author

Rebased onto latest main and addressed all review items (a4ca93a):

  1. ANSI --root CI failure: Updated test_mcp_serve_cli_help_and_root_forwarding to invoke Click/Typer with env={"NO_COLOR": "1", "TERM": "dumb"} (verified under FORCE_COLOR=1).
  2. Release version alignment & drift guard: Bumped server.json to 0.3.3 and asserted it matches secfoo.__about__.__version__ stripped of .devN in tests/test_plugins.py.
  3. Non-blocking & bounded run_skill: Offloaded execute_runs via anyio.to_thread.run_sync, added timeout: int = 600 (bounded cleanly), and added a conservative max_cost_usd: float | None = 1.0 gate checked consistently with CLI --max-cost.
  4. Unified cloud config (SECFOO_CLOUD_API_KEY): Taught secfoo.cloud.load_cloud_config() (and resolve_cloud_status()) to honor SECFOO_CLOUD_API_KEY + SECFOO_CLOUD_PORTAL_URL alongside ~/.secfoo/cloud.toml, so runner._try_cloud_sync, CLI, and MCP server agree without duplicating credential parsing or importing _portal_origin (view keys sfc_view_* remain refused for sync).
  5. Responsible AI overall_rating + CodeQL: Forwarded rai_parsed.overall_rating into repo.complete_run in submit_report, and logged cleanly in the JSONDecodeError fallback in _collect_export_records.

Verified locally: 116 passed, 5 skipped (Windows POSIX-mode skips), src/secfoo/cloud.py 97%, src/secfoo/mcp_server.py 90%, ruff check . and bandit passed.

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.

4 participants