Skip to content

connect opencode fails: OpenCode bootstraps opencode.jsonc, mcpproxy only recognizes opencode.json #922

Closed

Description

@algis-dumbris

Summary

mcpproxy connect opencode (and the Connect Clients flow) fails on a fresh OpenCode installation because recent OpenCode versions bootstrap their global config as opencode.jsonc, while mcpproxy only recognizes opencode.json. OpenCode is then reported as not installed, and an explicit connect is refused.

Environment

  • MCPProxy v0.52.0 (personal) darwin/arm64 (tray app + bundled CLI)
  • OpenCode 1.18.8 (Homebrew), macOS
  • Fresh OpenCode setup: first run auto-created ~/.config/opencode/ with opencode.jsonc containing only the $schema stub — no opencode.json anywhere

Reproduction

$ opencode --version
1.18.8
$ ls ~/.config/opencode/
.gitignore  node_modules  opencode.jsonc  package-lock.json  package.json

$ mcpproxy connect opencode
Error: OpenCode config file /Users/user/.config/opencode/opencode.json does not exist

The status/UI side has the same blind spot: OpenCode shows Exists: false (treated as not installed), so the Connect Clients flow offers no working path either.

Root cause

internal/connect/clients.go — ConfigPath("opencode", …) returns only the .json variant:

case "opencode":
    ...
    return filepath.Join(homeDir, ".config", "opencode", "opencode.json")

internal/connect/connect.go — Connect() has an opencode-specific existence gate on that single path, so a .jsonc-only installation can never connect:

if client.ID == "opencode" {
    if _, err := os.Stat(cfgPath); os.IsNotExist(err) {
        return nil, fmt.Errorf("OpenCode config file %s does not exist", cfgPath)
    }
}

GetAllStatus() / GetStatus() use os.Stat on the same single path, so detection reports OpenCode as absent.

Meanwhile OpenCode itself probes and merges three global config files (from its own log, v1.18.8):

loading path=~/.config/opencode/config.json
loading path=~/.config/opencode/opencode.json
loading path=~/.config/opencode/opencode.jsonc

and its bootstrap creates opencode.jsonc, not opencode.json. So on any freshly installed OpenCode, mcpproxy's single-path assumption never matches.

Suggested fix

In ConfigPath (or an opencode-specific resolver), probe the candidates OpenCode actually loads — opencode.json, opencode.jsonc (and possibly config.json) — and target the one that exists; keep opencode.json as the default for the create-new case.

Two details worth handling:

  1. Detection: Exists/installed status should be true if any of the candidate files exists.
  2. Write target: prefer writing into the file that already exists. Writing a new opencode.json next to an existing opencode.jsonc technically works today (OpenCode merges both, and the stub .jsonc has no mcp key), but it is fragile: .jsonc is loaded after .json, so any mcp.mcpproxy entry the user later adds/edits in .jsonc silently shadows the one mcpproxy wrote — and the user ends up with two config files disagreeing about the same server. .jsonc accepts plain JSON output, so writing into it is safe as long as existing comments are preserved or the file is comment-free (the bootstrap stub is).

Workaround

Manually add the entry to ~/.config/opencode/opencode.jsonc:

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "mcpproxy": {
      "type": "remote",
      "url": "http://127.0.0.1:8080/mcp",
      "enabled": true
    }
  }
}

Activity

  1. Dumbris commented on Jul 28, 2026

    @Dumbris
    Member

    Fix up in #923 (Codex-reviewed, auto-merge armed pending CI).

    Implementation notes vs. the suggested fix:

    • Path resolution probes opencode.jsonc → opencode.json (preferring .jsonc since it shadows .json for the same keys); opencode.json stays the default for the create-new case. Detection (Exists/status) is true if either exists. config.json was left out deliberately — current OpenCode docs direct users to opencode.json(c); the legacy file can be added later if reports surface.
    • .jsonc parsing tolerates // and /* */ comments plus trailing commas (string-aware; unterminated block comments are a parse error, not silently accepted).
    • Write safety: connect/disconnect refuse to rewrite a .jsonc that actually uses comments (re-serializing would strip them) with a manual-edit hint — the comment-free bootstrap stub, i.e. the reported case, rewrites cleanly.
    • Drift handling beyond the report: if an entry was written to opencode.json and a later OpenCode upgrade bootstraps opencode.jsonc, disconnect finds the entry in the other candidate and undo restores the file its backup actually came from.
  2. Dumbris commented on Jul 29, 2026

    @Dumbris
    Member

    Fixed in #923 (commit 6692231), released on main.

    mcpproxy connect opencode and the Connect Clients flow now recognize OpenCode's opencode.jsonc global config alongside opencode.json, so a fresh OpenCode install is detected instead of being reported as not installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions