Skip to content

feat: add sumo_qa_scan_repo MCP tool (#155 slice 3) - #230

Merged
sumithr merged 3 commits into
mainfrom
feat/issue-155-repo-map-mcp-tool
May 29, 2026
Merged

sumithr merged 3 commits into
mainfrom
feat/issue-155-repo-map-mcp-tool

Conversation

@sumithr

@sumithr sumithr commented May 28, 2026

Copy link
Copy Markdown
Owner

Stacked on #229 (slice 2) which is stacked on #222 (slice 1). When upstream PRs land on main, this PR's base auto-rebases.

Third implementation slice under #154's QA-native repo-understanding epic. Wraps the slice-2 deterministic scanner in a host-callable MCP tool so any host (Claude Code, IntelliJ AI Assistant, VS Code + Copilot) can map an arbitrary repo from the slash menu.

Refs #155.

Tool signature

sumo_qa_scan_repo(
    root: str,
    generator_version: str | None = None,
    write_to: str | None = None,
) -> RepoMapScanOutput | ErrorEnvelope

Design choices

  • Compact-by-default response. Returns per-type node counts, per-type + per-confidence edge counts, command counts by kind, warning counts by kind. NO node/edge arrays — a real scan of this repo produces 242 nodes / 84KB of JSON; the host budget can't carry that on every call. Callers who need the full artifact pass write_to=<path> and read it from disk.
  • generator_version defaults to the installed sumo-qa version via importlib.metadata.version("sumo-qa") so freshness metadata accurately identifies the producer.
  • Read-only annotation, openWorldHint=False — reads the local filesystem only, no network calls.
  • Failures (missing directory, file-as-root, scanner exceptions) come back through the standard {"isError": True, "error": {...}} envelope with an actionable hint.

Live demo (against this actual repo)

Server has 31 tools registered. New tool present:
  sumo_qa_scan_repo: YES

Compact summary returned to the host:
  node_count        : 242
  nodes_by_type     : {config: 29, docs: 48, source_file: 47, ci_workflow: 8,
                       infrastructure: 1, manifest: 2, test_file: 102, fixture: 5}
  edge_count        : 21  (all likely_tests, all high confidence)
  command_count     : 9   (extracted from pyproject.toml + package.json)
  warning_count     : 12  (11 unsupported_language + 1 skipped_file)
  artifact_path     : /tmp/sumo-qa-slice3-demo-repo-map.json
  artifact_bytes    : 84425

Full artifact round-trips cleanly through slice 1's load_repo_map.

Evidence

Gate Result
uv run pytest -q 1123 passed, 1 xfailed, 100% coverage on src/sumo_qa
uv run mypy src/sumo_qa/server.py src/sumo_qa/server_schemas.py Clean
uv run ruff check + ruff format --check Clean
MCP tool surface 31 tools (was 30); REQUIRED_TOOL_NAMES bumped 16 → 17
tests/fixtures/mcp_tools_list_snapshot.json Regenerated via scripts/regen_tools_list_snapshot.py

What landed

  • src/sumo_qa/server_schemas.py — new RepoMapScanOutput model (under existing _StrictBase)
  • src/sumo_qa/server.py — @mcp.tool registration, _package_version() helper, _build_scan_summary() aggregator, _HINT_SCAN_REPO
  • src/sumo_qa/installer.py — sumo_qa_scan_repo added to REQUIRED_TOOL_NAMES; doctor/verify handshake fails if a host install drops it
  • tests/test_server_repo_map_tool.py — 10 new tests (registration, annotation shape, declarative description, compact summary, optional write_to + slice-1 round-trip, default vs explicit generator_version, both error-envelope arms)
  • tests/test_server.py, tests/test_installer_verify.py, tests/test_skill_tool_crossref.py — updated for the new tool name
  • tests/fixtures/mcp_tools_list_snapshot.json — regenerated

Notes

  • A repo-walk SKILL.md update referencing sumo_qa_scan_repo is a small follow-up (the skill-tool-crossref test currently whitelists the tool as a standalone utility).
  • Codex adversarial review on slices 2 + 3 is still pending — I'll re-run it before merge once usage resets and surface findings in a follow-up commit.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0f2599b24f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/sumo_qa/server.py Resolved
sumithr pushed a commit that referenced this pull request May 28, 2026
The tool writes the full repo-map artifact to an arbitrary path when
write_to is set, so advertising readOnlyHint=True was misleading — a host
that trusts that hint could auto-run it or skip write confirmation and
silently overwrite a local file. Register with _writer_local (the same
annotation the other file-writing tools use) and assert the writer shape
in the registration test.

Addresses the P2 Codex review finding on PR #230.
@sumithr

sumithr commented May 28, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 27a98aa0e7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/sumo_qa/server.py Resolved
@sumithr
sumithr force-pushed the feat/issue-155-repo-map-scanner branch from 1110cf1 to ac24533 Compare May 29, 2026 00:06
Base automatically changed from feat/issue-155-repo-map-scanner to main May 29, 2026 00:48
t added 2 commits May 29, 2026 02:53
Third implementation slice under #154's QA-native repo-understanding
epic. Wraps the slice-2 deterministic scanner in a host-callable MCP
tool so any host (Claude Code, IntelliJ AI Assistant, VS Code + Copilot)
can map an arbitrary repo from the slash menu.

Tool signature:

    sumo_qa_scan_repo(
        root: str,
        generator_version: str | None = None,
        write_to: str | None = None,
    ) -> RepoMapScanOutput | ErrorEnvelope

Design choices:

- Compact-by-default response: per-type node counts, per-type +
  per-confidence edge counts, command counts by kind, warning counts
  by kind. NO node/edge arrays — a real scan of this repo produces
  242 nodes and 84KB JSON; the host budget can't carry that on every
  call. Callers who need the full artifact pass `write_to=<path>`
  and read it from disk.
- `generator_version` defaults to the installed sumo-qa version via
  `importlib.metadata.version("sumo-qa")` so the artifact's freshness
  metadata accurately identifies the producer.
- Read-only annotation, openWorldHint=False — the tool reads the
  local filesystem only, no network calls.
- Failures (missing directory, file-as-root, scanner exceptions) come
  back through the standard `{"isError": True, "error": {...}}`
  envelope with an actionable hint.

Wired in src/sumo_qa/server.py via `@mcp.tool`; output schema is the
new `RepoMapScanOutput` in server_schemas.py (under the existing
`_StrictBase`). REQUIRED_TOOL_NAMES in installer.py bumped from 16 to
17 — the doctor / verify handshake fails if a host install drops it.

10 new tests in tests/test_server_repo_map_tool.py cover registration,
annotation shape, declarative description, compact summary, optional
write_to + slice-1 load_repo_map round-trip, default vs explicit
generator_version, and both error-envelope arms. Existing
test_server / test_installer_verify / test_skill_tool_crossref
updated for the new tool name.

Full suite: 1123 passed, 100% coverage; mypy + ruff clean. Live demo
on this repo produced 242 nodes / 21 high-confidence likely_tests
edges / 9 commands / 12 warnings, 84425-byte artifact, all schema-
validated.

Refs #154.
The tool writes the full repo-map artifact to an arbitrary path when
write_to is set, so advertising readOnlyHint=True was misleading — a host
that trusts that hint could auto-run it or skip write confirmation and
silently overwrite a local file. Register with _writer_local (the same
annotation the other file-writing tools use) and assert the writer shape
in the registration test.

Addresses the P2 Codex review finding on PR #230.
@sumithr
sumithr force-pushed the feat/issue-155-repo-map-mcp-tool branch from 27a98aa to e6b98d8 Compare May 29, 2026 00:55
A relative write_to (the conventional .sumo-qa/repo-map.json) was resolved
against the MCP server's cwd, so when root != cwd the artifact landed in the
wrong workspace and downstream repo-map consumers wouldn't find it. Resolve
non-absolute write_to as Path(root) / write_to; absolute paths unchanged.
Addresses the P2 Codex review finding on PR #230.
@sumithr
sumithr merged commit 97625fe into main May 29, 2026
30 checks passed
@sumithr
sumithr deleted the feat/issue-155-repo-map-mcp-tool branch May 29, 2026 01:13
sumithr added a commit that referenced this pull request May 29, 2026
…#233)

## What

First consumer of the repo-map: `sumo_qa_analyze_diff_impact`. Given a
set of changed files it uses the persisted `.sumo-qa/repo-map.json`
(live-scan fallback) to answer the QA-native question — **which tests
exercise these changes, and which changed sources have no mapped
coverage (the risk surface)?**

This is the first cut of **issue #156** ("Add repo-map query and
diff-impact analysis tools"), branched off slice 3 so the diff shows
only the slice-4 delta. Scope is deliberately the **diff-impact tool
only**; `sumo_qa_query_repo_map` and the skill-wiring
(`reviewing-before-merge` / `preparing-for-work` / `strategising`) are
follow-up slices.

## How

Mirrors the slice-2 (pure service) + slice-3 (thin MCP wrapper) split:

- **`src/sumo_qa/repo_map_impact.py`** (new) — pure
`analyze_diff_impact(repo_map, changed_files) -> DiffImpact` (no I/O);
plus `changed_files_from_git(root, base_ref)` which diffs the working
tree against `merge-base(base_ref, HEAD)` using `git diff --name-only
-z` (clean GIT_* env + toplevel cross-check, same hygiene as the
scanner).
- **`repo_map_models.py`** — `ImpactNode` + `DiffImpact` models.
- **`server_schemas.py`** — compact `DiffImpactOutput` (bounded by the
changeset, no full node/edge arrays).
- **`server.py`** — the `sumo_qa_analyze_diff_impact` MCP tool: loads
the artifact (ignores a foreign-root artifact, falls back to a live
scan), resolves changed files from an explicit list or `base_ref`,
detects staleness vs HEAD, and optionally writes a
`.sumo-qa/diff-impact.json` overlay. Registered `_writer_local` from the
start (carries forward the PR #230 read-only-hint lesson).

## Output (per changeset)

`changed_nodes`, `affected_nodes` (one-hop), `related_tests`,
`unmapped_files`, **`risk_surface`** (changed sources with no mapped
test), `suggested_inspections`, plus `is_stale` / `used_live_scan` flags
and warning counts.

## Tests / verification

- New: `tests/test_repo_map_impact.py` (core + git helper),
`tests/test_server_diff_impact_tool.py` (wrapper). Contract/registration
tests + tools-list snapshot updated (31 → 32 tools; installer
required-tool count 17 → 18).
- Full suite: **1147 passed, 1 xfailed, 100% coverage**; ruff +
ruff-format + mypy(py3.10) clean.
- Live demo on this repo: changed sources mapped to their tests, risk
surface empty (both covered).

## Review

Codex reviewed the diff (two rounds): round 1 → diff against merge-base
not base-tip, `-z` for non-ASCII paths, foreign-artifact guard; round 2
→ suppress a redundant live-scan warning, tighten the foreign-artifact
test, sync the docstring. All applied and re-verified green. The GitHub
Codex bot will also review on open.

Stacked on #230 (slice 3). Merge order: #222 → #229 → #230 → this.

---------

Co-authored-by: t <t@t>
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.

1 participant