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:
- Set up opencode server on a remote machine (e.g.,
xe at http://100.64.0.3:4096)
- Configure opencode-mcp with
OPENCODE_BASE_URL=http://100.64.0.3:4096
- 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"
}
- 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.
Describe the bug
The
normalizeDirectoryfunction insrc/helpers.tsperforms a localexistsSynccheck on the MCP client machine, but the directory is meant to be accessed by the remote opencode server. This causes alldirectoryparameter calls to fail when the MCP client and opencode server are on different machines.In our setup:
nmxe(accessed viaOPENCODE_BASE_URL)/mnt/accelerated/Code/BetterICSexists onxebut not onnmopencode_setup({directory: "/mnt/accelerated/Code/BetterICS"})returns:To Reproduce
Steps to reproduce the behavior:
xeathttp://100.64.0.3:4096)OPENCODE_BASE_URL=http://100.64.0.3:4096directoryparameter pointing to a path that exists on the remote server but not locally:{ "directory": "/mnt/accelerated/Code/BetterICS" }Directory not found: "/mnt/accelerated/Code/BetterICS" does not exist...Expected behavior
The
directoryparameter should be passed directly to the opencode server via thex-opencode-directoryheader 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.tslines 133-139:resolve(directory)resolves the path relative to the MCP client's working directoryexistsSync(normalized)checks existence on the MCP client's filesystemOPENCODE_BASE_URLpoints to a remote serverNetwork Topology
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.