Skip to content

[BUG]: normalizeDirectory performs local existsSync check, breaking remote opencode server scenarios #14

@ad2248

Description

@ad2248

Describe the bug

The normalizeDirectory function in src/helpers.ts performs a local existsSync check on the MCP client machine, but the directory is meant to be accessed by the remote opencode server. This causes all directory parameter calls to fail when the MCP client and opencode server are on different machines.

In our setup:

  • MCP client runs on machine nm
  • Opencode server runs on machine xe (accessed via OPENCODE_BASE_URL)
  • Directory /mnt/accelerated/Code/BetterICS exists on xe but not on nm
  • Calling opencode_setup({directory: "/mnt/accelerated/Code/BetterICS"}) returns:
    Error: Directory not found: "/mnt/accelerated/Code/BetterICS" does not exist...
    

To Reproduce

Steps to reproduce the behavior:

  1. Set up opencode server on a remote machine (e.g., xe at http://100.64.0.3:4096)
  2. Configure opencode-mcp with OPENCODE_BASE_URL=http://100.64.0.3:4096
  3. Call any tool with a directory parameter pointing to a path that exists on the remote server but not locally:
    {
      "directory": "/mnt/accelerated/Code/BetterICS"
    }
  4. See error: Directory not found: "/mnt/accelerated/Code/BetterICS" does not exist...

Expected behavior

The directory parameter should be passed directly to the opencode server via the x-opencode-directory header without local validation. The opencode server itself is responsible for validating directory existence and permissions.

Screenshots

N/A

Additional context

Root Cause Analysis

The problematic code is in src/helpers.ts lines 133-139:

const normalized = resolve(directory);  // Resolves path on MCP client machine
if (!existsSync(normalized)) {          // Checks existence on MCP client machine ❌
  throw new Error(
    `Directory not found: "${normalized}" does not exist...`
  );
}
  • resolve(directory) resolves the path relative to the MCP client's working directory
  • existsSync(normalized) checks existence on the MCP client's filesystem
  • This is incorrect when OPENCODE_BASE_URL points to a remote server

Network Topology

Hermes (nm) → stdio → opencode-mcp (nm) → HTTP → opencode serve (xe)
                              ↓
                    existsSync checks nm's filesystem ❌
                    should pass directory to xe untouched ✓

Related

This issue prevents using opencode-mcp in distributed setups where the AI assistant (MCP client) and the code execution environment (opencode server) run on separate machines.

Metadata

Metadata

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions