GeezerVison is showing github.com — fix(core): expand ~ in a local MCP server's cwd by rekram1-node · Pull Request #61496 · anomalyco/opencode
Conversation
rekram1-node
commented
Nov 3, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Problem
A local MCP server's cwd didn't expand ~. The spawn path did path.resolve(directory, config.cwd), so "cwd": "~/tools" ended up as <project>/~/tools and "cwd": "~" as <project>/~.
Change
- I added
McpStdio.resolveCwd(directory, cwd) in packages/core/src/mcp/stdio.ts. It reuses FileAccess.resolvePath, the same ~ / ~/ / ~\ (Windows) expansion the shell and patch tools already use. ~user is left alone. The client now calls it, and anything else that spawns a stdio server can use the same function.
~ means the home of the machine running opencode. Environments don't expose their own home, and the shell tool already behaves this way for workspace locations, so I kept it consistent and wrote that down.
Verification
- New test in
packages/core/test/mcp-stdio.test.ts covers ~, ~/tools, a relative path, an absolute path and an unset cwd. It fails on ~ with the old expression.
bun run typecheck, bun run typecheck:tsc and test/mcp* in packages/core, and bun run check from the root.
Visual
<svg xmlns="http://www.w3.org/2000/svg" width="240" height="72" viewBox="0 0 240 72" fill="none" font-family="ui-monospace,Menlo,monospace" font-size="12">
<style>
.bad{animation:bad 4s ease-in-out infinite;opacity:0}
.good{animation:good 4s ease-in-out infinite}
.arrow{animation:good 4s ease-in-out infinite}
@keyframes bad{0%,35%{opacity:.55}50%,100%{opacity:0}}
@keyframes good{0%,40%{opacity:0}55%,95%{opacity:1}100%{opacity:0}}
@media (prefers-reduced-motion:reduce){.bad,.good,.arrow{animation:none}.bad{opacity:0}.good,.arrow{opacity:1}}
</style>
<rect x="1" y="1" width="238" height="70" rx="10" stroke="currentColor" stroke-opacity=".2"/>
<text x="16" y="26" fill="currentColor" fill-opacity=".5">cwd: "~/tools"</text>
<g class="bad">
<text x="16" y="52" fill="currentColor"><project>/~/tools</text>
<path d="M14 47h138" stroke="currentColor" stroke-width="1.5"/>
</g>
<g class="good">
<path class="arrow" d="M16 48h14m-4-4 4 4-4 4" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M40 54v-7l7-6 7 6v7z" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/>
<text x="64" y="52" fill="currentColor">$HOME/tools</text>
</g>
</svg>
Added by the opencode bot (AI-generated).
Public API: local MCP cwd config now expands a leading ~ to the home directory (backwards compatible apart from a directory literally named ~ in the project)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change looks sound. I ran the real MCP client connect path with cwd: "~/mcptools". On the base the server spawned in <workspace>/~/mcptools and the connection failed with NotFound. With this PR it spawns in $HOME/mcptools and connects. The MCP tests pass, except one descendant-termination test that also fails on the base. typecheck:tsc in core and tsc in schema both pass.
Public API: the config key is unchanged. Only the meaning of a cwd value starting with ~ / ~/ changes. Before, it pointed to a ~ directory inside the workspace; now it points to the home directory. This is backwards compatible, except for a config that really means a directory literally named ~ inside the project. That edge case is unlikely, and such a config can switch to ./~.
No concerns.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Nov 7, 2026
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|