Skip to content

fix(mcp): name the plugin path APM writes in .mcp.json conflict hints - #3930

Merged
Daniel Meppiel (danielmeppiel) merged 7 commits into
mainfrom
danielmeppiel-fix-mcp-conflict-hint-plugin-root
Nov 19, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 7 commits into
mainfrom
danielmeppiel-fix-mcp-conflict-hint-plugin-root

Conversation

@danielmeppiel

Copy link
Copy Markdown
Collaborator

Description

Root cause 2 of #3927. When a Claude or Copilot project .mcp.json entry for a plugin MCP server conflicts, ClaudeClientAdapter.native_conflict_guidance (inherited by CopilotProjectClientAdapter) treated APM's own ${CLAUDE_PROJECT_DIR:-.} plugin-root rendering as an apm.yml environment reference. The hint then told users to write ${CLAUDE_PROJECT_DIR} (dropping the :-. default, which breaks the server) and to rotate credentials for a path.

The adapter now strips its own plugin_root_project_reference before collecting reference names:

  • A field holding only that reference names the exact value APM writes, for example (args[0]: ${CLAUDE_PROJECT_DIR:-.}/apm_modules/_local/plug/scripts/server.js), or suggests renaming or removing the connection. No credential-rotation line.
  • Real apm.yml environment references keep today's names-only guidance and rotation line. If both kinds conflict, the package paths are appended to the same hint.

Before (main 0e19cce):

[x] MCP server 'synthdb' conflicts with the existing claude connection in .../.mcp.json. Preserved that connection. Field args[0] holds a value where apm.yml declares environment references, and APM cannot confirm it wrote them. Put the references declared in apm.yml back yourself (args[0]: ${CLAUDE_PROJECT_DIR}), then retry. If .mcp.json was committed, rotate those credentials: editing the file does not erase them in Git history.

After:

[x] MCP server 'synthdb' conflicts with the existing claude connection in .../.mcp.json. Preserved that connection. Field args[0] holds a value where APM writes a package path, and APM cannot confirm it wrote it. Restore what APM writes (args[0]: ${CLAUDE_PROJECT_DIR:-.}/apm_modules/_local/plug/scripts/server.js) or rename or remove the connection yourself, then retry.

Issue and approved scope

Issue: Refs #3927

Human scope-approval comment: #3927 (comment)

Does this PR complete the issue, or what remains? It fixes root cause 2 (the conflict hint) only. Root cause 1 (the dependency identity key ignores the port) is handled in a separate PR.

Type of change

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

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)

New tests:

  • tests/integration/test_lock_derived_expected_state_lifecycle.py::test_plugin_root_conflict_hint_restores_the_value_apm_writes[claude|copilot]: installed CLI, local plugin dependency, hand-edited .mcp.json arg. Fails on unfixed main for both targets and passes with the fix.
  • tests/unit/test_claude_mcp.py: test_conflict_guidance_restores_plugin_root_path_without_rotation and test_conflict_guidance_keeps_env_hint_beside_plugin_root_path. Both fail on main.

Validation evidence (on HEAD merged with main 09af2b1):

  • APM_BINARY_PATH=.venv/bin/apm .venv/bin/python -m pytest -p no:xdist tests/integration/test_lock_derived_expected_state_lifecycle.py -k conflict_hint with the src/ fix reverted: 2 failed. With the fix: 2 passed.
  • APM_BINARY_PATH=.venv/bin/apm .venv/bin/python -m pytest -p no:xdist tests/integration/test_claude_mcp_env_references_e2e.py tests/integration/test_lock_derived_expected_state_lifecycle.py: 15 passed.
  • .venv/bin/python -m pytest -p no:xdist tests/unit/test_claude_mcp.py tests/unit/integration -k "conflict or claude": 350 passed.
  • uvx [email protected] check and uvx [email protected] format --check on src/ tests/ scripts/lint_architecture_boundaries.py scripts/architecture_linter/ scripts/windows_native_symlink_probe_entry.py: passed.
  • .venv/bin/python -m pylint --disable=all --enable=R0801 --min-similarity-lines=10 --fail-on=R0801 src/apm_cli/ scripts/lint_architecture_boundaries.py scripts/architecture_linter/: 10.00/10.
  • bash scripts/lint-auth-signals.sh: clean. bash scripts/lint-architecture-boundaries.sh: exit 0.

Changelog

  • One line in one section under ## [Unreleased] in CHANGELOG.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.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • Spec edit: docs/src/content/docs/specs/openapm-v0.1.md updated
    (new/changed <a id="req-XXX"></a> anchor + prose + Appendix C
    row).
  • Manifest edit: docs/src/content/docs/specs/manifests/openapm-v0.1.requirements.yml
    updated.
  • Test edit: a @pytest.mark.req("req-XXX") test under
    tests/spec_conformance/ added or extended.
  • CONFORMANCE.{md,json} regenerated via
    uv run --extra dev python -m tests.spec_conformance.gen_statement
    and committed.
  • N/A -- this PR does not change OpenAPM-observable behaviour.

