Skip to content

fix(opencode): disable repo-level MCP entry by default + venv-python fallback - #108

Merged
jphein merged 2 commits into
mainfrom
fix/opencode-config-venv-python
May 22, 2026
Merged

fix(opencode): disable repo-level MCP entry by default + venv-python fallback#108
jphein merged 2 commits into
mainfrom
fix/opencode-config-venv-python

Conversation

@jphein

@jphein jphein commented May 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

Upstream PR MemPalace#1567's `.opencode/opencode.json` spawns `python -m mempalace.mcp_server` with bare `python`. On any uv-managed clone (which the README's setup steps produce), `python` resolves to system python without mempalace installed → spawn fails with `MCP error -32000: Connection closed` and a ModuleNotFoundError on stderr.

Visible to anyone who launches opencode from `/Projects/memorypalace`: an ERROR line per session, even though the user-level `/.config/opencode/opencode.jsonc` wrapper continues to work in parallel.

Fix: use `.venv/bin/python` (relative; resolves against the opencode cwd = repo root). Works for every contributor who ran `uv sync`.

Why fork-ahead instead of patching upstream

Upstream's intent was "portability across install methods (pip vs uv vs dev install)" per Gemini's review on MemPalace#1567. That intent is fine, but the actual upstream landing — bare `python` — assumes the contributor has activated their venv before launching opencode. uv users typically don't activate manually; uv handles it transparently for `uv run`, but opencode launches its own subprocess and inherits the unmodified shell PATH.

This commit picks the path that's correct for the uv setup the README documents. Filing an upstream PR to follow.

Test plan

  • `opencode` launched from repo root no longer logs the MCP -32000 error (verified by tailing `~/.local/share/opencode/log/`)
  • User-level wrapper at `~/.config/opencode/opencode.jsonc` still active in parallel — both MCP entries connect

🤖 Generated with Claude Code

…'t fail

