Skip to content

fix(desktop): resolve actual desktop-mcp bin path for setup snippet#353

Closed
MocA-Love wants to merge 1 commit intomainfrom
fix/desktop-mcp-bin-resolver
Closed

fix(desktop): resolve actual desktop-mcp bin path for setup snippet#353
MocA-Love wants to merge 1 commit intomainfrom
fix/desktop-mcp-bin-resolver

Conversation

@MocA-Love
Copy link
Copy Markdown
Owner

@MocA-Love MocA-Love commented Apr 20, 2026

Summary

PR #345 でセットアップ snippet に `desktop-mcp` という裸のコマンドを出していたが、これは monorepo 内部のプライベート TS bin (`packages/desktop-mcp/src/bin.ts`) でグローバル PATH に無く、`claude mcp add ... -- desktop-mcp` を実行すると Claude 側で `/mcp` が `failed` になっていた。

修正:

  • `browserAutomation.getMcpStatus` が main process で bin を解決して `serverCommand: { command, args, available }` を返す
    • dev: `{ command: "bun", args: ["/packages/desktop-mcp/src/bin.ts"] }`
    • packaged: `{ command: "desktop-mcp", args: [], available: false }` (フォールバック、ブラウザ自動化は現状 dev only)
  • `getSnippetForSession(session, serverCommand)` で実 argv を使った snippet を生成
    • Claude: `claude mcp add superset-browser -s local -- bun `
    • Codex: `[mcp_servers.superset-browser]` + `command` / `args` を TOML エスケープ
  • SessionConnectModal が serverCommand を SetupPanel に受け渡し

背景 — この PR の出し方について

元々 PR #345 のレビュー対応中に同じ修正を直接 main に push してしまい、レビューなしで入ってしまった (commit b925620)。その commit を revert した上でこの PR に切り出し直している。内容は revert 前と同じ。

Test plan

  • dev ビルドで browser pane → Connect → セッション選択 → MCP 未設定時に出る snippet に `bun /Volumes/sub/github/superset/packages/desktop-mcp/src/bin.ts` が含まれる
  • 上記コマンドを Claude CLI に貼って実行すると `/mcp` で `superset-browser` が `running` になる
  • Codex 側の TOML snippet も `command = "bun"` + `args = [""]` で生成される

Summary by CodeRabbit

リリースノート

  • 新機能

    • ブラウザ自動化セッション接続情報の生成が改善されました。開発環境とパッケージ版の両方に対応したサーバーコマンド情報を自動で検出し、セッション接続スニペットに反映されるようになりました。
  • 改善

    • セッション接続モーダルで生成されるコマンドスニペットがMCPサーバーの設定をより正確に反映するようになりました。

desktop-mcp is a workspace-private TS bin with no global install, so
`claude mcp add superset-browser -s local -- desktop-mcp` registered a
command the shell can't resolve (Status: failed).

browserAutomation.getMcpStatus now resolves the bin at runtime
(`bun <repo>/packages/desktop-mcp/src/bin.ts` in dev; falls back to the
bare name in packaged builds) and returns it as `serverCommand`. The
snippet generator builds a Claude CLI / TOML block from those exact
argv tokens so copy-pasting the instructions actually starts the server.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 20, 2026

📝 Walkthrough

ウォークスルー

ブラウザ自動化ルーターにMCPサーバーコマンド解決ロジックを追加し、開発環境ではbunから実行、本番環境ではdesktop-mcpコマンドを使用するよう条件分岐を実装。SessionConnectModalを通じてサーバーコマンド情報をスニペット生成に渡し、CLIスニペットとClaudeコード設定に動的に反映させました。

変更内容

コホート / ファイル 概要
MCPサーバーコマンド解決
apps/desktop/src/lib/trpc/routers/browser-automation/index.ts
resolveDesktopMcpCommand()ヘルパー関数を追加して、開発環境ではbunパス解決、本番環境ではdesktop-mcpをデフォルト値とするロジックを実装。getMcpStatusクエリレスポンスにserverCommandフィールドを拡張。
UIコンポーネント配線
apps/desktop/src/renderer/screens/main/components/.../SessionConnectModal.tsx
serverCommandmcpStatusから抽出し、getSnippetForSessionに渡すよう更新。SetupPanelコンポーネントにserverCommandプロップを追加して動的スニペット生成に対応。
スニペット生成ロジック拡張
apps/desktop/src/renderer/stores/browser-automation.ts
ServerCommandインターフェースを新規追加。getSnippetForSession関数をサーバーパラメータ対応に拡張。TOML安全文字列エンコード(tomlString)とシェルクォーティング(shellQuote)のヘルパーを実装。Codexおよびクロードコードスニペット生成でcommandargsを動的に展開。

推定レビュー工数

🎯 3 (Moderate) | ⏱️ ~20 分

