Skip to content

fix: skip already-configured self-defined MCP servers on install#191

Merged
danielmeppiel merged 1 commit intomicrosoft:mainfrom
sergio-sisternes-epam:fix/189-mcp-reinstall-skip
Mar 9, 2026
Merged

fix: skip already-configured self-defined MCP servers on install#191
danielmeppiel merged 1 commit intomicrosoft:mainfrom
sergio-sisternes-epam:fix/189-mcp-reinstall-skip

Conversation

@sergio-sisternes-epam
Copy link
Collaborator

Description

Self-defined (registry: false) MCP servers were reinstalled/reconfigured on every apm install even when already present in the target runtime's configuration. This adds a name-based "already configured" check to the self-defined server install path, mirroring the existing ID-based check used for registry servers.

What changed:

  • Added _check_self_defined_servers_needing_installation() helper that checks each target runtime's config for existing server entries by name
  • Modified the self-defined deps block in _install_mcp_dependencies() to skip servers that are already configured, printing ✓ (already configured) instead of reinstalling
  • Added 8 unit tests covering the new skip logic

Fixes #189

Type of change

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

Testing

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

Local integration test output:

┌─ MCP Servers (4)
│  ✓ server-a (already configured)
│  ✓ server-b (already configured)
│  ✓ server-c (already configured)
│  ✓ server-d (already configured)
└─ All servers up to date

@sergio-sisternes-epam sergio-sisternes-epam marked this pull request as ready for review March 6, 2026 23:26
Copilot AI review requested due to automatic review settings March 6, 2026 23:26
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes repeated reinstall/reconfigure of self-defined (registry: false) MCP servers during apm install by adding a name-based “already configured” check (aligning behavior with the existing registry/UUID-based skip logic).

Changes:

  • Added _check_self_defined_servers_needing_installation() to detect self-defined servers missing from at least one target runtime config.
  • Updated _install_mcp_dependencies() to skip already-configured self-defined servers and print ✓ (already configured) instead of reinstalling.
  • Added unit tests covering the new helper and the skip behavior in the install flow.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/apm_cli/cli.py Adds helper for self-defined server presence checks and integrates skip/printing logic into MCP installation.
tests/unit/test_transitive_mcp.py Adds tests for the new helper and for skipping already-configured self-defined servers during install.

You can also share your feedback on Copilot code review. Take the survey.

@danielmeppiel
Copy link
Collaborator

What if the configuration changes for a self defined MCP server? The server could be found as already installed, but we would still need to update its settings like env vars etc. Is this scenario covered? @sergio-sisternes-epam

@sergio-sisternes-epam
Copy link
Collaborator Author

During my tests I've been using --force when I wanted to override any existing config. This can be targeted to a specific package to avoid overwriting everything

@danielmeppiel
Copy link
Collaborator

I have the feeling the manifest should be the source of truth to improve UX. I'm not sure imposing a --force flag for this case is the best experience.

@sergio-sisternes-epam
Copy link
Collaborator Author

sergio-sisternes-epam commented Mar 7, 2026

Good point @danielmeppiel! I agree the manifest should be the source of truth long-term, but today the behaviour is inconsistent in the opposite direction: MCP servers are silently overwritten on every apm install, while other Primitives require --force to overwrite. This PR proposes to create consistency in the behaviour for all primitives. Otherwise, users might get confused (as I was).

A smarter "diff-aware" install that detects manifest changes and only re-applies what actually changed would be a great improvement. But it should apply across all Primitives. I'd suggest we track that as a separate enhancement and keep this PR focused on creating a consistent behaviour, if that is the route we want it to take.

Copy link
Collaborator

@danielmeppiel danielmeppiel left a comment

Choose a reason for hiding this comment

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

Approving — the consistency argument is compelling, and this matches how registry servers already work. The --force flag doesn't bypass the registry-server skip either, so this PR is truly aligned with existing behavior.

Code quality is solid: the helper is clean, error handling is conservative (installs if config read fails), output formatting matches the existing pattern, and tests cover the key scenarios well.

I've opened a follow-up issue for diff-aware install (detect manifest changes → re-apply without --force) covering all primitive types.

Copy link
Collaborator

@danielmeppiel danielmeppiel left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution, Sergio! The fix for #189 itself looks good — the self-defined MCP server skip logic is the right approach.

However, this PR needs some cleanup before we can merge it:

1. Rebase onto main

The branch currently carries 71 commits, but only 2-3 are yours — the rest are commits from main that were pulled in via git merge. This makes the diff show 50 changed files / 5,048 additions when the actual fix is much smaller.

Please rebase your branch onto main to clean this up:

git fetch upstream
git rebase upstream/main
git push --force-with-lease

This will reduce the PR to just your actual commits and make the diff reviewable.

2. Scope

Once the rebase is done, please ensure the PR only contains changes related to the #189 fix (skipping already-configured self-defined MCP servers). The current diff includes unrelated changes that were already merged to main separately (emoji removal from CLI help, plugin hardening, stale MCP cleanup, changelog updates, etc.) — those should all disappear after the rebase.

3. Test fixtures

The test fixtures (mock-marketplace-plugin, mock-claude-plugin, mock-plugin) are near-duplicates of each other. If your fix needs test fixtures, consider parametrizing a single fixture instead of duplicating directories. But first — let's see what the diff actually looks like after the rebase, since most of those fixtures may belong to the plugin feature that's already in main.

Looking forward to the cleaned-up version!

@sergio-sisternes-epam sergio-sisternes-epam force-pushed the fix/189-mcp-reinstall-skip branch from 63faaf3 to 917463b Compare March 9, 2026 23:16
…rosoft#189)

Adapt the fix to the extracted MCPIntegrator on upstream/main and retain the review follow-up behavior: cache runtime config reads for self-defined checks and emit non-console skip feedback.
@sergio-sisternes-epam sergio-sisternes-epam force-pushed the fix/189-mcp-reinstall-skip branch from 917463b to 1c5d4c9 Compare March 9, 2026 23:38
@sergio-sisternes-epam
Copy link
Collaborator Author

@danielmeppie I’ve cleaned the branch up and rebased it again onto the latest main. Did merge rather than rebase, apologies.

The PR is now reduced to the #189 fix only, adapted to the recent MCPIntegrator implementation:

  • skip already-configured self-defined MCP servers
  • preserve the follow-up review behaviour around cached runtime config reads and non-console skip feedback

Current diff is limited to:

  • src/apm_cli/integration/mcp_integrator.py
  • tests/unit/test_transitive_mcp.py

I also reran the focused MCP unit tests locally:

  • uv run pytest tests/unit/test_transitive_mcp.py
  • 36 passed

On the fixture point: after cleaning up the branch, this PR no longer includes any plugin fixture changes, so I’ve kept that out of scope for #189. If needed, fixture deduplication can be handled separately.

@danielmeppiel danielmeppiel merged commit ff360f7 into microsoft:main Mar 9, 2026
6 checks 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.

[BUG] apm install <pkg> reinstalls all MCP servers even when already configured

3 participants