The Claude/Copilot conflict hint classified APM's own
${CLAUDE_PROJECT_DIR:-.} plugin-root rendering as an apm.yml environment
reference, suggested ${CLAUDE_PROJECT_DIR} without its default, and asked
to rotate credentials for a path. Such a field now names the exact value
APM writes; real environment references keep their guidance.

Refs #3927

apm-spec-waiver: diagnostic wording only; no OpenAPM requirement changes

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 13:55

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

Preserved-conflict hints can expose literal credentials and suggest incomplete or invalid JSON replacements for mixed fields and non-ASCII package paths.

3 open issues
What changed in this PR

Updates APM’s Claude and Copilot project .mcp.json conflict hints to distinguish plugin package paths from environment references. This addresses the guidance portion of #3927; the dependency-port identity issue remains separate.

Changes:

  • Adds package-path recovery hints that preserve ${CLAUDE_PROJECT_DIR:-.} and avoid credential-rotation advice for path-only conflicts.
  • Adds unit and installed-CLI regression coverage, including preservation of conflicting native entries.
  • Documents the revised guidance and records the user-visible change.
File Description
tests/​unit/​test_claude_mcp.py Tests path-only and combined path/environment conflict guidance.
tests/​integration/​test_lock_derived_expected_state_lifecycle.py Exercises conflict hints and native-file preservation for Claude and Copilot.
src/​apm_cli/​adapters/​client/​claude.py Separates package-path hints from environment-reference guidance.
docs/​src/​content/​docs/​consumer/​install-mcp-servers.md Explains package-path restoration hints.
CHANGELOG.md Records the conflict-guidance change under Unreleased.

Review effort: Balanced

Comment thread src/apm_cli/adapters/client/claude.py Resolved
Comment thread src/apm_cli/adapters/client/claude.py Resolved
Comment thread src/apm_cli/adapters/client/claude.py Resolved
A plugin-root field can carry a literal credential (a query string) or a
non-ASCII segment, and a mixed field also needs the project-root
reference with its default. Print the exact value only for a plain ASCII
path; otherwise name the reference verbatim, never the value.

Addresses Copilot inline on src/apm_cli/adapters/client/claude.py:382-383.

Co-authored-by: Copilot App <[email protected]>
A path inside a flag (--config=${CLAUDE_PROJECT_DIR:-.}/...) is printed
exactly when its literal text is plain, and a field that mixes the plugin
root with an env reference no longer lists the root as a reference
declared in apm.yml; it is named in the package-path clause instead.

Addresses cli-logging-expert panel findings 1 and 2.

Co-authored-by: Copilot App <[email protected]>
The printability rule covers the whole field, so pin that literal text
before ${CLAUDE_PROJECT_DIR:-.} is never echoed either.

Addresses test-coverage-expert delta finding 1.

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

Copy link
Copy Markdown
Collaborator Author

APM Review Panel: ship_with_followups

Stops the Claude/Copilot .mcp.json conflict hint from treating APM's own plugin-root path as a user env reference, so users get the real path to restore instead of wrong ${CLAUDE_PROJECT_DIR} or credential-rotation advice.

panel-mode=lean then delta; personas=cli-logging-expert,test-coverage-expert,apm-ceo

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

This PR fixes root cause 2 of #3927 and stays inside the approved scope. ClaudeClientAdapter.native_conflict_guidance (inherited by CopilotProjectClientAdapter) read APM's own ${CLAUDE_PROJECT_DIR:-.} rendering as an apm.yml env reference. It sent users to a variable they never wrote and told them to rotate credentials.

Now:

  • A field that holds only APM's path shows the exact value APM writes when the text is plain ASCII. Otherwise it shows a generic package-path phrase.
  • A field with real env references keeps the names-only guidance and the rotation line, with any package path listed in its own clause.

Credential advice appears only when a credential-shaped reference is present.

The panel agrees. On the delta pass, cli-logging-expert confirmed its two lean findings are resolved. test-coverage-expert's one gap, credential-shaped text before the root, is folded with mutation-break proof. The installed-CLI regression test test_plugin_root_conflict_hint_restores_the_value_apm_writes[claude|copilot] fails on main and passes at head, so the user-facing fix is proven end to end. The only leftover is the pre-existing "references declared in apm.yml" wording for package-declared env references. That wording is out of scope per the record.

Aligned with: Secure by default: rotation guidance only for real env references, and no secret-shaped values echoed, pinned by tests. Multi-harness: the regression test runs on both claude and copilot. Pragmatic as npm: the hint names the exact path APM writes. Portable by manifest: APM-rendered paths are no longer attributed to apm.yml.

