Repository navigation
fix(pack): never ship APM-managed root .mcp.json servers - #3971
Closed
Daniel Meppiel (danielmeppiel) wants to merge 2 commits into
Closed
Daniel Meppiel (danielmeppiel) wants to merge 2 commits into
Daniel Meppiel (danielmeppiel) wants to merge 2 commits into
Conversation
apm install renders the package's own MCP dependencies into root .mcp.json for copilot and claude. apm pack then referenced that consumer render from the Codex plugin.json and copied it into Claude manifests and bundles, so pack output depended on whether install had run and could ship the author's credential headers. core/plugin_manifest.py now owns which root .mcp.json servers are APM-managed (apm_managed_mcp_names, from apm.lock.yaml) and every pack read of the project root excludes them: Codex references .mcp.json only when it holds no managed server (warning when authored servers are also withheld), Claude and the plugin bundle filter managed servers out, and an unreadable lockfile withholds the file (fail closed). Fixes #3966 Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel)
requested a review
from Sergio Sisternes (sergio-sisternes-epam)
as a code owner
November 19, 2026 18:23
Co-authored-by: Copilot App <[email protected]>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Incomplete MCP ownership filtering leaves managed servers in Claude bundles, including previously generated manifests, and allows Codex to reference configuration files containing credential headers.
3 open issues
What changed in this PR
This PR addresses #3966 by filtering APM-managed root .mcp.json servers from pack output, reducing the risk of distributing development MCP configuration and credentials.
Changes:
- Adds centralized lockfile-based ownership checks for Codex references, Claude manifests, and Claude bundles.
- Adds unit and lifecycle regression tests for managed servers, mixed ownership, and unreadable lockfiles.
- Updates pack documentation, usage guidance, and the security changelog.
| File | Description |
|---|---|
tests/unit/core/test_plugin_manifest.py |
Tests ownership filtering and unreadable-lock handling. |
tests/integration/test_pack_mcp_ownership_lifecycle.py |
Compares pack output before and after install. |
src/apm_cli/core/plugin_manifest.py |
Adds ownership checks and filters generated manifests. |
src/apm_cli/bundle/plugin_exporter.py |
Filters managed root MCP servers during bundle export. |
packages/apm-guide/.apm/skills/apm-usage/commands.md |
Updates pack usage guidance. |
docs/src/content/docs/reference/cli/pack.md |
Documents Claude filtering and Codex reference rules. |
CHANGELOG.md |
Records the security fix. |
Review effort: Balanced
|
|
||
| # MCP -- root package wins on server-name collision | ||
| root_mcp = _collect_mcp(project_root) | ||
| root_mcp = _collect_mcp(project_root, exclude_apm_managed=True) |
Comment on lines
+280
to
+283
| names = set(lock.mcp_servers) | set(lock.mcp_configs) | ||
| for servers in lock.mcp_target_servers.values(): | ||
| names.update(servers) | ||
| return frozenset(str(name) for name in names) |
| _warn_unknown_mcp_ownership(logger) | ||
| return {} | ||
| servers = {name: server for name, server in servers.items() if name not in managed} | ||
| return _sanitize_mcp_servers(servers, logger=logger) |
6 of 10 tasks
Collaborator
Author
Daniel Meppiel (danielmeppiel)
added a commit
that referenced
this pull request
Nov 19, 2026
* fix(lockfile): stamp the running APM on every substantive lock write (#3962) Harvested from #3977. Co-authored-by: Copilot App <[email protected]> * fix(bundle): warn when a bundle's lockfile was written by a newer APM (#3963) Harvested from #3978. Co-authored-by: Copilot App <[email protected]> * fix(marketplace): origin-check every marketplace resolution entry point (#3959) Harvested from #3976; the positional install reads the lock lazily. Co-authored-by: Copilot App <[email protected]> * fix(install): preview object-form marketplace dependencies in --dry-run (#3960) Harvested from #3973. Co-authored-by: Copilot App <[email protected]> * fix(prune): keep object-form marketplace dependencies (#3960) Harvested from #3974. Co-authored-by: Copilot App <[email protected]> * fix(install): retire a local bundle's MCP servers when a reinstall drops them (#3956) Harvested from #3975. Co-authored-by: Copilot App <[email protected]> * fix(update,audit): honour the current executables decision after apm deny (#3958) Harvested from #3981. Co-authored-by: Copilot App <[email protected]> * fix(approve): correct the remediation after apm deny; approve clears a same-store deny (#3957) Harvested from #3979. Co-authored-by: Copilot App <[email protected]> * fix(approve): match package names exactly and refuse ambiguous names A partial name could grant or deny execution for another package. Co-authored-by: Copilot App <[email protected]> * fix(pack): never ship APM-managed root .mcp.json servers (#3966) Harvested from #3971. Co-authored-by: Copilot App <[email protected]> * fix(install): the trust owner reads the scope manifest, so -g honours executables: (#3954) exec_trust_context_for_project takes the manifest file instead of deriving apm.yml from a caller-chosen root; -g resolves APM_HOME/apm.yml through core.scope.get_manifest_path. A closed-world guard registers every caller. Supersedes #3969 and keeps its lifecycle test. Co-authored-by: Copilot App <[email protected]> * fix(deps): deps update and lock --update revalidate marketplaces (#3961) Every caller of the shared install entry now runs inside a registered catalog-freshness envelope; the guard is closed-world. Co-authored-by: Copilot App <[email protected]> * fix(lifecycle): lifecycle test --execute fires through the script gate APM_NO_SCRIPTS, org executables.deny_all and project script trust now apply; LifecycleScriptRunner is built only by build_runner_from_context, guarded closed-world by the new lifecycle-script-firing-gate owner. Co-authored-by: Copilot App <[email protected]> * test(approve): exact and unambiguous approve/deny matching Co-authored-by: Copilot App <[email protected]> * fix(pack): root .mcp.json reads exclude APM-managed servers by default (#3966) The only opt-out is a dependency's own authored .mcp.json; a closed-world guard refuses any other. Co-authored-by: Copilot App <[email protected]> * test(architecture): a bundle reinstall must reconcile its owned MCP servers (#3956) Co-authored-by: Copilot App <[email protected]> * test(architecture): guard object-form lock-row mapping and exact approve matching Co-authored-by: Copilot App <[email protected]> * fix(update): read packages as replay does; skip the policy fetch when the gate was never on (#3958) Harvested from #3981 (b4cface, cb015e6); the trust read uses the scope manifest. Co-authored-by: Copilot App <[email protected]> * fix(install): -g MCP admission reads trust from APM_HOME/apm.yml (#3954) Harvested from #3969 (5c2cab2). Co-authored-by: Copilot App <[email protected]> * fix(targets): apm targets honours targets: in apm.yml (#3792) Reads the manifest restriction through the same owner install uses. Co-authored-by: Copilot App <[email protected]> * fix(cli): user-facing text names current keys, targets and marketplaces - compile's no-output hint names targets:, not the deprecated target: - pack's mismatch hint no longer suggests the deprecated pack --target - skip messages name executables.allow instead of allowExecutables - origin and freshness errors say marketplace, not catalog - generated apm.yml headers and unknown-target errors stop listing vscode - config docs show default_client: copilot Co-authored-by: Copilot App <[email protected]> * docs(changelog): 0.37 owner hardening entries; ruff fixes apm-spec-waiver: consistency fixes route callers through existing owners; no new or changed normative requirement Co-authored-by: Copilot App <[email protected]> * docs(changelog): reference #3988 apm-spec-waiver: consistency fixes route callers through existing owners; no new or changed normative requirement Co-authored-by: Copilot App <[email protected]> * fix(update): converge the mixed-type reconcile; pin probe boundaries Harvested from #3981 (6cd7b3a, delta panel fold). Only a denied row with mixed per-type verdicts reconciles, so common partial approvals keep the no-change short-circuit; the probe catches only unreadable-package errors instead of every exception. Tests pin when the probe fetches policy, mixed detection on a two-type package, and every unavailable policy outcome. Test calls pass the scope manifest path, per #3988's trust-owner signature. Refs #3958 apm-spec-waiver: consistency fixes route callers through existing owners; no new or changed normative requirement Co-authored-by: danielmeppiel <[email protected]> Co-authored-by: Copilot App <[email protected]> * test: align tests with the 0.37 contracts this PR introduces CI on 913336a was red on tests that encoded the pre-#3983 contracts: - lifecycle test --execute now fires through the script gate, so the firing test trusts the project first and the old bypass trap now asserts untrusted scripts are withheld (mutation-break: restoring an ungated LifecycleScriptRunner fails it); - codex native admission names executables.allow, not allowExecutables; - a real LockFile.write stamps the running CLI (#3962), so the heal eligibility fixture pins the stamp it means to write; - pack no longer ships servers apm install renders from apm.yml (#3966), so the bundle MCP retire test authors its server in .mcp.json. Addresses merge-worker CI triage on #3988. apm-spec-waiver: consistency fixes route callers through existing owners; no new or changed normative requirement Co-authored-by: Copilot App <[email protected]> * fix(uninstall): origin-check marketplace rows from the batch index require_locked_catalog_origin rescanned lockfile.dependencies for every package, breaking the uninstall single-traversal guarantee. The batch index now also keys rows case-insensitively, and the registry fallback checks each matched row through require_locked_row_origin before any catalog I/O. Adds a rebound-alias regression test (mutation-break: dropping the check lets the catalog be reached) and moves the origin entry-point guard and its mutation case to the new call. Refs #3959 apm-spec-waiver: consistency fixes route callers through existing owners; no new or changed normative requirement Co-authored-by: Copilot App <[email protected]> * fix(pack): warn when root .mcp.json servers APM manages are left out A Claude plugin silently lost the MCP servers apm install renders from apm.yml. Pack now names them and the remedy; the CHANGELOG moves the #3966 line to upgrade notes with that migration, pack.md and apm-usage say the same, and the unrelated #3931 line this PR dropped is restored. Addresses panel follow-ups (supply-chain, doc-writer) on #3988. apm-spec-waiver: consistency fixes route callers through existing owners; no new or changed normative requirement Co-authored-by: Copilot App <[email protected]> * fix: fold Copilot review on trust and origin owners - install x@alias reads a legacy apm.lock for the origin check, through the read-only lockfile resolver, so a rebound alias fails closed before migration (Copilot on commands/install.py:220); - the update probe reuses POLICY_RESOLUTION_FAILURE_OUTCOMES, so an incomplete policy chain also forces the guarded install path (Copilot on commands/update.py:148); - apm approve clears a same-store deny stored under any spelling the deny ladder matches (URL, host, case), via canonical_exec_identity (Copilot on commands/approve.py:817). Each fix has a regression test proven by mutation-break. Refs #3957, #3958, #3959 apm-spec-waiver: consistency fixes route callers through existing owners; no new or changed normative requirement Co-authored-by: Copilot App <[email protected]> * fix(targets): singular target: all lists the install set as active restriction() folds singular `target: all` to None (auto-detect), but install expands it to the stable install set, so apm targets showed every target inactive. Expand it through target_catalog.expand_all("install"). Regression test proven by mutation-break. Addresses Copilot on commands/targets.py:32. Refs #3792 apm-spec-waiver: consistency fixes route callers through existing owners; no new or changed normative requirement Co-authored-by: Copilot App <[email protected]> * perf: share one marketplace index across dry-run and prune lookups locked_marketplace_row and locked_marketplace_form were called per declaration without an index, so LockFile.get_dependency rebuilt the marketplace index each time (O(M*N)). Both callers now build it once, as the reachability walk already does. Addresses Copilot on install/dry_run_plan.py:33 and install/orphans.py:46. Refs #3960 apm-spec-waiver: consistency fixes route callers through existing owners; no new or changed normative requirement Co-authored-by: Copilot App <[email protected]> * test(architecture): track the shared marketplace index in mutation cases The object-form mutation cases match the exact call text, which now passes the shared marketplace index. Co-authored-by: Copilot App <[email protected]> * fix(pack): ship apm.yml MCP declarations; only root claims hide root entries Red team qa-prA-5 and qa-prA-6 on #3988, both regressions against main: - A Claude bundle and plugin.json dropped the producer's own apm.yml MCP servers: they were read only from the rendered root .mcp.json, which pack now withholds. collect_mcp_servers projects the root manifest's self-defined declarations from apm.yml values (never the rendered copy), through the existing credential stripping, so output is byte-identical before and after apm install. The pack warning remains only for APM-managed servers apm.yml does not define (a dependency's). - apm_managed_mcp_names unioned lock claims from every runtime, so a Cursor-only claim on `docs` hid an authored root `docs` from Claude and Codex. Only claims whose runtime writes root .mcp.json count, read through the factory (ClientFactory.project_destination_is_root_mcp_json, side-effect free); unknown runtimes and unplaced aggregate names stay managed (conservative). The new unit tests fail on e9d6c9d and pass here; the bundle-retire lifecycle test is back to its apm.yml declaration; test_pack_mcp_ownership asserts byte identity, no header or secret values and no reference to the rendered file; the pack guard requires both owner rules, with a standalone mutation test. CHANGELOG, pack.md and apm-usage updated. apm-spec-waiver: consistency fixes route callers through existing owners; no new or changed normative requirement Co-authored-by: Copilot App <[email protected]> --------- Co-authored-by: danielmeppiel <[email protected]> Co-authored-by: Copilot App <[email protected]>
Takeshi Masukawa (takeaship)
pushed a commit
to takeaship/apm
that referenced
this pull request
Nov 20, 2026
) Harvested from microsoft#3971. Co-authored-by: Copilot App <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Description
After
apm install, root.mcp.jsonholds APM's own render of the package's MCP dependencies (copilot and claude write it in 0.37), and that render can carry the author's credential headers.apm packtreated that file as authored content: the Codexplugin.jsongained"mcpServers": "./.mcp.json", the Claude manifest gained the servers, and the Claude plugin bundle copied them into its.mcp.json. So pack output changed after install, and Codex users were pointed at the author's dev MCP config.core/plugin_manifest.py(thepack-plugin-manifestsowner) now owns which root.mcp.jsonservers are APM-managed:apm_managed_mcp_namesreadsapm.lock.yaml(mcp_servers,mcp_configs,mcp_target_serversfor any target). Every pack read of the project root routes through it:./.mcp.jsononly when it holds no APM-managed server. If it mixes managed and authored servers, the reference is dropped and a warning names both sets.mcpServersand the plugin bundle's root.mcp.jsondrop managed servers before credential stripping. Dependency.mcp.jsonreads are unchanged.Docs (
reference/cli/pack.md) and the apm-usage guide skill now describe this.Issue and approved scope
Issue: Fixes #3966
Human scope-approval comment: #3966 (apm-scope:v1 record by Daniel Meppiel (@danielmeppiel), 2026-11-19)
Does this PR complete the issue, or what remains? Completes it: the same
[codex, copilot, claude]package packs to byte-identical plugin manifests before and afterapm install, with no.mcp.jsonreference and no header values. MCP authoring for packs is not redesigned (out of scope).Type of change
Testing
Tested locally
All existing tests pass
Added tests for new functionality (if applicable)
tests/integration/test_pack_mcp_ownership_lifecycle.pyruns the real CLI: pack, install (fixture token only), pack again. It asserts identical manifests, no.mcp.json/devsrv/Authorization/token in them, and no.mcp.jsonor token in the bundle. It fails on main.tests/unit/core/test_plugin_manifest.py::TestApmManagedMcpExcludedFromPackcovers the mixed file, an authored-only file next to a lock that manages other names, and an unreadable lock. 2 of 3 fail on main.Commands:
.venv/bin/python -m pytest -q -n 8 tests/unit/bundle tests/unit/test_packer.py tests/unit/core tests/unit/test_agent_plugin_exporter.py tests/unit/test_codex_native_admission.py tests/unit/test_bundle_formats.py tests/integration/test_pack_mcp_ownership_lifecycle.py: 1903 passed, 1 skipped, 1 failed. The failure,test_auth_credential_report.py::test_hanging_helper_store_never_fails_the_operation, is an auth timing test that this diff does not touch.uvx [email protected] checkandformat --checkon src/, tests/ and the architecture linter scripts: clean.python -m pylint --disable=all --enable=R0801 --min-similarity-lines=10 --fail-on=R0801 src/apm_cli/ scripts/...: 10.00/10.bash scripts/lint-auth-signals.sh: clean.bash scripts/lint-architecture-boundaries.sh: rc 0.Changelog
## [Unreleased]inCHANGELOG.md:user-visible effect first, 25 words or fewer, ending with
(#PR);breaking changes only under upgrade notes; no Highlights; see
.github/instructions/changelog.instructions.md.Spec conformance (OpenAPM v0.1)
CONFORMANCE.{md,json}regenerated