Skip to content

[Bug]: brew upgrade leaves two MCPProxy instances in the menu bar (pkg postinstall never quits the old tray) #2016

Done

Description

@rantoniuk

What happened?

After brew upgrade --cask mcpproxy the menu bar shows two MCPProxy icons: the old tray (still running from the replaced bundle) and the freshly launched new one.

The quit-first fix from #957 / Spec 092 FR-004 lives in packaging/macos/postinstall.sh, but that script is not the one shipped in the release pkg. The pkg the cask installs (mcpproxy-<ver>-darwin-arm64.pkg inside *-installer.dmg) is built by scripts/create-pkg.sh and runs scripts/postinstall.sh, which only does:

/bin/launchctl asuser "$REAL_UID" /usr/bin/env -i ... \
    /usr/bin/open -a "$APP_BUNDLE" --env MCPPROXY_LAUNCHED_BY=installer

with no quit/pgrep/pkill step. Confirmed in /var/log/install.log for a 0.75.0 upgrade: the postinstall output is the scripts/postinstall.sh one ("CLI symlink created", "Installation Summary", "Launching mcpproxy tray (installer-tagged) with clean env"), and none of the packaging/macos/postinstall.sh lines ("asking the running MCPProxy to quit", "no MCPProxy instance running") appear.

installd: PackageKit: Parent bundle com.smartmcpproxy.mcpproxy will be atomically shoved.
./postinstall: Starting mcpproxy post-installation setup...
./postinstall: ✅ CLI symlink created: /usr/local/bin/mcpproxy
./postinstall: 🎉 mcpproxy installation complete!
./postinstall: Launching mcpproxy tray (installer-tagged) with clean env: /Applications/MCPProxy.app

Because PackageKit "atomically shoves" the bundle, the running tray now belongs to a bundle that no longer exists on disk, so open -a starts a new process instead of activating the old one. The tray has no single-instance guard of its own (Spec 092 supersede handles a stale core, not a second tray), so both stay up.

sequenceDiagram
    participant B as brew upgrade
    participant P as PackageKit
    participant S as scripts/postinstall.sh
    participant Old as Old tray (running)
    participant New as New tray
    B->>P: installer -pkg mcpproxy-<ver>.pkg
    P->>P: atomically replace /Applications/mcpproxy.app
    Note over Old: keeps running from replaced bundle
    P->>S: run postinstall
    S->>New: open -a /Applications/MCPProxy.app
    Note over Old,New: two menu bar icons
Loading

Expected behavior

The upgrade ends with exactly one tray running the new version, same as the DMG flow fixed in #957.

Suggested fix

Any of these, ideally the first two together:

  1. Make scripts/create-pkg.sh ship packaging/macos/postinstall.sh (or port its quit_running_instance step into scripts/postinstall.sh), so there is a single postinstall for every pkg.
  2. Add quit: "com.smartmcpproxy.mcpproxy" to the cask's uninstall stanza in homebrew-mcpproxy/Casks/mcpproxy.rb, so Homebrew quits the old app before replacing it.
  3. Defense in depth: on launch, the tray checks NSRunningApplication.runningApplications(withBundleIdentifier:) for another instance and either exits or asks the older one to terminate.

Side note while porting the quit step: packaging/macos/postinstall.sh matches pgrep -f "MCPProxy.app/Contents/MacOS/MCPProxy", but the pkg payload installs the bundle as lowercase Applications/mcpproxy.app (see pkgutil --files com.smartmcpproxy.mcpproxy.pkg). pgrep -f is case-sensitive, so on an existing lowercase install that pattern would not match the running process (/Applications/mcpproxy.app/Contents/MacOS/MCPProxy) and the quit step would be skipped. Using pgrep -if or matching Contents/MacOS/MCPProxy would avoid that.

Steps to reproduce

  1. brew install --cask smart-mcp-proxy/mcpproxy/mcpproxy (an older version) and start the tray.
  2. brew upgrade --cask mcpproxy.
  3. Look at the menu bar: two MCPProxy icons. pgrep -lf MCPProxy.app shows two tray processes.

MCPProxy version

v0.75.0 (Homebrew cask, darwin/arm64)

Operating system

macOS 27 (Darwin 27.0.0), Apple Silicon

Relevant logs

/var/log/install.log excerpt above (2026-11-23 17:01, upgrade to 0.75.0).

Pre-submission checklist

Activity

  1. added a commit that references this issue on Nov 24, 2026
    3f49246
  2. Dumbris commented on Nov 24, 2026

    @Dumbris
    Member

    Thank you @rantoniuk, this was a very good report. Your diagnosis was right: the quit step from #957 was never in the shipped pkg, and the case-sensitive match would have missed the installed app anyway.

    The fix is in #2024: the pkg now quits the running tray in a preinstall step, before the bundle is replaced. It will be in the next release. If you still see two icons after that upgrade, please reopen this issue.

  3. added a commit that references this issue on Nov 24, 2026
    f2f9f0e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions