@mekareteriker/opencode-mcp 1.10.2-mekareteriker.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +204 -0
- package/LICENSE +22 -0
- package/README.md +174 -0
- package/dist/client.d.ts +60 -0
- package/dist/client.js +282 -0
- package/dist/client.js.map +1 -0
- package/dist/helpers.d.ts +150 -0
- package/dist/helpers.js +575 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +198 -0
- package/dist/index.js.map +1 -0
- package/dist/prompts.d.ts +9 -0
- package/dist/prompts.js +210 -0
- package/dist/prompts.js.map +1 -0
- package/dist/resources.d.ts +10 -0
- package/dist/resources.js +197 -0
- package/dist/resources.js.map +1 -0
- package/dist/server-manager.d.ts +72 -0
- package/dist/server-manager.js +264 -0
- package/dist/server-manager.js.map +1 -0
- package/dist/tools/config.d.ts +3 -0
- package/dist/tools/config.js +105 -0
- package/dist/tools/config.js.map +1 -0
- package/dist/tools/events.d.ts +6 -0
- package/dist/tools/events.js +63 -0
- package/dist/tools/events.js.map +1 -0
- package/dist/tools/file.d.ts +3 -0
- package/dist/tools/file.js +153 -0
- package/dist/tools/file.js.map +1 -0
- package/dist/tools/global.d.ts +3 -0
- package/dist/tools/global.js +17 -0
- package/dist/tools/global.js.map +1 -0
- package/dist/tools/message.d.ts +3 -0
- package/dist/tools/message.js +169 -0
- package/dist/tools/message.js.map +1 -0
- package/dist/tools/misc.d.ts +3 -0
- package/dist/tools/misc.js +298 -0
- package/dist/tools/misc.js.map +1 -0
- package/dist/tools/project.d.ts +3 -0
- package/dist/tools/project.js +62 -0
- package/dist/tools/project.js.map +1 -0
- package/dist/tools/provider.d.ts +3 -0
- package/dist/tools/provider.js +175 -0
- package/dist/tools/provider.js.map +1 -0
- package/dist/tools/session.d.ts +3 -0
- package/dist/tools/session.js +392 -0
- package/dist/tools/session.js.map +1 -0
- package/dist/tools/tui.d.ts +7 -0
- package/dist/tools/tui.js +121 -0
- package/dist/tools/tui.js.map +1 -0
- package/dist/tools/workflow.d.ts +7 -0
- package/dist/tools/workflow.js +775 -0
- package/dist/tools/workflow.js.map +1 -0
- package/package.json +68 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
Fork notation: entries tagged `[upstream]` were cherry-picked or carried forward from
|
|
9
|
+
[AlaeddineMessadi/opencode-mcp](https://github.com/AlaeddineMessadi/opencode-mcp).
|
|
10
|
+
Entries tagged `[fork]` are specific to `@mekareteriker/opencode-mcp`.
|
|
11
|
+
|
|
12
|
+
## [1.10.2-mekareteriker.0] - 2026-05-16
|
|
13
|
+
|
|
14
|
+
First release of the `@mekareteriker/opencode-mcp` fork. Re-publishes upstream `main` HEAD
|
|
15
|
+
(three commits sitting unreleased on master since `v1.10.1`, including the critical
|
|
16
|
+
Windows path fix), adds CI matrix for Linux/Windows/macOS, and changes nothing about
|
|
17
|
+
the wire protocol or tool surface — drop-in replacement for `opencode-mcp@1.10.1`.
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
|
|
21
|
+
- `[upstream]` Accept Windows absolute paths in `normalizeDirectory` ([upstream commit `e8e6cfe`](https://github.com/AlaeddineMessadi/opencode-mcp/commit/e8e6cfe), [PR #6](https://github.com/AlaeddineMessadi/opencode-mcp/pull/6) by [@samuelgudi](https://github.com/samuelgudi)). Previously the validator required the resolved path to start with `"/"`, which broke every tool that accepts `directory` on Windows clients. Now uses platform-aware `path.isAbsolute`.
|
|
22
|
+
|
|
23
|
+
### Added
|
|
24
|
+
|
|
25
|
+
- `[upstream]` `OPENCODE_SERVE_ARGS` env var for passing custom args to `opencode serve` ([upstream commit `0f1e1f6`](https://github.com/AlaeddineMessadi/opencode-mcp/commit/0f1e1f6), PR #7/#9).
|
|
26
|
+
- `[upstream]` `variant` parameter for model selection in tools ([upstream commit `4756a36`](https://github.com/AlaeddineMessadi/opencode-mcp/commit/4756a36), PR #8/#10).
|
|
27
|
+
- `[fork]` GitHub Actions CI: matrix `os: [ubuntu-latest, windows-latest, macos-latest]` × `node: [18, 20, 22]`, plus an npm-pack smoke job.
|
|
28
|
+
- `[fork]` `release.yml` workflow: publishes to npm on `v*` tag push with provenance.
|
|
29
|
+
- `[fork]` `sync-upstream.yml` workflow: daily cron mirrors upstream `main` into `upstream-tracking` branch and opens an issue if new commits land.
|
|
30
|
+
- `[fork]` `publishConfig.access: "public"` so the scoped package publishes without an extra `--access` flag.
|
|
31
|
+
|
|
32
|
+
### Changed
|
|
33
|
+
|
|
34
|
+
- `[fork]` Package name: `opencode-mcp` → `@mekareteriker/opencode-mcp`.
|
|
35
|
+
- `[fork]` `repository`/`homepage`/`bugs` URLs now point at `MekaretEriker/opencode-mcp`.
|
|
36
|
+
- `[fork]` `postbuild` script guards `chmod +x` with `|| true` so it doesn't fail on Windows runners (no chmod).
|
|
37
|
+
- `[fork]` LICENSE: dual copyright line preserving Alaeddine Messadi's original attribution alongside the fork maintainer's.
|
|
38
|
+
- `[fork]` Tests `tests/helpers.test.ts`, `tests/client.test.ts`, `tests/tools.test.ts` — hardcoded `/tmp` replaced by `os.tmpdir()` so the suite is platform-agnostic and Windows CI runner can pass. Addresses the "13 Linux-only failures" called out in upstream commit `e8e6cfe`. See `SPEC-fork.md` §4 patch #5.
|
|
39
|
+
|
|
40
|
+
### Patches pending upstream
|
|
41
|
+
|
|
42
|
+
- The `os.tmpdir()` test fix above is fork-only for now. Will submit to upstream as a PR; if merged it drops from the fork on the next rebase.
|
|
43
|
+
|
|
44
|
+
## [1.10.1] - 2026-04-10
|
|
45
|
+
|
|
46
|
+
### Changed
|
|
47
|
+
|
|
48
|
+
- Instruction examples now use discovered/default provider and model values instead of hardcoded Anthropic examples. This avoids steering MCP clients toward unavailable providers and aligns the startup guidance with `opencode_setup`.
|
|
49
|
+
|
|
50
|
+
### Fixed
|
|
51
|
+
|
|
52
|
+
- Health checks for authenticated OpenCode servers now propagate HTTP basic auth through the full auto-start path, including startup polling and reconnection flows.
|
|
53
|
+
- `ensureServer()` now forwards configured server credentials during startup so remote protected servers no longer fail the health probe while coming online.
|
|
54
|
+
|
|
55
|
+
### Stats
|
|
56
|
+
|
|
57
|
+
- Tool count: 79
|
|
58
|
+
- Tests: 320
|
|
59
|
+
|
|
60
|
+
## [1.10.0] - 2026-02-10
|
|
61
|
+
|
|
62
|
+
### Added
|
|
63
|
+
|
|
64
|
+
- **`opencode_permission_list` tool** — lists all pending permission requests across sessions, showing permission type, session ID, patterns, and tool name. Helps detect and unblock sessions stuck waiting for approval in headless mode.
|
|
65
|
+
- **`OPENCODE_DEFAULT_PROVIDER` / `OPENCODE_DEFAULT_MODEL` env vars** — set default provider and model for all tool calls. Three-tier resolution: explicit params → env defaults → server fallback. Implemented via `applyModelDefaults()` across all 8 model-accepting tools.
|
|
66
|
+
- **`normalizeDirectory()` path validation** — resolves paths to absolute, strips trailing slashes, resolves `..`, and rejects non-existent directories with descriptive errors.
|
|
67
|
+
- **Lazy server reconnection** — on `ECONNREFUSED`/`ENOTFOUND` after all retries, auto-restarts the OpenCode server (max 3 reconnection attempts per MCP session).
|
|
68
|
+
- **Enhanced `diagnoseError()`** — 6 new error patterns with contextual suggestions (empty response, model errors, permission issues, config problems).
|
|
69
|
+
- **Directory display in workflow responses** — `opencode_run`, `opencode_fire`, `opencode_check`, `opencode_status` now show the active project directory.
|
|
70
|
+
- **Session-directory consistency warnings** — warns when a session was created for a different directory than the current request.
|
|
71
|
+
- **Permissions guidance in instructions** — recommends `"permission": "allow"` in `opencode.json` for headless use, documents permission tools.
|
|
72
|
+
|
|
73
|
+
### Changed
|
|
74
|
+
|
|
75
|
+
- **`opencode_session_permission` updated** — now uses the new API (`POST /permission/{requestID}/reply`) with automatic fallback to the deprecated endpoint. `reply` parameter changed from free string to enum: `"once"` | `"always"` | `"reject"`. Removed the old `remember` parameter.
|
|
76
|
+
|
|
77
|
+
### Fixed
|
|
78
|
+
|
|
79
|
+
- **Directory validation errors swallowed by `.catch(() => null)`** — `opencode_status`, `opencode_context`, and `opencode_check` used `Promise.all` with `.catch(() => null)` which silently ate validation errors (showing "UNREACHABLE" instead of "directory not found"). Fixed by adding early `normalizeDirectory()` before `Promise.all` in all 3 tools.
|
|
80
|
+
|
|
81
|
+
### Removed
|
|
82
|
+
|
|
83
|
+
- Demo projects (`projects/snake-game/`, `projects/nextjs-todo-app/`) — these were test artifacts.
|
|
84
|
+
|
|
85
|
+
### Stats
|
|
86
|
+
|
|
87
|
+
- Tool count: 79 (up from 78)
|
|
88
|
+
- Tests: 316 (up from 275)
|
|
89
|
+
|
|
90
|
+
## [1.9.0] - 2026-02-10
|
|
91
|
+
|
|
92
|
+
### Added
|
|
93
|
+
|
|
94
|
+
- **`opencode_run` workflow tool** — one-call solution for complex tasks: creates a session, sends the prompt, polls until completion, and returns the result with todo progress. Supports `maxDurationSeconds` (default 10 min) and session reuse via `sessionId`.
|
|
95
|
+
- **`opencode_fire` workflow tool** — fire-and-forget: creates a session, dispatches the task, and returns immediately with the session ID and monitoring instructions. Best for long-running tasks where you want to do other work in parallel.
|
|
96
|
+
- **`opencode_check` workflow tool** — compact progress report for a session: status, todo progress (completed/total), current task, file change count. Much cheaper than `opencode_conversation`. Supports `detailed` mode for last message text.
|
|
97
|
+
- Tool count: 78 (up from 75)
|
|
98
|
+
- Tests: 275 (up from 267) — 8 new tests covering `opencode_run` (polling, error, session reuse), `opencode_fire` (dispatch, session reuse), and `opencode_check` (progress, completion, detailed mode)
|
|
99
|
+
|
|
100
|
+
### Changed
|
|
101
|
+
|
|
102
|
+
- Instructions updated with new Tier 2 tools (`opencode_run`, `opencode_fire`, `opencode_check`) and simplified recommended workflows
|
|
103
|
+
- Best-practices prompt updated with new tool selection table
|
|
104
|
+
|
|
105
|
+
## [1.8.0] - 2026-02-10
|
|
106
|
+
|
|
107
|
+
### Added
|
|
108
|
+
|
|
109
|
+
- **`instructions` field** — the MCP server now provides a comprehensive structured guide via the `instructions` option in the `McpServer` constructor. This helps LLM clients understand tool tiers (5 levels from essential to dangerous), recommended workflows, and the async `message_send_async` + `wait` pattern for long tasks.
|
|
110
|
+
- **Tool annotations** — all tools now carry MCP `readOnlyHint` / `destructiveHint` annotations so clients can auto-approve safe read-only operations and warn before destructive ones (e.g. `session_delete`, `instance_dispose`)
|
|
111
|
+
- **`opencode-best-practices` prompt** — new prompt template (6th prompt) covering setup, provider/model selection, tool selection table, prompt writing tips, monitoring, error recovery, and common pitfalls
|
|
112
|
+
- **Honest wake-up documentation** — `opencode_wait` description now explains that most MCP clients do NOT interrupt the LLM for log notifications, and suggests `opencode_session_todo` for monitoring very long tasks
|
|
113
|
+
|
|
114
|
+
### Changed
|
|
115
|
+
|
|
116
|
+
- `opencode_instance_dispose` description now includes a WARNING about permanent shutdown
|
|
117
|
+
- Prompts: 6 (up from 5)
|
|
118
|
+
- Tests: 267 (up from 266)
|
|
119
|
+
|
|
120
|
+
## [1.6.0] - 2026-02-09
|
|
121
|
+
|
|
122
|
+
### Fixed
|
|
123
|
+
|
|
124
|
+
- **Empty message display** — `formatMessageList()` no longer shows blank output for assistant messages that performed tool calls but had no text content. It now shows concise tool action summaries like `Agent performed 3 action(s): Write: /src/App.tsx, Bash: npm install`
|
|
125
|
+
- **Session status `[object Object]`** — `opencode_sessions_overview` and `opencode_session_status` now correctly resolve status objects (e.g. `{ state: "running" }`) to readable strings instead of displaying `[object Object]`
|
|
126
|
+
- **`opencode_wait` timeout message** — now includes actionable recovery suggestions (`opencode_conversation` to check progress, `opencode_session_abort` to stop) and correctly resolves object-shaped status values during polling
|
|
127
|
+
- **`toolError()` contextual suggestions** — common error patterns (401/403 auth, timeout, rate limit, connection refused, session not found) now include helpful follow-up tool suggestions instead of bare error text
|
|
128
|
+
|
|
129
|
+
### Added
|
|
130
|
+
|
|
131
|
+
- `resolveSessionStatus()` exported helper in `src/helpers.ts` — normalizes status from string, object (`{ state, status, type }`), or boolean flags into a readable string
|
|
132
|
+
- `summarizeToolInput()` helper — extracts the most useful arg (path, command, query, url) from tool input objects for compact display
|
|
133
|
+
- `extractCostMeta()` helper — extracts cost/token metadata from `step-finish` message parts
|
|
134
|
+
- `diagnoseError()` private helper — pattern-matches common errors and returns contextual suggestions
|
|
135
|
+
- 11 new tool handler tests for `opencode_sessions_overview`, `opencode_session_status`, and `opencode_wait` covering object status resolution, timeout messages, and edge cases
|
|
136
|
+
- Tests: 266 total (up from 255)
|
|
137
|
+
|
|
138
|
+
## [1.5.0] - 2026-02-09
|
|
139
|
+
|
|
140
|
+
### Added
|
|
141
|
+
|
|
142
|
+
- `opencode_status` workflow tool for a fast health/providers/sessions/VCS dashboard
|
|
143
|
+
- `opencode_provider_test` workflow tool to quickly validate a provider/model actually responds (creates a temp session, sends a tiny prompt, cleans up)
|
|
144
|
+
- `opencode_session_search` to find sessions by keyword in title (also matches session ID)
|
|
145
|
+
- `scripts/mcp-smoke-test.mjs` end-to-end smoke test runner (spawns opencode-mcp over stdio and exercises most tools/workflows against a running OpenCode server)
|
|
146
|
+
|
|
147
|
+
### Changed
|
|
148
|
+
|
|
149
|
+
- Provider configuration detection is now shared via `isProviderConfigured()` (used consistently across provider listing and setup workflows)
|
|
150
|
+
- Multiple tool outputs are more token-efficient and user-friendly (compact provider list/model listing, session formatting, and warning surfacing)
|
|
151
|
+
- Tool count: 75 (up from 72)
|
|
152
|
+
- Tests: 255 total
|
|
153
|
+
|
|
154
|
+
### Fixed
|
|
155
|
+
|
|
156
|
+
- `opencode_message_send` no longer silently returns empty output for empty responses; it now appends actionable warnings like `opencode_ask`/`opencode_reply`
|
|
157
|
+
- `opencode_session_share` / `opencode_session_unshare` now return formatted confirmations instead of raw JSON dumps
|
|
158
|
+
- `opencode_events_poll` no longer crashes on timeout when the SSE stream is idle (abort now cancels the stream safely)
|
|
159
|
+
|
|
160
|
+
## [1.4.0] - 2025-02-09
|
|
161
|
+
|
|
162
|
+
### Added
|
|
163
|
+
|
|
164
|
+
- **Auth error detection** — `opencode_ask` and `opencode_reply` now analyze AI responses for signs of failure (empty response, missing text content, error keywords like "unauthorized" or "invalid key") and append a clear `--- WARNING ---` with actionable guidance instead of silently returning nothing
|
|
165
|
+
- **`analyzeMessageResponse()` helper** — new diagnostic function in `src/helpers.ts` that detects empty, error, and auth-related response issues
|
|
166
|
+
- **Provider probing in `opencode_setup`** — connected providers are now verified with a lightweight "Reply with OK" probe to distinguish between WORKING, CONNECTED BUT NOT RESPONDING (bad API key), and could-not-verify states. Unconfigured providers now show available auth methods.
|
|
167
|
+
- **`opencode_provider_models` tool** — new tool to list models for a single provider, replacing the previous approach of dumping all providers and all models in one massive response
|
|
168
|
+
- **164 tests** (up from 140) — new tests for `analyzeMessageResponse`, auth warning in ask/reply, provider probe statuses, compact provider list, and per-provider model listing
|
|
169
|
+
|
|
170
|
+
### Changed
|
|
171
|
+
|
|
172
|
+
- **`opencode_provider_list` is now compact** — returns only provider names, connection status, and model count (not the full model list). This dramatically reduces token usage for MCP clients. Use `opencode_provider_models` with a provider ID to drill into a specific provider's models.
|
|
173
|
+
- Tool count: 72 (up from 71)
|
|
174
|
+
|
|
175
|
+
## [1.3.0] - 2025-02-08
|
|
176
|
+
|
|
177
|
+
### Added
|
|
178
|
+
|
|
179
|
+
- **Auto-serve** — the MCP server now automatically detects whether `opencode serve` is running and starts it as a child process if not. No more manual "start opencode serve" step before using the MCP server.
|
|
180
|
+
- Checks the `/global/health` endpoint on startup
|
|
181
|
+
- Finds the `opencode` binary via `which`/`where`
|
|
182
|
+
- Spawns `opencode serve --port <port>` and polls until healthy
|
|
183
|
+
- Graceful shutdown: kills the managed child process on SIGINT/SIGTERM/exit
|
|
184
|
+
- Clear error messages with install instructions if the binary is not found
|
|
185
|
+
- **`OPENCODE_AUTO_SERVE` env var** — set to `"false"` to disable auto-start for users who prefer manual control
|
|
186
|
+
- **`src/server-manager.ts` module** — new module with `findBinary()`, `isServerRunning()`, `startServer()`, `stopServer()`, `ensureServer()`
|
|
187
|
+
- **140 tests** (up from 117) — 23 new tests for the server manager covering health checks, binary detection, auto-start, error cases, and shutdown
|
|
188
|
+
|
|
189
|
+
### Changed
|
|
190
|
+
|
|
191
|
+
- Startup flow in `src/index.ts` now calls `ensureServer()` before connecting the MCP transport
|
|
192
|
+
- Updated README: removed manual "start opencode serve" step, added auto-serve documentation, updated env vars table and architecture section
|
|
193
|
+
|
|
194
|
+
## [1.2.0] - 2025-02-08
|
|
195
|
+
|
|
196
|
+
### Added
|
|
197
|
+
|
|
198
|
+
- **Per-tool project directory targeting** — every tool now accepts an optional `directory` parameter that scopes the request to a specific project directory via the `x-opencode-directory` header. This enables working with multiple projects simultaneously from a single MCP connection without restarting the server.
|
|
199
|
+
- **`opencode_setup` workflow tool** — new high-level onboarding tool that checks server health, lists provider configuration status, and shows project info. Use it as the first step when starting work.
|
|
200
|
+
- **117 tests** (up from 102) — new tests for directory header propagation, `opencode_setup` handler, and `directoryParam` validation
|
|
201
|
+
|
|
202
|
+
### Changed
|
|
203
|
+
|
|
204
|
+
- `opencode_find_file` tool: renamed the search-root override parameter from `directory` to `searchDirectory` to avoid collision with t
|
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Alaeddine Messadi (upstream author)
|
|
4
|
+
Copyright (c) 2026 Mekaret (fork maintainer)
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# @mekareteriker/opencode-mcp
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@mekareteriker/opencode-mcp)
|
|
4
|
+
[](https://github.com/MekaretEriker/opencode-mcp/blob/main/LICENSE)
|
|
5
|
+
[](https://nodejs.org/)
|
|
6
|
+
[](https://github.com/MekaretEriker/opencode-mcp/actions/workflows/ci.yml)
|
|
7
|
+
|
|
8
|
+
> **This is a hardened fork of [AlaeddineMessadi/opencode-mcp](https://github.com/AlaeddineMessadi/opencode-mcp).**
|
|
9
|
+
> The upstream package is unmaintained on npm (latest release `v1.10.1` is 5+ weeks old and missing a Windows-blocking fix already merged on master). This fork re-publishes upstream `main` HEAD, adds CI for Linux/Windows/macOS, and ships further hardening — structured errors, idempotency, SSE streaming — on a regular release cadence. Drop-in replacement: same wire protocol, same 79 tools.
|
|
10
|
+
>
|
|
11
|
+
> **Patches pending upstream** are tracked in [CHANGELOG.md](./CHANGELOG.md) and submitted upstream as PRs. When upstream merges, we rebase and the patch leaves the fork. We aim to stay as close to upstream as possible.
|
|
12
|
+
|
|
13
|
+
**Give any MCP client the power of [OpenCode](https://opencode.ai/).**
|
|
14
|
+
|
|
15
|
+
opencode-mcp is an MCP server that bridges your AI tools (Claude, Cursor, Windsurf, VS Code, etc.) to OpenCode's headless API. It lets your AI delegate real coding work — building features, debugging, refactoring, running tests — to OpenCode sessions that autonomously read, write, and execute code in your project.
|
|
16
|
+
|
|
17
|
+
**79 tools** | **10 resources** | **6 prompts** | **Multi-project** | **Auto-start** | **Windows-tested**
|
|
18
|
+
|
|
19
|
+
## Why Use This?
|
|
20
|
+
|
|
21
|
+
- **Delegate coding tasks** — Tell Claude "build me a REST API" and it delegates to OpenCode, which creates files, installs packages, writes tests, and reports back.
|
|
22
|
+
- **Parallel work** — Fire off multiple tasks to OpenCode while your primary AI keeps working on something else.
|
|
23
|
+
- **Any MCP client** — Works with Claude Desktop, Claude Code, Cursor, Windsurf, VS Code Copilot, Cline, Continue, Zed, Amazon Q, and any other MCP-compatible tool.
|
|
24
|
+
- **Zero setup** — The server auto-starts `opencode serve` if it's not already running. No manual steps.
|
|
25
|
+
- **Windows-first CI** — Every release is tested on Linux, Windows, and macOS across Node 18/20/22.
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
> **Prerequisite:** [OpenCode](https://opencode.ai/) must be installed.
|
|
30
|
+
> `curl -fsSL https://opencode.ai/install | bash` or `npm i -g opencode-ai` or `brew install sst/tap/opencode`
|
|
31
|
+
|
|
32
|
+
**Claude Code:**
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
claude mcp add opencode -- npx -y @mekareteriker/opencode-mcp
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**Claude Desktop / Cursor / Windsurf / Cline / Continue** (add to your MCP config):
|
|
39
|
+
|
|
40
|
+
```json
|
|
41
|
+
{
|
|
42
|
+
"mcpServers": {
|
|
43
|
+
"opencode": {
|
|
44
|
+
"command": "npx",
|
|
45
|
+
"args": ["-y", "@mekareteriker/opencode-mcp"]
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
That's it. Restart your client and OpenCode's tools will be available.
|
|
52
|
+
|
|
53
|
+
### Migrating from upstream `opencode-mcp`
|
|
54
|
+
|
|
55
|
+
If you have the upstream package in your MCP config, change `"opencode-mcp"` to `"@mekareteriker/opencode-mcp"` in the `args` array. Nothing else changes — same tool names, same parameters, same behavior. To go back, just swap the name back.
|
|
56
|
+
|
|
57
|
+
> See [Configuration](docs/configuration.md) for all client configs (VS Code Copilot, Zed, Amazon Q, etc.) and environment variables.
|
|
58
|
+
|
|
59
|
+
## How It Works
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
MCP Client <--stdio--> opencode-mcp <--HTTP--> OpenCode Server
|
|
63
|
+
(Claude, Cursor, etc.) (this package) (opencode serve)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Your MCP client calls tools over stdio. This server translates them into HTTP requests to the OpenCode headless API. If the OpenCode server isn't running, it's started automatically.
|
|
67
|
+
|
|
68
|
+
## Key Tools
|
|
69
|
+
|
|
70
|
+
The 79 tools are organized into tiers. Start with the workflow tools — they handle the common patterns in a single call.
|
|
71
|
+
|
|
72
|
+
### Workflow Tools (13) — Start Here
|
|
73
|
+
|
|
74
|
+
| Tool | What it does |
|
|
75
|
+
|---|---|
|
|
76
|
+
| `opencode_setup` | Check server health, providers, and project status. Use first. |
|
|
77
|
+
| `opencode_ask` | Create session + send prompt + get answer. One call. |
|
|
78
|
+
| `opencode_reply` | Follow-up message in an existing session |
|
|
79
|
+
| `opencode_run` | Send a task and wait for completion (session + async send + polling) |
|
|
80
|
+
| `opencode_fire` | Fire-and-forget: dispatch a task, return immediately |
|
|
81
|
+
| `opencode_check` | Compact progress report for a running session (status, todos, files changed) |
|
|
82
|
+
| `opencode_conversation` | Get formatted conversation history |
|
|
83
|
+
| `opencode_sessions_overview` | Quick overview of all sessions |
|
|
84
|
+
| `opencode_context` | Project + VCS + config + agents in one call |
|
|
85
|
+
| `opencode_review_changes` | Formatted diff summary for a session |
|
|
86
|
+
| `opencode_wait` | Poll an async session until it finishes |
|
|
87
|
+
| `opencode_provider_test` | Quick-test whether a provider is working |
|
|
88
|
+
| `opencode_status` | Health + providers + sessions + VCS dashboard |
|
|
89
|
+
|
|
90
|
+
### Recommended Patterns
|
|
91
|
+
|
|
92
|
+
**Quick question:**
|
|
93
|
+
```
|
|
94
|
+
opencode_ask({ prompt: "Explain the auth flow in this project" })
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
**Build something and wait:**
|
|
98
|
+
```
|
|
99
|
+
opencode_run({ prompt: "Add input validation to POST /api/users", maxDurationSeconds: 300 })
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**Parallel background tasks:**
|
|
103
|
+
```
|
|
104
|
+
opencode_fire({ prompt: "Refactor the auth module to use JWT" })
|
|
105
|
+
→ returns sessionId immediately
|
|
106
|
+
opencode_check({ sessionId: "..." })
|
|
107
|
+
→ check progress anytime
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### All Tool Categories
|
|
111
|
+
|
|
112
|
+
| Category | Count | Description |
|
|
113
|
+
|---|---|---|
|
|
114
|
+
| [Workflow](docs/tools.md#workflow-tools) | 13 | High-level composite operations |
|
|
115
|
+
| [Session](docs/tools.md#session-tools) | 20 | Create, list, fork, share, abort, revert, permissions |
|
|
116
|
+
| [Message](docs/tools.md#message-tools) | 6 | Send prompts, execute commands, run shell |
|
|
117
|
+
| [File & Search](docs/tools.md#file--search-tools) | 6 | Search text/regex, find files/symbols, read files |
|
|
118
|
+
| [System](docs/tools.md#system--monitoring-tools) | 13 | Health, VCS, LSP, MCP servers, agents, logging |
|
|
119
|
+
| [TUI Control](docs/tools.md#tui-control-tools) | 9 | Remote-control the OpenCode terminal UI |
|
|
120
|
+
| [Provider & Auth](docs/tools.md#provider--auth-tools) | 6 | List providers/models, set API keys, OAuth |
|
|
121
|
+
| [Config](docs/tools.md#config-tools) | 3 | Get/update configuration |
|
|
122
|
+
| [Project](docs/tools.md#project-tools) | 2 | List and inspect projects |
|
|
123
|
+
| [Events](docs/tools.md#event-tools) | 1 | Poll real-time SSE events |
|
|
124
|
+
|
|
125
|
+
### Resources (10)
|
|
126
|
+
|
|
127
|
+
Browseable data endpoints — your client can read these without tool calls:
|
|
128
|
+
|
|
129
|
+
| URI | Description |
|
|
130
|
+
|---|---|
|
|
131
|
+
| `opencode://project/current` | Current active project |
|
|
132
|
+
| `opencode://config` | Current configuration |
|
|
133
|
+
| `opencode://providers` | Providers with models |
|
|
134
|
+
| `opencode://agents` | Available agents |
|
|
135
|
+
| `opencode://commands` | Available commands |
|
|
136
|
+
| `opencode://health` | Server health and version |
|
|
137
|
+
| `opencode://vcs` | Version control info |
|
|
138
|
+
| `opencode://sessions` | All sessions |
|
|
139
|
+
| `opencode://mcp-servers` | MCP server status |
|
|
140
|
+
| `opencode://file-status` | VCS file status |
|
|
141
|
+
|
|
142
|
+
### Prompts (6)
|
|
143
|
+
|
|
144
|
+
Guided workflow templates your client can offer as selectable actions:
|
|
145
|
+
|
|
146
|
+
| Prompt | Description |
|
|
147
|
+
|---|---|
|
|
148
|
+
| `opencode-code-review` | Review diffs from a session |
|
|
149
|
+
| `opencode-debug` | Step-by-step debugging workflow |
|
|
150
|
+
| `opencode-project-setup` | Get oriented in a new project |
|
|
151
|
+
| `opencode-implement` | Have OpenCode build a feature |
|
|
152
|
+
| `opencode-best-practices` | Setup, tool selection, monitoring, and pitfalls |
|
|
153
|
+
| `opencode-session-summary` | Summarize what happened in a session |
|
|
154
|
+
|
|
155
|
+
## Multi-Project Support
|
|
156
|
+
|
|
157
|
+
Every tool accepts an optional `directory` parameter to target a different project. No restarts needed.
|
|
158
|
+
|
|
159
|
+
```
|
|
160
|
+
opencode_ask({ directory: "/home/user/mobile-app", prompt: "Add navigation" })
|
|
161
|
+
opencode_ask({ directory: "/home/user/web-app", prompt: "Add auth" })
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Environment Variables
|
|
165
|
+
|
|
166
|
+
All optional. Only needed if you've changed defaults on the OpenCode server.
|
|
167
|
+
|
|
168
|
+
| Variable | Default | Description |
|
|
169
|
+
|---|---|---|
|
|
170
|
+
| `OPENCODE_BASE_URL` | `http://127.0.0.1:4096` | OpenCode server URL |
|
|
171
|
+
| `OPENCODE_SERVER_USERNAME` | `opencode` | HTTP basic auth username |
|
|
172
|
+
| `OPENCODE_SERVER_PASSWORD` | *(none)* | HTTP basic auth password (enables auth when set) |
|
|
173
|
+
| `OPENCODE_AUTO_SERVE` | `true` | Auto-start `opencode serve` if not running |
|
|
174
|
+
| `OPENCODE_DEFAULT_PROVIDER` | *(none)* | Default provider ID when not specified p
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP client wrapper for the OpenCode server API.
|
|
3
|
+
*
|
|
4
|
+
* Features:
|
|
5
|
+
* - Basic auth support
|
|
6
|
+
* - Automatic retry with exponential backoff for transient errors
|
|
7
|
+
* - Proper 204 No Content handling on all methods
|
|
8
|
+
* - SSE streaming support
|
|
9
|
+
* - Error categorization (transient vs permanent)
|
|
10
|
+
* - Directory path normalization and validation
|
|
11
|
+
* - Lazy server reconnection on connection failure
|
|
12
|
+
*/
|
|
13
|
+
export interface OpenCodeClientOptions {
|
|
14
|
+
baseUrl: string;
|
|
15
|
+
username?: string;
|
|
16
|
+
password?: string;
|
|
17
|
+
/** Enable lazy server reconnection when connection fails. */
|
|
18
|
+
autoServe?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare class OpenCodeError extends Error {
|
|
21
|
+
readonly status: number;
|
|
22
|
+
readonly method: string;
|
|
23
|
+
readonly path: string;
|
|
24
|
+
readonly body: string;
|
|
25
|
+
constructor(message: string, status: number, method: string, path: string, body: string);
|
|
26
|
+
get isTransient(): boolean;
|
|
27
|
+
get isNotFound(): boolean;
|
|
28
|
+
get isAuth(): boolean;
|
|
29
|
+
}
|
|
30
|
+
export declare class OpenCodeClient {
|
|
31
|
+
private baseUrl;
|
|
32
|
+
private authHeader?;
|
|
33
|
+
private autoServe;
|
|
34
|
+
private reconnectAttempts;
|
|
35
|
+
private username?;
|
|
36
|
+
private password?;
|
|
37
|
+
constructor(options: OpenCodeClientOptions);
|
|
38
|
+
getBaseUrl(): string;
|
|
39
|
+
private buildUrl;
|
|
40
|
+
private headers;
|
|
41
|
+
private request;
|
|
42
|
+
get<T = unknown>(path: string, query?: Record<string, string>, directory?: string): Promise<T>;
|
|
43
|
+
post<T = unknown>(path: string, body?: unknown, opts?: {
|
|
44
|
+
timeout?: number;
|
|
45
|
+
directory?: string;
|
|
46
|
+
}): Promise<T>;
|
|
47
|
+
patch<T = unknown>(path: string, body?: unknown, directory?: string): Promise<T>;
|
|
48
|
+
put<T = unknown>(path: string, body?: unknown, directory?: string): Promise<T>;
|
|
49
|
+
delete<T = unknown>(path: string, query?: Record<string, string>, directory?: string): Promise<T>;
|
|
50
|
+
/**
|
|
51
|
+
* Subscribe to SSE events. Returns an async iterable of parsed events.
|
|
52
|
+
* The caller should break out of the loop when done.
|
|
53
|
+
*/
|
|
54
|
+
subscribeSSE(path: string, opts?: {
|
|
55
|
+
signal?: AbortSignal;
|
|
56
|
+
}): AsyncGenerator<{
|
|
57
|
+
event: string;
|
|
58
|
+
data: string;
|
|
59
|
+
}, void, undefined>;
|
|
60
|
+
}
|