Panel summary

Persona B R N Takeaway
CLI Logging Expert 0 0 0 Both prior findings resolved: flag-embedded plugin paths print verbatim, mixed fields list only env names. No new output issue; ship.
Test Coverage Expert 0 1 0 Mixed-field and in-flag root printing are trapped; the prefix gap it raised is folded in 8b19216.

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

Top 1 follow-ups

  1. [CLI Logging Expert] File a separate issue to fix the existing "references declared in apm.yml" wording so it covers env references declared by a package in plugin .mcp.json. -- It misattributes the source of a reference for plugin packages. It is out of scope for [BUG] Dependency identity key ignores the port; MCP conflict hint misreads ${CLAUDE_PROJECT_DIR:-.} #3927 per the record, but it is the same kind of trust gap.

Recommendation

Merge once a required review lands: CI is green on head 8b19216. The regression test fails on main and passes at head, every panel and Copilot finding was folded, and no blocking item remains. Track the "references declared in apm.yml" wording as a separate issue rather than widening this PR.

Folded in this run

  • (Copilot) Do not echo a literal secret (e.g. ?token=) in a plugin-root field -- resolved in 0ede80a.
  • (Copilot) Keep the :-. default and mention the package path for mixed fields -- resolved in 0ede80a.
  • (Copilot) Drop ascii() escapes that are invalid JSON for non-ASCII paths -- resolved in 0ede80a.
  • (cli-logging-expert) Print a flag-embedded plugin path (--config=${CLAUDE_PROJECT_DIR:-.}/...) exactly -- resolved in 63352ab.
  • (cli-logging-expert) Stop listing ${CLAUDE_PROJECT_DIR:-.} as an apm.yml reference in mixed fields -- resolved in 63352ab.
  • (test-coverage-expert) Pin that credential-shaped text before the root is never echoed -- resolved in 8b19216.

Copilot signals reviewed

  • src/apm_cli/adapters/client/claude.py:383 -- LEGIT: a plugin-root field could carry a literal credential (resolved in 0ede80a).
  • src/apm_cli/adapters/client/claude.py:382 -- LEGIT: a mixed field dropped the path and the :-. default (resolved in 0ede80a).
  • src/apm_cli/adapters/client/claude.py:383 -- LEGIT: ascii() escapes are not valid JSON (resolved in 0ede80a).

Deferred (out-of-scope follow-ups)

  • (cli-logging-expert) The "references declared in apm.yml" wording for env references declared by a package -- scope boundary: the record excludes other conflict-hint wording.

Regression-trap evidence (mutation-break gate)

  • tests/integration/test_lock_derived_expected_state_lifecycle.py::test_plugin_root_conflict_hint_restores_the_value_apm_writes[claude|copilot] -- with the src/ fix reverted to main, both cases FAILED; with the fix, both passed.
  • tests/unit/test_claude_mcp.py::TestClaudeLegacyEntries -- removed the root exclusion from the env-name scan: 3 tests FAILED. Replaced the printable check with startswith(root): 2 FAILED. Replaced it with a suffix-only check: 1 FAILED. The guards were restored each time.

Lint contract

uvx [email protected] check and format --check (src, tests, scripts), pylint R0801 (10.00/10), scripts/lint-auth-signals.sh, and scripts/lint-architecture-boundaries.sh are all silent on HEAD merged with main bcd020f.

CI

All checks green on 8b19216: 31 pass, 3 skipped (after 0 CI fix iterations).

Mergeability status

PR head SHA CEO stance iters folds defers Copilot rounds CI mergeable mergeStateStatus notes
#3930 8b19216 ship_with_followups 2 6 1 1 green MERGEABLE BLOCKED pending required review

Full per-persona findings

CLI Logging Expert

Lean pass (0ede80a), both folded in 63352ab:

  • [recommended] A plugin path inside a flag got the vague "a package path under" phrase, which drops the flag prefix, at src/apm_cli/adapters/client/claude.py:389.
  • [recommended] The mixed-field hint listed ${CLAUDE_PROJECT_DIR:-.} under "references declared in apm.yml", at src/apm_cli/adapters/client/claude.py:405.

Delta pass (648b6dc): No findings.

Test Coverage Expert

Lean pass: No findings.

Delta pass (648b6dc), folded in 8b19216:

  • [recommended] No test covered unprintable literal text before the plugin-root reference, so a suffix-only printability check would have passed, at tests/unit/test_claude_mcp.py:631.

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-merge-worker. This comment is AI-generated and may contain errors.

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit be0e43a into main Nov 19, 2026
34 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-fix-mcp-conflict-hint-plugin-root branch November 19, 2026 14:58
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.

2 participants