Upstream PR MemPalace#1567's `.opencode/opencode.json` uses bare `python -m
mempalace.mcp_server`. That only works if mempalace is installed in
the python that resolves on PATH — which on JP's box (and any
uv-managed clone) it isn't, because mempalace lives in the editable
`./.venv/` and PATH-resolution finds system python instead.

Result: opencode launched from the repo root tries to spawn the
local MCP server, fails with `MCP error -32000: Connection closed`
+ a ModuleNotFoundError on mempalace, and logs ERROR every session.
The user-level `~/.config/opencode/opencode.jsonc` wrapper still
works in parallel, but the repo-level entry is noisy and broken.

Switch to `.venv/bin/python` — relative path, resolves against the
opencode cwd (the repo root), works for every contributor who ran
`uv sync` (which the README already tells them to do).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 22, 2026 03:40
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a configuration issue where the MCP server failed to start due to incorrect Python path resolution. By explicitly pointing to the local .venv/bin/python executable, the change ensures that the environment dependencies are correctly loaded, preventing spawn errors in uv-managed setups.

Highlights

  • MCP Server Configuration: Updated the command path in .opencode/opencode.json to use .venv/bin/python instead of the system python.
  • Environment Compatibility: Resolved ModuleNotFoundError issues for uv-managed environments by ensuring the local virtual environment is explicitly used for the MCP server process.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@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 updates the mempalace MCP server configuration in .opencode/opencode.json to use a specific virtual environment path for execution. The review feedback correctly identifies that the hardcoded Unix-style path is not cross-platform and recommends using uv run for better portability and environment management.

Comment thread .opencode/opencode.json
"mempalace": {
"type": "local",
"command": ["python", "-m", "mempalace.mcp_server"],
"command": [".venv/bin/python", "-m", "mempalace.mcp_server"],

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

The path .venv/bin/python is Unix-specific and will fail on Windows (where it is .venv/Scripts/python.exe). It also makes the configuration dependent on the current working directory. Since this project uses uv, using uv run is a more portable and robust solution that automatically handles platform-specific paths and environment activation, ensuring the correct dependencies are available regardless of whether the virtual environment was manually activated.

Suggested change
"command": [".venv/bin/python", "-m", "mempalace.mcp_server"],
"command": ["uv", "run", "python", "-m", "mempalace.mcp_server"],

Copilot AI 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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

…-server

A user-level `~/.config/opencode/opencode.jsonc` with a daemon-routed
wrapper is the canonical way to wire mempalace on this fork. When the
repo-level `.opencode/opencode.json` is ALSO enabled and points at a
local `mempalace.mcp_server` spawn, opencode connects to BOTH:

- user wrapper → palace-daemon at disks.jphe.in:8085 (309K production
  drawers, healthy)
- repo subprocess → `~/.mempalace/palace` (legacy katana store, 24K
  drawers, HNSW capacity divergence — 63% invisible to vector search)

Result: opencode's UI surfaces 'HNSW capacity divergence' + 'routing
to BM25 fallback' INFO-stderr lines that look like errors, and any
mempalace_* tool call non-deterministically lands on whichever server
opencode picked.

Flip `enabled` to false on the repo entry so the user-level wrapper
is the sole source of truth. Contributors who want a local-only
spawn (no daemon set up) flip back to true; the previous commit
already pointed the spawn at `.venv/bin/python` so it works for them
when uv-managed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jphein jphein changed the title fix(opencode): repo MCP config uses .venv/bin/python so spawn stops failing fix(opencode): disable repo-level MCP entry by default + venv-python fallback May 22, 2026
@jphein
jphein merged commit 47018e5 into main May 22, 2026
7 checks passed
@jphein
jphein deleted the fix/opencode-config-venv-python branch May 22, 2026 03:46
jphein added a commit that referenced this pull request May 22, 2026
…riding user wrapper (#110)

The previous `enabled: false` approach (PR #108) didn't work in
practice. opencode appears to merge the repo-level and user-level
MCP entries by name; the repo entry's `command` overrides the
user-level one even when `enabled` is set to false.

Symptom: the user-level wrapper at
`~/.config/opencode/opencode.jsonc` points at the daemon-routed
`mempalace-mcp-wrapper.sh`. The repo-level entry pointed at
`.venv/bin/python -m mempalace.mcp_server`. Opencode's log on
session start shows the local palace getting opened with
'mempalace-mcp: routing → local palace @ /home/jp/.mempalace/palace'
and the HNSW capacity divergence warning — meaning the repo's
local-spawn command won despite enabled=false.

Strip the `mcp` block from the repo config entirely. The user-level
wrapper handles daemon routing. Contributors who don't have a daemon
can add their own user-level config or re-add the entry under
`.opencode/opencode.local.json` (gitignored).

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
jphein added a commit that referenced this pull request May 22, 2026
…merges (#112)

Five PRs landed today that didn't have YAML entries yet; CLAUDE.md +
README still referenced the pre-transfer jphein/mempalace ownership;
the opencode integration recipe didn't cover the two gotchas that
bit us tonight (npm-vs-opencode-cache patch target; the "looks like
an error" stderr lines from local-palace spawns).

YAML additions (newest first):
  - local-palace-retired-marker (#111798cf14)
  - opencode-repo-config-empty-mcp (#1107133eee)
  - opencode-repo-mcp-drop-comment-key (#109637bb01)
  - opencode-repo-mcp-disable-flag (#10847018e5; superseded by #110)
  - mcp-stub-resources-prompts-list (#1076ca0670)

CLAUDE.md changes:
  - Fork URL: `jphein/mempalace` → `techempower-org/mempalace`
  - Origin/upstream line reflects the May 2026 transfer
  - Palace data section: local palace is retired; production lives in
    postgres on disks.jphe.in
  - Python venv: `./venv/` → `./.venv/` (uv convention)
  - Issue tracker links updated to techempower-org

README.md changes:
  - Quickstart and `Open upstream PRs` table use techempower-org URLs

docs/integrations/opencode.md changes:
  - New "Patch target gotcha" subsection: opencode caches plugins under
    ~/.cache/opencode/packages/ independently of the global npm install;
    patches must apply there.
  - New "What 'looks like an error' but isn't" verification subsection
    listing the three stderr lines that surfaced today during debug.
  - New "If you see a different palace count" troubleshooting block:
    palace-count divergence between MCP and CLI usually means an old
    shell without PALACE_DAEMON_URL; on this fork the local palace is
    retired so the CLI now refuses with the marker text.

FORK_CHANGELOG.md regenerated via scripts/render-docs.py. check-docs.sh
clean (29 fork hash refs resolve; only existing MemPalace#1024 pr_state warning,
unchanged).

Co-authored-by: Claude Opus 4.7 (1M context) <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.

2 participants