Skip to content

Fix #46: Port file written to $TMPDIR (/var/folders/...) instead of /... - #63

Open
JiwaniZakir wants to merge 1 commit into
southleft:mainfrom
JiwaniZakir:fix/46-port-file-written-to-tmpdir-var-folders
Open

Fix #46: Port file written to $TMPDIR (/var/folders/...) instead of /...#63
JiwaniZakir wants to merge 1 commit into
southleft:mainfrom
JiwaniZakir:fix/46-port-file-written-to-tmpdir-var-folders

Conversation

@JiwaniZakir

Copy link
Copy Markdown

Closes #46

Fixes port discovery on macOS by writing port advertisement files to /tmp instead of os.tmpdir(), which resolves to /var/folders/... on some macOS systems.

Changes

src/core/port-discovery.ts

  • Replaced const PORT_FILE_DIR = tmpdir() with a platform conditional: process.platform === 'win32' ? tmpdir() : '/tmp'. The Figma Desktop Bridge plugin hardcodes /tmp when scanning for port files, so the server must write there regardless of what os.tmpdir() returns on the host system.

tests/port-discovery.test.ts

  • Updated the existing getPortFilePath test to assert the expected directory based on platform (/tmp on non-Windows, tmpdir() on Windows).
  • Added a dedicated test asserting path.startsWith('/tmp/') on non-Windows platforms, explicitly covering the macOS os.tmpdir() divergence scenario.

Motivation

On macOS, os.tmpdir() can return /var/folders/l2/<hash>/T/ rather than /tmp. The Figma Desktop Bridge plugin scans only /tmp for figma-console-mcp-*.json port files. When these two paths diverge, the server successfully advertises its port (e.g. figma-console-mcp-9223.json) but writes it to /var/folders/..., which the plugin never checks. The result is the plugin stalling on "MCP scanning..." indefinitely and all write tools failing with "Cannot connect to Figma Desktop."

Workarounds like setting TMPDIR=/tmp in the MCP env config had no effect because the server reads os.tmpdir() at module load time. Hardcoding /tmp on non-Windows systems aligns the server's write location with the plugin's scan location without affecting Windows, where C:\Users\...\AppData\Local\Temp is the correct path.

Testing

Automated: The updated getPortFilePath tests in tests/port-discovery.test.ts verify the correct directory is selected per platform. The new explicit /tmp prefix assertion will catch any regression that reintroduces os.tmpdir() on macOS/Linux.

Manual verification: On a macOS host where os.tmpdir() returns /var/folders/..., after this change the server log should show:

"filePath":"/tmp/figma-console-mcp-9223.json","msg":"Port advertised"

and the Figma Desktop Bridge plugin should transition from "MCP scanning..." to a connected state. Confirm ls /tmp/figma-console-mcp-*.json shows the file immediately after the server starts.


This PR was created with AI assistance (Claude). The changes were reviewed by quality gates and a critic model before submission.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

Port file written to $TMPDIR (/var/folders/...) instead of /tmp/ — plugin cannot discover server on macOS

1 participant