Skip to content

Fix packaged MCP launcher paths with spaces - #92

Merged
kjgbot merged 2 commits into
mainfrom
fix/packaged-mcp-launcher-shim
Jun 5, 2026
Merged

kjgbot merged 2 commits into
mainfrom
fix/packaged-mcp-launcher-shim

Conversation

@miyaontherelay

@miyaontherelay miyaontherelay commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

User description

Summary

  • route packaged Agent Relay MCP launches through a stable no-space shim when the app bundle path contains spaces
  • keep packaged MCP smoke verification strict for external, executable, non-app.asar command paths
  • add regression coverage for packaged resource paths containing spaces

Verification

  • npx vitest run src/main/broker.test.ts
  • scripts/verify-mcp-spawn.mjs "/Applications/Pear by Agent Relay.app"
  • npm run build
  • git diff --check

CodeAnt-AI Description

Fix packaged MCP launches when the app is installed in a folder with spaces

What Changed

  • Packaged MCP launches now use a no-space shim when the launcher path would otherwise contain spaces, so the command can still start correctly.
  • The shim is written to a temporary location and points to the packaged launcher without using app.asar.
  • Regression coverage now checks that packaged MCP commands stay executable, avoid spaces, and still resolve to the expected launcher behavior.

Impact

✅ Fewer packaged launch failures
✅ Works from app folders with spaces
✅ Clearer packaged MCP startup checks

🔄 Retrigger CodeAnt AI Review

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

@codeant-ai

codeant-ai Bot commented Jun 5, 2026

Copy link
Copy Markdown

CodeAnt AI is reviewing your PR.

@coderabbitai

coderabbitai Bot commented Jun 5, 2026 •

Copy link
Copy Markdown

Review Change Stack

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Free

Run ID: 5873f3bc-d340-4ca1-9c3b-005488a57a7e

📥 Commits

Reviewing files that changed from the base of the PR and between 1b75eab and b693858.

📒 Files selected for processing (2)
  • src/main/broker.test.ts
  • src/main/mcp-command.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/mcp-command.ts

📝 Walkthrough

Walkthrough

Adds packaged-mode shim creation for Agent Relay MCP launchers with whitespace or special characters, enhances verification to validate shim paths, and expands broker tests to assert whitespace-free shim resolution and percent-sign escaping on Windows.

Changes

MCP Launcher Shim Materialization

Layer / File(s) Summary
Shim creation infrastructure
src/main/mcp-command.ts
Adds createHash and tmpdir imports, platform-specific quoting helpers, selection of shim roots, and materializePackagedAgentRelayMcpShim to create hashed shims under pear-agent-relay-mcp/<hash>/launch.(sh|cmd). resolveAgentRelayMcpCommand uses the shim path in packaged mode.
Shim path validation rules
scripts/verify-mcp-spawn.mjs
Replaces a single equality check with validations ensuring the resolved MCP command exists, is a file, is executable on non-Windows, does not contain app.asar, contains no whitespace, and either equals the launcher or includes the pear-agent-relay-mcp shim segment.
Test coverage for spaced and percent-containing paths
src/main/broker.test.ts
Imports readFile, snapshots/restores process.platform and PUBLIC/ProgramData env vars, manages an extra temp dir, and adds packaged-mode tests asserting whitespace-free shim resolution, no app.asar references, and Windows percent-sign escaping in launcher content.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 I hashed the path where spaces lay hid,
A tiny shim sprung up from tempgrid,
No app.asar, no whitespace in sight,
Launch scripts gleam and run just right,
Hop, run, relay — a rabbit's tidy bid.


Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

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

@codeant-ai codeant-ai Bot added the size:M This PR changes 30-99 lines, ignoring generated files label Jun 5, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a mechanism to handle packaged MCP launcher paths containing spaces by generating a space-free shim launcher (using /tmp on POSIX and tmpdir() on Windows). Feedback focuses on two edge cases on Windows: first, tmpdir() can still contain spaces if the user's username has spaces, so a fallback to space-free directories like C:\Users\Public is recommended; second, percent signs % in the launcher path must be escaped as %% in the generated batch file to prevent unexpected expansion by CMD.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/main/mcp-command.ts Outdated
Comment on lines +120 to +124
function packagedMcpShimRoot(): string {
// Use /tmp on POSIX so the MCP command handed to Codex has no spaces even
// when the app is installed as "Pear by Agent Relay.app".
return process.platform === 'win32' ? tmpdir() : '/tmp'
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

On Windows, if the user's username contains spaces (e.g., C:\Users\John Doe), tmpdir() will return a path with spaces. Consequently, packagedMcpShimRoot() will return a path with spaces, and the generated shim path will still contain spaces, defeating the purpose of this PR and causing the verification tests to fail.

We should fall back to a space-free writable directory on Windows (such as C:\Users\Public or C:\ProgramData) if the default temp directory contains spaces.

function packagedMcpShimRoot(): string {
  // Use /tmp on POSIX so the MCP command handed to Codex has no spaces even
  // when the app is installed as "Pear by Agent Relay.app".
  if (process.platform !== 'win32') {
    return '/tmp'
  }
  const defaultTmp = tmpdir()
  if (!/\s/.test(defaultTmp)) {
    return defaultTmp
  }
  // Fallback to space-free writable directories on Windows if the user's temp directory contains spaces
  const publicDir = process.env.PUBLIC || 'C:\\Users\\Public'
  if (existsSync(publicDir) && !/\s/.test(publicDir)) {
    return publicDir
  }
  const programData = process.env.ProgramData || 'C:\\ProgramData'
  if (existsSync(programData) && !/\s/.test(programData)) {
    return programData
  }
  return defaultTmp
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in b693858: packaged Windows shims now try whitespace-free roots only (temp when clean, then PUBLIC, then ProgramData) and fail rather than returning a command path with spaces.

Comment thread src/main/mcp-command.ts
Comment on lines +116 to +118
function windowsCmdQuote(value: string): string {
return `"${value.replace(/"/g, '""')}"`
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

In Windows batch (.cmd/.bat) files, percent signs % are special characters used for variable and parameter expansion (e.g., %1, %VAR%). If the launcherPath contains a % character (for example, in a URL-encoded path or a username containing %), CMD will attempt to expand it, which can corrupt the path and cause execution to fail.

To prevent this, any literal % in the path must be escaped by doubling it to %% inside the batch file.

Suggested change
function windowsCmdQuote(value: string): string {
return `"${value.replace(/"/g, '""')}"`
}
function windowsCmdQuote(value: string): string {
return `"${value.replace(/"/g, '""').replace(/%/g, '%%')}"`
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in b693858: literal percent signs are now doubled in generated .cmd shims, with a regression test covering a %USER% launcher path.

@codeant-ai

codeant-ai Bot commented Jun 5, 2026

Copy link
Copy Markdown

CodeAnt AI finished reviewing your PR.

@kjgbot
kjgbot merged commit 4591f55 into main Jun 5, 2026
3 checks passed
@kjgbot
kjgbot deleted the fix/packaged-mcp-launcher-shim branch June 5, 2026 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants