Skip to content

feat(cli): derive apm mcp install forwarded options from apm install - #3633

Merged
Daniel Meppiel (danielmeppiel) merged 5 commits into
mainfrom
danielmeppiel-mcp-install-help-forwarded-options
Nov 12, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 5 commits into
mainfrom
danielmeppiel-mcp-install-help-forwarded-options

Conversation

@danielmeppiel

@danielmeppiel Daniel Meppiel (danielmeppiel) commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Description

TL;DR

apm mcp install --help now lists the options it forwards to apm install as real Click options, cloned from apm install's own definitions. Help text, accepted values and shell completion come from one source and cannot drift. Forwarded installs behave as before: raw values are re-emitted to apm install unchanged.

Fixes #3588

Note

Local preflight skipped by maintainer instruction (2026-11-12); CI is the gate.

Problem (WHY)

  • The forwarded flags were hand-written prose inside the help= string of apm mcp install (src/apm_cli/commands/mcp.py), not Click options, so they were not shell-completable.
  • The prose had already drifted: -t/--target read "Agent target(s) to deploy to" while apm install says "Target harness(es) to deploy to" ([cli-consistency] CLI Consistency Report — 2026-11-11 #3554).
  • The CLI reference table copied the same list again and was missing --target and --trust-transitive-mcp.
  • [!] The old regression test only checked that flag names appeared in help, so wording drift passed silently.

The issue states the goal: help text, validation and shell completion should "stay in sync with apm install automatically". The repo's architecture rule says call sites should route "THROUGH that owner instead of re-deriving the answer locally" (.github/instructions/architecture.instructions.md).

Approach (WHAT)

# Fix
1 mcp install uses a click.Command subclass that clones the selected apm install Option objects on first use. Help, type, choices and metavar all come from apm install.
2 Cloned options record their raw command-line value and are re-emitted to apm install as --flag value before any -- separator. Defaults are never materialised.
3 Help renders them under a "Forwarded install options" section. Every other apm install option (except the alias-owned --mcp) is borrowed hidden: Click parses it with install's own arity and forwards it raw, so a value like --root --dry-run stays attached. The help notes that --mcp NAME is implied.
4 The regression test derives expected flag spelling and help text from apm install's own get_help_record.

Implementation (HOW)

  • src/apm_cli/commands/mcp.py: _FORWARDED_INSTALL_PARAMS holds only the shown selection (install parameter names). _borrow_install_options() lazily clones every install option through _ForwardedInstallOption.from_install_option and hides the unselected ones. It clones them from apm_cli.commands.install.install, so apm startup keeps install lazily imported (verified: apm mcp --help does not import it). _ForwardedInstallOption.consume_value captures the raw value when the source is COMMANDLINE, and to_install_args rebuilds the tokens. expose_value=False keeps converted values out of the callback.
  • tests/unit/test_cli_consistency.py: the FU-3 test now compares each forwarded flag's install help record, with whitespace removed, against the "Forwarded install options" section.
  • tests/unit/test_mcp_command.py: adds tests for borrowed definitions, verbatim raw forwarding (-t a,b, -g, repeated --env, pass-through --runtime, -- tail), install-identical validation errors, and shell completion of names and choices.
  • Docs: reference/cli/mcp.md replaces the copied table with the flag list and a link to apm install. apm-guide commands.md lists the full forwarded set.

Diagrams

How a forwarded flag gets from apm mcp install to apm install (new parts boxed):

flowchart LR
    U["apm mcp install api -t claude --env A=1 -- npx srv"] --> P["Click parse with borrowed install options"]
    subgraph NEW["New in this PR"]
        B["_borrow_install_options: clone apm install Options"] --> P
        P --> R["consume_value records raw value"]
        R --> T["to_install_args rebuilds tokens"]
    end
    T --> F["apm install --mcp api --target claude --env A=1 -- npx srv"]
Loading

Trade-offs

  • Shown selection stays in mcp.py. Which install options to surface is a product choice. It is kept to the 14 flags the old help and the issue name, because new flags are out of scope. The definitions are never copied, and the test fails if apm install drops or rewords one.
  • Class swap on a shallow copy (clone.__class__ = _ForwardedInstallOption) instead of rebuilding each Option from attributes. The subclass adds no state, and rebuilding would mean another hand-maintained attribute list.
  • Raw re-emission instead of serialising converted values: TargetParamType normalises values, so re-emitting the raw token keeps apm install behaviour unchanged. Short flags are forwarded in their long form (-g becomes --global); apm install treats both spellings the same.
  • All install options parsed, 14 shown: borrowing only the shown set let a pass-through option lose a flag-shaped value (Copilot review). Hidden borrowing keeps install's arity without adding help surface.
  • No architecture-registry owner record: this deduplicates help text rather than a durable runtime decision. The behavioural regression test is the guard.

Benefits

  1. Shell completion works on apm mcp install for the 14 forwarded options and their choices (for example --transport <TAB>).
  2. Zero hand-written forwarded help text remains. The --target wording drift from [cli-consistency] CLI Consistency Report — 2026-11-11 #3554 is fixed by construction.
  3. Invalid values, such as --transport bogus, fail at apm mcp install with the same Click error as apm install.
  4. A test fails if the forwarded set or any help string drifts from apm install. All 4 mutation checks below fail the suite.

Validation

Targeted tests (after merging current main)
$ .venv/bin/python -m pytest -q -p no:xdist tests/unit/test_mcp_command.py tests/unit/test_cli_consistency.py tests/unit/policy/test_help_consistency.py
70 passed in 10.67s

Red before the fix: 5 failed, 12 passed (the new tests plus the rewritten FU-3 test).

Mutation-break checks (each restored after)
Mutation Result
Drop verbose from the forwarded selection 1 failed
Hand-override --target help with the old prose 2 failed
Stop recording raw values 5 failed
Keep plain click.Option (no subclass) 6 failed
Borrow only the shown options (no hidden pass-through) 2 failed
Drop the '--mcp NAME is implied' help note 1 failed
Lint mirror (CI-equivalent)
ruff check (src tests scripts/...)            All checks passed!
ruff format --check                           2152 files already formatted
pylint R0801                                  10.00/10
bash scripts/lint-auth-signals.sh             [+] auth-signal lint clean
bash scripts/lint-architecture-boundaries.sh  exit 0
Manual end-to-end
$ apm mcp install fetch --dry-run -t copilot -- npx -y srv
[i] [dry-run] would add MCP server 'fetch' to .../apm.yml
$ apm mcp install fetch --transport bogus
Error: Invalid value for '--transport': 'bogus' is not one of 'stdio', 'http', 'sse', 'streamable-http'.
$ _APM_COMPLETE=bash_complete COMP_WORDS="apm mcp install x --transport " COMP_CWORD=5 apm
plain,stdio / plain,http / plain,sse / plain,streamable-http

Scenario evidence

Scenario Test Principle
Help lists forwarded options with apm install's exact text test_cli_consistency.py::test_mcp_install_help_forwarded_options_complete Consistency
Forwarded install unchanged (values, repeats, pass-through, --) test_mcp_command.py::TestMcpInstallAlias::test_forwards_raw_option_values_verbatim, ::test_pass_through_value_shaped_like_a_flag_stays_attached, ::test_hidden_install_options_forward_but_stay_out_of_help and the existing alias tests Backward compatibility
Validation matches apm install TestMcpInstallAlias::test_forwarded_option_validation_matches_install Consistency
Shell completion works TestMcpInstallAlias::test_forwarded_options_shell_complete DevX

How to test

  • apm mcp install --help: see the "Forwarded install options" section, worded exactly like apm install --help.
  • apm mcp install fetch --dry-run -t copilot -- npx -y srv: dry-run add succeeds.
  • apm mcp install fetch --transport bogus: Click choice error, exit 2.
  • With completion enabled, apm mcp install x --transport <TAB> offers the four transports.

Issue and approved scope

Issue: Fixes #3588

Human scope-approval comment: #3588 (comment) (review contact Daniel Meppiel (@danielmeppiel))

This PR completes the issue: real options with help from the shared definitions, shell completion, a drift test, unchanged forwarding behaviour, and updated CLI reference plus apm-guide commands.md. No new flags, renames, apm install changes or other aliases.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass (targeted files only locally; CI is the authority)
  • Added tests for new functionality (if applicable)

Spec conformance (OpenAPM v0.1)

  • Spec edit
  • Manifest edit
  • Test edit
  • CONFORMANCE.{md,json} regenerated
  • N/A -- this PR does not change OpenAPM-observable behaviour.

Co-authored-by: Copilot [email protected]

apm mcp install now declares the install options it forwards as real
Click options cloned from the apm install command, so help text,
validation and shell completion come from one definition. Raw values
are re-emitted to apm install unchanged.

Fixes #3588

Co-authored-by: Copilot App <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The alias parser can mistake a pass-through option’s flag-shaped value for its own flag, leaving --root without a value and breaking an otherwise valid install command.

1 open issue
What changed in this PR

This PR makes apm mcp install borrow option definitions from apm install, addressing #3588 by sharing help text, validation, and shell completion.

Changes:

  • Lazily clones selected install options and reconstructs explicitly supplied values for forwarding.
  • Adds regression coverage for help consistency, forwarding, validation, and completion.
  • Updates the CLI reference, usage guide, and changelog.
File Description
src/​apm_cli/​commands/​mcp.py Adds borrowed option definitions, grouped help, and argument reconstruction.
tests/​unit/​test_mcp_command.py Tests borrowed options, raw forwarding, validation, and completion.
tests/​unit/​test_cli_consistency.py Compares forwarded help against canonical install definitions.
packages/​apm-guide/​.apm/​skills/​apm-usage/​commands.md Updates the forwarded flag list and shared-help description.
docs/​src/​content/​docs/​reference/​cli/​mcp.md Replaces duplicated descriptions with a link to install documentation.
CHANGELOG.md Records the shared option help and completion changes.

Review effort: Balanced

Comment thread src/apm_cli/commands/mcp.py Resolved
@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

APM Review Panel: ship_with_followups

Eliminates MCP-install option drift by borrowing directly from apm install definitions; all 3 panelists converge, zero blocking findings, 17/17 tests green.

panel-mode=lean; personas=devx-ux-expert,test-coverage-expert,python-architect (adhoc: Click-internals design),apm-ceo

cc Sergio Sisternes (@sergio-sisternes-epam) -- a fresh advisory pass is ready for your review.

The panel is unanimous: this PR delivers exactly what #3588 asked for -- a single source of truth for forwarded install options in the MCP alias -- and does so with a design that minimises Click-internals coupling. The test-coverage-expert confirms all five user-promise surfaces (help drift, completion, validation, raw forwarding, e2e path) are defended by regression traps, with 17/17 passing. The python-architect validated the lazy-import, selection-only coupling, and raw re-emission design as sound.

The one substantive UX observation -- that forwarded help strings still carry '(requires --mcp)' inside a context where --mcp is implicit -- should not be fixed by rewriting the inherited strings: the approved scope and Done-when demand help text identical to apm install's definitions, and forking the strings would recreate the exact drift #3588 exists to eliminate. The right move is a one-line note in the command description that '--mcp NAME' is implied.

The python-architect's suggestion to extract the copy + class swap into a from_install_option classmethod is clean housekeeping with zero behaviour change.

Aligned with: Portable by manifest: forwarded options derive from the install path; single source of truth reduces cross-surface drift. Pragmatic as npm: the MCP alias mirrors apm install's own help and validation. OSS community driven: closes #3588 with a design that prevents future drift rather than patching it.

Panel summary

Persona B R N Takeaway
DevX UX Expert 0 1 0 Solid alias UX; forwarded help inherits '(requires --mcp)' which misleads in the alias context where --mcp is implicit.
Test Coverage Expert 0 0 0 All 5 user-promise surfaces (help drift, completion, validation, raw forwarding, e2e path) defended by regression traps; 17/17 passed.
Python Architect 0 1 0 Design is sound: selection-only coupling, lazy load, raw re-emission minimise Click-internals surface; tests pin the borrowing contract.

B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.

Top 2 follow-ups

  1. [DevX UX Expert] Add a note to the mcp install command description that '--mcp NAME' is implied, so the inherited '(requires --mcp)' parenthetical reads correctly in context. -- Stripping the parenthetical from cloned help would fork the strings and re-create drift; a command-level note preserves single-source identity.
  2. [Python Architect] Extract the copy + class swap into a _ForwardedInstallOption.from_install_option classmethod with a docstring warning about the init-bypass path. -- Makes the construction path discoverable and self-documenting; zero behaviour change.

Recommendation

Merge when CI is green. Both follow-ups are small and inside this PR's scope, so the merge worker folds them here rather than tracking them separately. The UX note is the higher-signal item; it is the only thing a user might notice in --help output.


Full per-persona findings

DevX UX Expert

  • [recommended] Forwarded help strings show '(requires --mcp)' inside apm mcp install --help, confusing users who are already in the --mcp context at src/apm_cli/commands/mcp.py:171
    Options like --transport, --url, --env, and --header carry '(requires --mcp)'. In apm mcp install, --mcp is implicit. Seeing it makes users wonder whether they must also pass --mcp.
    Suggested: adapt the display to the alias context. The CEO resolved this as a command-description note so the shared strings stay identical.

Test Coverage Expert

No findings.

Python Architect

  • [recommended] Extract the copy + class swap into a _ForwardedInstallOption classmethod so the init-bypass construction path is discoverable at src/apm_cli/commands/mcp.py:159
    copy.copy + class reassignment is the least-coupled option, but it silently bypasses init. A classmethod factory encapsulates the unusual construction and gives a docstring site for the warning.
    Suggested: _ForwardedInstallOption.from_install_option(source) returning the clone with expose_value=False.

This panel is advisory. It does not block merge. Re-apply the
panel-review label after addressing feedback to re-run.


Generated by autopilot-pr-review-worker. This comment is AI-generated and may contain errors.

Borrow every apm install option (except the alias-owned --mcp) so Click
parses pass-through values with install's own arity; only the 14 shown
options appear in help and completion, the rest are hidden. A value like
'--root --dry-run' now stays attached to its option, as in apm install
(addresses Copilot inline on src/apm_cli/commands/mcp.py:235).

Also folds panel follow-ups: a from_install_option factory documents the
init-bypassing clone (python-architect), and the help states that
'--mcp NAME' is implied so inherited '(requires --mcp)' notes read
correctly without forking install's help strings (devx-ux-expert).

Co-authored-by: Copilot App <[email protected]>
@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

APM Review Panel: ship_now

apm mcp install --help now surfaces its 14 forwarded install options as real Click options cloned from apm install, with install's arity for pass-through values and mutation-verified regression tests.

panel-mode=delta; personas=python-architect,devx-ux-expert,test-coverage-expert,apm-ceo

cc Sergio Sisternes (@sergio-sisternes-epam) -- a fresh advisory pass is ready for your review.

Delta since the last advisory (head cda1333 -> e25cc28): both in-scope follow-ups from the lean panel are folded: the help now notes that '--mcp NAME' is implied (inherited strings unchanged), and the clone path lives in a _ForwardedInstallOption.from_install_option factory. The Copilot inline finding was a legitimate parsing bug: a pass-through option could lose a flag-shaped value (--root --dry-run). It is fixed: every apm install option except --mcp is now borrowed (14 shown, the rest hidden), so Click parses pass-through values with install's own arity. Regression tests and mutation-break evidence back the fix.

All three delta panelists returned zero findings. The python-architect confirms the auto-borrowing is sound: the only callback is a pure normalizer, only command-line values are forwarded, and the factory has an nargs guard. The devx-ux-expert confirms that hidden options only error on flags the user typed. The test-coverage-expert confirms the flag-shaped-value, hidden-forward, borrowed-set and help-note promises are mutation-verified traps. There is nothing to arbitrate.

Aligned with: Pragmatic as npm: options appear where users look for them, with install's validation and completion. OSS community driven: closes #3588. Install options added later are parsed and forwarded automatically, and the drift test fails if a shown option's help diverges from apm install.

Panel summary

Persona B R N Takeaway
Python Architect 0 0 0 Delta auto-borrowing of install options is architecturally sound: pure callback, COMMANDLINE-only forwarding, nargs guard in factory, set-equality test catches drift.
DevX UX Expert 0 0 0 Delta resolves prior '(requires --mcp)' finding with a contextual help note; hidden options error only on flags the user typed, no UX regression.
Test Coverage Expert 0 0 0 All delta tests pass. Flag-shaped-value, hidden-forward, borrowed-set, and help-note promises are mutation-verified regression traps. No silent-drift gap.

B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.

Recommendation

Every follow-up from the lean panel is folded. The flag-value parsing bug is fixed and covered by regression tests. Three independent delta panelists returned zero findings. CI is green on e25cc28. Merge once the CODEOWNER approves. No follow-ups remain.


Full per-persona findings

Python Architect

No findings.

DevX UX Expert

No findings.

Test Coverage Expert

No findings.

This panel is advisory. It does not block merge. Re-apply the
panel-review label after addressing feedback to re-run.


Generated by autopilot-pr-review-worker. This comment is AI-generated and may contain errors.

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 8cd567e into main Nov 12, 2026
27 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-mcp-install-help-forwarded-options branch November 12, 2026 15:37
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 12, 2026
Resolve conflicts with #3633 (forwarded apm install options) and #3630 (bootstrap author), keeping the APM_HOME wording.

Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 17, 2026
* fix(tests): restore release-gate lanes for 0.36.0

Main's tag-gate lanes (build-release push + manual-build-release) were red
on runs 43381609442, 43381682871 and 43394173235. PR CI never runs them.

Product regressions (Windows/real installs), fixed:
- Hook cleanup removed nothing on Windows: remove_stale_deployed_files
  looked up recorded hashes with POSIX keys while callers passed native
  backslash keys, so content proof failed closed (#3672, Refs #3649).
- describe_path_obstruction returned None on Windows, which reports a
  directory-for-file as EACCES and a file-for-parent as ENOENT instead of
  EISDIR/ENOTDIR (#3709, Refs #3678).
- Skill preflight refused claimed members of an unclaimed, populated skill
  directory that materialization leaves alone, failing a local bundle
  install (Refs #3625).

Stale tests (behaviour changed intentionally), updated:
- policy chain mocks now return real PolicyFetchResult (#2933, Refs #2753)
- bare-cache/downloader/anonymous-https fixtures use real Git checkouts
  (#3603, Refs #3457)
- mcp install help, registry error wording, deps why -g help
  (#3633 Refs #3588, #2803 Refs #2478, #3614 Refs #2884)
- downloader stub carries carried_licenses (#3646, Refs #3556)
- frozen-hash lifecycle uses a generic git host so -g URL validation
  uses git ls-remote instead of a live api.github.com 404 (#3672)

New Windows-shaped regression tests are marked windows_compat.

Co-authored-by: Copilot App <[email protected]>

* chore: spec waiver for release-gate repair

apm-spec-waiver: restores pre-existing behaviour on Windows and in skill preflight; no OpenAPM-observable change

Co-authored-by: Copilot App <[email protected]>

---------

Co-authored-by: danielmeppiel <[email protected]>
Co-authored-by: Copilot App <[email protected]>
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.

[FEATURE] Derive apm mcp install --help forwarded options from apm install instead of hand-written prose

2 participants