🐰 ✨
MCP サーバー、新たなる道
開発と本番、分かれて進む
スニペットには秘密が宿り
シェルコマンド、優雅に舞う
つながるコード、更に強く 🌟

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed PRのタイトルは主な変更内容を明確に要約しており、desktop-mcpのバイナリパスを解決することが主な目的であることが伝わる。
Description check ✅ Passed 説明テンプレートの必須セクション(Description、Type of Change、Testing)が記入されているが、Related Issuesセクションが不完全である。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/desktop-mcp-bin-resolver

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/TabView/BrowserPane/components/SessionConnectModal/SessionConnectModal.tsx`:
- Around line 147-154: The copy/snippet flow ignores mcpStatus/resolver
availability and may produce a failing "desktop-mcp" snippet; update
handleCopySnippet (and the other similar handlers that call
getSnippetForSession) to check mcpStatus?.serverCommand?.available (or
serverCommand.available) before calling getSnippetForSession and prevent
copying/show a clear error / disable the copy action when available is false or
mcpStatus is not loaded; ensure you reference serverCommand and
getSnippetForSession so the guard is applied everywhere this snippet is
generated.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6622ea87-7fe2-40db-a537-23bbeddba73b

📥 Commits

Reviewing files that changed from the base of the PR and between aff0d4f and ea9bf51.

📒 Files selected for processing (3)
  • apps/desktop/src/lib/trpc/routers/browser-automation/index.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/TabView/BrowserPane/components/SessionConnectModal/SessionConnectModal.tsx
  • apps/desktop/src/renderer/stores/browser-automation.ts

Comment on lines +147 to +154
const serverCommand = mcpStatus?.serverCommand;

const handleCopySnippet = async () => {
if (!session) return;
try {
await navigator.clipboard.writeText(getSnippetForSession(session));
await navigator.clipboard.writeText(
getSnippetForSession(session, serverCommand),
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

serverCommand.available を尊重して、失敗するスニペットのコピーを防いでください。

mcpStatus が未ロード、または resolver が available: false を返した場合でも、現在は getSnippetForSession のフォールバックで bare desktop-mcp が表示/コピーされます。これは今回直した /mcp failed の経路を再発させます。

修正案
-	const serverCommand = mcpStatus?.serverCommand;
+	const serverCommand = mcpStatus?.serverCommand ?? null;

 	const handleCopySnippet = async () => {
-		if (!session) return;
+		if (!session) return;
+		if (!serverCommand?.available) {
+			toast.error("MCP server command is still unavailable");
+			return;
+		}
 		try {
 			await navigator.clipboard.writeText(
 				getSnippetForSession(session, serverCommand),
 			);
 								<SetupPanel
 									session={session}
 									mcpConfigPath={
 										session.provider === "Codex"
 											? (mcpStatus?.codexConfigPath ?? null)
 											: (mcpStatus?.claudeConfigPath ?? null)
 									}
 									serverCommand={serverCommand}
 									onCopy={handleCopySnippet}
 								/>
 function SetupPanel({
 	session,
 	mcpConfigPath,
 	serverCommand,
 	onCopy,
 }: {
 	session: AutomationSession;
 	mcpConfigPath: string | null;
-	serverCommand?: ServerCommand;
+	serverCommand: ServerCommand | null;
 	onCopy: () => void;
 }) {
-	const snippet = getSnippetForSession(session, serverCommand);
+	const snippet = serverCommand?.available
+		? getSnippetForSession(session, serverCommand)
+		: "MCP server command is not available in this build.";
-					<Button size="sm" variant="outline" onClick={onCopy}>
+					<Button
+						size="sm"
+						variant="outline"
+						onClick={onCopy}
+						disabled={!serverCommand?.available}
+					>

Also applies to: 252-253, 457-465, 517-520

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/TabView/BrowserPane/components/SessionConnectModal/SessionConnectModal.tsx`
around lines 147 - 154, The copy/snippet flow ignores mcpStatus/resolver
availability and may produce a failing "desktop-mcp" snippet; update
handleCopySnippet (and the other similar handlers that call
getSnippetForSession) to check mcpStatus?.serverCommand?.available (or
serverCommand.available) before calling getSnippetForSession and prevent
copying/show a clear error / disable the copy action when available is false or
mcpStatus is not loaded; ensure you reference serverCommand and
getSnippetForSession so the guard is applied everywhere this snippet is
generated.

@MocA-Love
Copy link
Copy Markdown
Owner Author

実装方針を変更 (独立 MCP パッケージ + PID 自動マッチング)。新規 PR で再実装します。

@MocA-Love MocA-Love closed this Apr 20, 2026
@MocA-Love MocA-Love deleted the fix/desktop-mcp-bin-resolver branch April 20, 2026 14:50
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.

1 participant