# opencode-advisor-mcp **Repository Path**: henrydontbb/opencode-advisor-mcp ## Basic Information - **Project Name**: opencode-advisor-mcp - **Description**: Unofficial local MCP server that lets Codex ask a read-only OpenCode advisor for a second review pass on Git changes. - **Primary Language**: JavaScript - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-07-10 - **Last Updated**: 2026-07-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # OpenCode Advisor MCP OpenCode Advisor MCP gives Codex three local MCP tools: - `ask_opencode_advisor` for a read-only reviewer pass - `ask_opencode_planner` for a read-only planning pass - `get_opencode_task` for queued or running work The MCP server has exactly two built-in roles: `reviewer` and `planner`. It does not reuse normal OpenCode, Codex, or Cockpit provider settings. The bundled agents can reason only over the request plus supplied Git status/diff context and, for the planner, the supplied plan; they have no file or shell tools. ## Install And Configure The supported release path is the [Gitee `v0.3.2` source-only Release](https://gitee.com/henrydontbb/opencode-advisor-mcp/releases/tag/v0.3.2). It does not attach a binary tarball and is not published to npm. Check out the exact tag, pack locally, then install that local artifact. ```powershell git clone --branch v0.3.2 --depth 1 https://gitee.com/henrydontbb/opencode-advisor-mcp.git Set-Location opencode-advisor-mcp git rev-parse 'v0.3.2^{}' # Compare the resolved commit with the Gitee Release page before packing. npm ci npm pack npm install -g .\opencode-advisor-mcp-0.3.2.tgz npm run setup ``` `npm run setup` is required only for a first install. An upgrade that already has an independent provider profile must not rerun setup; install the verified local tarball and restart the MCP client instead. For another local packed tarball, install that exact file: ```powershell npm install -g opencode-advisor-setup ``` For source development or as a fallback, install dependencies and run setup from the checkout: ```powershell npm ci npm run setup ``` `opencode-advisor-setup` requires an interactive terminal. It asks for a third-party provider ID, display name, API base URL, transport (`responses` or `chat_completions`), model list, reviewer model and optional reasoning variant, planner model and optional reasoning variant, and API key. The key is hidden at entry and is never accepted from command arguments, MCP TOML, or a pipe. Setup does not inspect normal OpenCode, Codex, or Cockpit configuration, credentials, or account-login state; no OpenCode account login is required. The setup command creates an independent profile under `%USERPROFILE%\.codex\opencode-advisor` on Windows or `$HOME/.codex/opencode-advisor` on POSIX. Windows credentials use CurrentUser DPAPI. POSIX uses a filesystem-permission fallback: private `0700` profile directories and a `0600` Base64-encoded credential envelope, rather than DPAPI-equivalent encryption. The profile contains the bundled `codex-advisor` and `codex-planning-partner` agent templates plus a non-secret provider manifest. The credential is bound to the exact manifest fingerprint, and the generated OpenCode overlay must also match that manifest. An incomplete profile written during setup, stale overlay, or binding mismatch is fail-closed: MCP calls return setup guidance without queuing work. If setup ends before it writes profile artifacts, a previously valid profile remains usable. Rerun `opencode-advisor-setup` instead of editing profile artifacts by hand. ## MCP Configuration For a source checkout, use Node and the absolute server path. The only required environment setting is `OPENCODE_ADVISOR_ALLOWED_ROOTS`: ```toml [mcp_servers.opencode_advisor] command = "node" args = ["C:\\absolute\\path\\to\\opencode-advisor-mcp\\src\\server.mjs"] startup_timeout_sec = 30 tool_timeout_sec = 420 [mcp_servers.opencode_advisor.env] OPENCODE_ADVISOR_ALLOWED_ROOTS = "C:\\workspace\\allowed-repositories" ``` For a Gitee source-tag tarball or another local tarball installed globally, use `command = "opencode-advisor-mcp"`; [examples/codex-mcp.toml](examples/codex-mcp.toml) shows that installed-package form. Do not put provider URLs, model IDs, API keys, tokens, or `OPENCODE_CONFIG_CONTENT` in the MCP configuration. See [docs/CONFIGURATION.md](docs/CONFIGURATION.md) for non-secret runtime settings. ## Provider Compatibility The setup transport is explicit: - `responses` generates an `@ai-sdk/openai` provider. OpenCode owns the Responses streaming SSE exchange, including output-text events such as `response.output_text.delta` / `response.output_text.done`, error events (`error`, `response.failed`), and function-call events. - `chat_completions` generates an `@ai-sdk/openai-compatible` provider and uses standard `/v1/chat/completions` stream chunks followed by `[DONE]`. Each role can optionally select an OpenCode model `variant`. The choices are independent even when reviewer and planner use the same model; a common setup is reviewer `high` and planner `max`. Leave a variant empty to use the model default. For a `responses` provider/model that supports the selected variant, the generated OpenCode model variant reaches the Responses request as `reasoning.effort`. `high` and `max` are examples, not values guaranteed by every provider or model. The built-in agents deny all tool execution. A streamed function call is covered only as a fail-closed condition: it is not executed, does not complete a tool round-trip, and the built-in-agent fixture expects a timeout rather than a reviewer or planner result. Raw provider tool events are not MCP output; only structured assistant text can become a reviewer or planner result. The provider key belongs only to the independent Advisor profile. ## Verify From a source checkout: ```powershell npm run smoke npm test npm run test:doctor $env:OPENCODE_ADVISOR_ALLOWED_ROOTS = "" npm run doctor ``` `opencode-advisor-doctor` checks the independent profile, both roles, structured JSON output, and sanitized MCP response shape. A missing or unreadable profile remains an `opencode_failed` MCP result with setup guidance; it never creates a queued task. Use `opencode-advisor-doctor --json` (or `npm run --silent doctor -- --json` from source) for a machine-readable report. JSON mode preserves the same checks and exit status as the default text report and does not add provider settings or credentials. ## Legacy Windows Recovery Windows ownership records created before 0.3.2 are v1 records without durable tree containment. They are intentionally never auto-killed or auto-replayed. After a real Windows restart, use the explicit two-step recovery flow only for those retained records: ```powershell opencode-advisor-recover prepare # Restart Windows fully. Do not use sleep, hibernate, or only close the MCP client. opencode-advisor-recover finalize --plan --confirm-restarted ``` `prepare` does not modify the active queue. `finalize` verifies the prepared hashes and a changed boot observation, archives only the prepared v1 ownership records, marks old running tasks as `opencode_failed`, and expires old queued tasks. It never calls a process-kill API. New 0.3.2 Windows attempts use a per-call Job Object supervisor and can be recovered automatically only after that supervisor is identity-verified missing. ## Security Boundaries - Reviewer and planner child processes run with `--pure` and an explicit `provider/model`. - OpenCode receives isolated XDG and OpenCode configuration paths plus a generated `OPENCODE_CONFIG_CONTENT` overlay. - `OPENCODE_ADVISOR_RUNTIME_HOME` is an opt-in absolute local runtime-state override for disposable validation or CI; it redirects child runtime state without moving the Advisor profile, generated configuration, or credential. - `OPENCODE_DISABLE_PROJECT_CONFIG=1` prevents the reviewed repository's OpenCode configuration from being merged. - Inherited OpenCode, XDG, provider-key, token, secret, and password environment variables are removed before OpenCode starts. - Queue files, runner logs, doctor reports, and MCP responses do not include provider URLs, model selections, role variants, or API keys. - Default queue execution is serial. Each Advisor-started OpenCode attempt has private process ownership metadata. On Windows, 0.3.2 launches each durable OpenCode call through a dedicated Job Object supervisor: the managed root is created suspended, put in a non-breakaway `KILL_ON_JOB_CLOSE` Job, durably recorded as the supervisor's identity, and resumed only after that record is running. Reaping opens one supervisor process handle, verifies image, creation FILETIME, and file metadata on that handle, then calls `TerminateProcess` and waits on the same handle. The managed title is diagnostic only. A v2 supervisor that is identity-verified missing proves its Job tree is gone; malformed, mismatched, ambiguous, access-denied, or helper-failed records remain fenced. Legacy v1 Windows records never gain this authority and require `opencode-advisor-recover` after a confirmed restart. POSIX keeps exact verified detached process-group cleanup, starting with `SIGTERM` and escalating to `SIGKILL` on a later retry; both its root and group must disappear before replay. - Use planner and reviewer through the MCP tools. Direct `opencode run` or `opencode run --session` bypasses queue, timeout, ownership, and cleanup controls. - A custom `OPENCODE_ADVISOR_OPENCODE_CMD` on Windows must name an existing, operator-trusted absolute `.exe`; command strings with arguments and `.cmd` / `.bat` wrappers are rejected. - Keep `OPENCODE_ADVISOR_ALLOWED_ROOTS` narrow and use this only for repositories you are authorized to disclose to the configured provider. Further details: - [Install](docs/INSTALL.md) - [Configuration](docs/CONFIGURATION.md) - [Usage](docs/USAGE.md) - [Architecture](docs/ARCHITECTURE.md) - [Acceptance](docs/ACCEPTANCE.md)