opencode-mcp 1.4.0 → 1.8.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 +55 -0
- package/README.md +25 -8
- package/dist/client.d.ts +3 -1
- package/dist/client.js +29 -1
- package/dist/client.js.map +1 -1
- package/dist/helpers.d.ts +45 -0
- package/dist/helpers.js +293 -11
- package/dist/helpers.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +82 -11
- package/dist/index.js.map +1 -1
- package/dist/prompts.js +65 -0
- package/dist/prompts.js.map +1 -1
- package/dist/tools/config.js +70 -3
- package/dist/tools/config.js.map +1 -1
- package/dist/tools/events.js +1 -1
- package/dist/tools/events.js.map +1 -1
- package/dist/tools/file.js +38 -17
- package/dist/tools/file.js.map +1 -1
- package/dist/tools/global.js +6 -3
- package/dist/tools/global.js.map +1 -1
- package/dist/tools/message.js +10 -2
- package/dist/tools/message.js.map +1 -1
- package/dist/tools/misc.js +145 -11
- package/dist/tools/misc.js.map +1 -1
- package/dist/tools/project.js +41 -3
- package/dist/tools/project.js.map +1 -1
- package/dist/tools/provider.js +94 -28
- package/dist/tools/provider.js.map +1 -1
- package/dist/tools/session.js +126 -19
- package/dist/tools/session.js.map +1 -1
- package/dist/tools/workflow.js +278 -88
- package/dist/tools/workflow.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,61 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.8.0] - 2026-02-10
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **`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.
|
|
13
|
+
- **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`)
|
|
14
|
+
- **`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
|
|
15
|
+
- **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
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- `opencode_instance_dispose` description now includes a WARNING about permanent shutdown
|
|
20
|
+
- Prompts: 6 (up from 5)
|
|
21
|
+
- Tests: 267 (up from 266)
|
|
22
|
+
|
|
23
|
+
## [1.6.0] - 2026-02-09
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
|
|
27
|
+
- **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`
|
|
28
|
+
- **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]`
|
|
29
|
+
- **`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
|
|
30
|
+
- **`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
|
|
31
|
+
|
|
32
|
+
### Added
|
|
33
|
+
|
|
34
|
+
- `resolveSessionStatus()` exported helper in `src/helpers.ts` — normalizes status from string, object (`{ state, status, type }`), or boolean flags into a readable string
|
|
35
|
+
- `summarizeToolInput()` helper — extracts the most useful arg (path, command, query, url) from tool input objects for compact display
|
|
36
|
+
- `extractCostMeta()` helper — extracts cost/token metadata from `step-finish` message parts
|
|
37
|
+
- `diagnoseError()` private helper — pattern-matches common errors and returns contextual suggestions
|
|
38
|
+
- 11 new tool handler tests for `opencode_sessions_overview`, `opencode_session_status`, and `opencode_wait` covering object status resolution, timeout messages, and edge cases
|
|
39
|
+
- Tests: 266 total (up from 255)
|
|
40
|
+
|
|
41
|
+
## [1.5.0] - 2026-02-09
|
|
42
|
+
|
|
43
|
+
### Added
|
|
44
|
+
|
|
45
|
+
- `opencode_status` workflow tool for a fast health/providers/sessions/VCS dashboard
|
|
46
|
+
- `opencode_provider_test` workflow tool to quickly validate a provider/model actually responds (creates a temp session, sends a tiny prompt, cleans up)
|
|
47
|
+
- `opencode_session_search` to find sessions by keyword in title (also matches session ID)
|
|
48
|
+
- `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)
|
|
49
|
+
|
|
50
|
+
### Changed
|
|
51
|
+
|
|
52
|
+
- Provider configuration detection is now shared via `isProviderConfigured()` (used consistently across provider listing and setup workflows)
|
|
53
|
+
- Multiple tool outputs are more token-efficient and user-friendly (compact provider list/model listing, session formatting, and warning surfacing)
|
|
54
|
+
- Tool count: 75 (up from 72)
|
|
55
|
+
- Tests: 255 total
|
|
56
|
+
|
|
57
|
+
### Fixed
|
|
58
|
+
|
|
59
|
+
- `opencode_message_send` no longer silently returns empty output for empty responses; it now appends actionable warnings like `opencode_ask`/`opencode_reply`
|
|
60
|
+
- `opencode_session_share` / `opencode_session_unshare` now return formatted confirmations instead of raw JSON dumps
|
|
61
|
+
- `opencode_events_poll` no longer crashes on timeout when the SSE stream is idle (abort now cancels the stream safely)
|
|
62
|
+
|
|
8
63
|
## [1.4.0] - 2025-02-09
|
|
9
64
|
|
|
10
65
|
### Added
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
An [MCP](https://modelcontextprotocol.io/) server that gives any MCP-compatible client full access to [OpenCode](https://opencode.ai/). Manage sessions, send prompts, search files, review diffs, configure providers, control the TUI, and more.
|
|
9
9
|
|
|
10
|
-
**
|
|
10
|
+
**75 tools** | **10 resources** | **5 prompts** | **Multi-project support** | **Auto-start**
|
|
11
11
|
|
|
12
12
|
## Quick Start
|
|
13
13
|
|
|
@@ -184,8 +184,10 @@ High-level tools designed to be the easiest way for an LLM to interact with Open
|
|
|
184
184
|
| `opencode_context` | Project + path + VCS + config + agents in one call |
|
|
185
185
|
| `opencode_wait` | Poll an async session until it finishes |
|
|
186
186
|
| `opencode_review_changes` | Formatted diff summary for a session |
|
|
187
|
+
| `opencode_provider_test` | Quick-test whether a provider is actually working |
|
|
188
|
+
| `opencode_status` | Quick dashboard: health, providers, sessions, VCS |
|
|
187
189
|
|
|
188
|
-
### Session Tools (
|
|
190
|
+
### Session Tools (19)
|
|
189
191
|
|
|
190
192
|
Create, list, get, delete, update, fork, share, abort, revert sessions. Get diffs, todos, summaries, child sessions, and respond to permission requests.
|
|
191
193
|
|
|
@@ -197,7 +199,11 @@ Send prompts (sync or async), list/get messages, execute slash commands, run she
|
|
|
197
199
|
|
|
198
200
|
Search text/regex across the project, find files by name, find workspace symbols, list directories, read files, check VCS file status.
|
|
199
201
|
|
|
200
|
-
###
|
|
202
|
+
### Project Tools (2)
|
|
203
|
+
|
|
204
|
+
List known projects and inspect the current active project.
|
|
205
|
+
|
|
206
|
+
### Config & Provider Tools (9)
|
|
201
207
|
|
|
202
208
|
Get/update config, list providers and models, manage auth (API keys, OAuth).
|
|
203
209
|
|
|
@@ -205,7 +211,7 @@ Get/update config, list providers and models, manage auth (API keys, OAuth).
|
|
|
205
211
|
|
|
206
212
|
Remote-control the OpenCode TUI: append/submit/clear prompts, execute commands, show toasts, open dialogs (help, sessions, models, themes).
|
|
207
213
|
|
|
208
|
-
### System & Monitoring Tools (
|
|
214
|
+
### System & Monitoring Tools (14)
|
|
209
215
|
|
|
210
216
|
Health checks, VCS info, LSP/formatter status, MCP server management, agent/command listing, logging, SSE event polling.
|
|
211
217
|
|
|
@@ -308,14 +314,14 @@ src/
|
|
|
308
314
|
resources.ts MCP Resources (10 browseable data endpoints)
|
|
309
315
|
prompts.ts MCP Prompts (5 guided workflow templates)
|
|
310
316
|
tools/
|
|
311
|
-
workflow.ts High-level workflow tools (
|
|
312
|
-
session.ts Session management tools (
|
|
317
|
+
workflow.ts High-level workflow tools (10)
|
|
318
|
+
session.ts Session management tools (19)
|
|
313
319
|
message.ts Message/prompt tools (6)
|
|
314
320
|
file.ts File and search tools (6)
|
|
315
321
|
tui.ts TUI remote control tools (9)
|
|
316
322
|
config.ts Config tools (3)
|
|
317
323
|
provider.ts Provider/auth tools (6)
|
|
318
|
-
misc.ts System, agents, LSP, MCP, logging tools (
|
|
324
|
+
misc.ts System, agents, LSP, MCP, logging tools (12)
|
|
319
325
|
events.ts SSE event polling (1)
|
|
320
326
|
global.ts Health check (1)
|
|
321
327
|
project.ts Project tools (2)
|
|
@@ -332,11 +338,22 @@ npm start # runs the MCP server
|
|
|
332
338
|
npm run dev # watch mode
|
|
333
339
|
```
|
|
334
340
|
|
|
341
|
+
### Smoke Testing
|
|
342
|
+
|
|
343
|
+
There is a local smoke test runner that spawns `opencode-mcp` over stdio and calls most tools end-to-end against your running OpenCode server:
|
|
344
|
+
|
|
345
|
+
```bash
|
|
346
|
+
npm run build
|
|
347
|
+
node scripts/mcp-smoke-test.mjs
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
By default it **skips tools that are destructive or require special environment state** (OAuth flows, TUI control, `config_update`, `instance_dispose`, long-running `session_init`/`session_summarize`).
|
|
351
|
+
|
|
335
352
|
## Documentation
|
|
336
353
|
|
|
337
354
|
- [Getting Started](docs/getting-started.md) — step-by-step setup guide
|
|
338
355
|
- [Configuration](docs/configuration.md) — all env vars and MCP client configs
|
|
339
|
-
- [Tools Reference](docs/tools.md) — detailed reference for all
|
|
356
|
+
- [Tools Reference](docs/tools.md) — detailed reference for all 75 tools
|
|
340
357
|
- [Resources Reference](docs/resources.md) — all 10 MCP resources
|
|
341
358
|
- [Prompts Reference](docs/prompts.md) — all 5 MCP prompts
|
|
342
359
|
- [Usage Examples](docs/examples.md) — real workflow examples
|
package/dist/client.d.ts
CHANGED
|
@@ -43,7 +43,9 @@ export declare class OpenCodeClient {
|
|
|
43
43
|
* Subscribe to SSE events. Returns an async iterable of parsed events.
|
|
44
44
|
* The caller should break out of the loop when done.
|
|
45
45
|
*/
|
|
46
|
-
subscribeSSE(path: string
|
|
46
|
+
subscribeSSE(path: string, opts?: {
|
|
47
|
+
signal?: AbortSignal;
|
|
48
|
+
}): AsyncGenerator<{
|
|
47
49
|
event: string;
|
|
48
50
|
data: string;
|
|
49
51
|
}, void, undefined>;
|
package/dist/client.js
CHANGED
|
@@ -149,7 +149,7 @@ export class OpenCodeClient {
|
|
|
149
149
|
* Subscribe to SSE events. Returns an async iterable of parsed events.
|
|
150
150
|
* The caller should break out of the loop when done.
|
|
151
151
|
*/
|
|
152
|
-
async *subscribeSSE(path) {
|
|
152
|
+
async *subscribeSSE(path, opts) {
|
|
153
153
|
const url = this.buildUrl(path);
|
|
154
154
|
const res = await fetch(url, {
|
|
155
155
|
method: "GET",
|
|
@@ -158,6 +158,7 @@ export class OpenCodeClient {
|
|
|
158
158
|
Accept: "text/event-stream",
|
|
159
159
|
"Cache-Control": "no-cache",
|
|
160
160
|
},
|
|
161
|
+
signal: opts?.signal,
|
|
161
162
|
});
|
|
162
163
|
if (!res.ok) {
|
|
163
164
|
const text = await res.text();
|
|
@@ -171,8 +172,27 @@ export class OpenCodeClient {
|
|
|
171
172
|
let buffer = "";
|
|
172
173
|
let currentEvent = "";
|
|
173
174
|
let currentData = "";
|
|
175
|
+
const abortHandler = () => {
|
|
176
|
+
try {
|
|
177
|
+
// Cancels any pending reader.read() and causes the generator to unwind.
|
|
178
|
+
void reader.cancel().catch(() => {
|
|
179
|
+
// ignore
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
// ignore
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
if (opts?.signal) {
|
|
187
|
+
if (opts.signal.aborted)
|
|
188
|
+
abortHandler();
|
|
189
|
+
else
|
|
190
|
+
opts.signal.addEventListener("abort", abortHandler, { once: true });
|
|
191
|
+
}
|
|
174
192
|
try {
|
|
175
193
|
while (true) {
|
|
194
|
+
if (opts?.signal?.aborted)
|
|
195
|
+
break;
|
|
176
196
|
const { done, value } = await reader.read();
|
|
177
197
|
if (done)
|
|
178
198
|
break;
|
|
@@ -197,6 +217,14 @@ export class OpenCodeClient {
|
|
|
197
217
|
}
|
|
198
218
|
}
|
|
199
219
|
finally {
|
|
220
|
+
if (opts?.signal) {
|
|
221
|
+
try {
|
|
222
|
+
opts.signal.removeEventListener("abort", abortHandler);
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
// ignore
|
|
226
|
+
}
|
|
227
|
+
}
|
|
200
228
|
reader.releaseLock();
|
|
201
229
|
}
|
|
202
230
|
}
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAQH,MAAM,OAAO,aAAc,SAAQ,KAAK;IAGpB;IACA;IACA;IACA;IALlB,YACE,OAAe,EACC,MAAc,EACd,MAAc,EACd,IAAY,EACZ,IAAY;QAE5B,KAAK,CAAC,OAAO,CAAC,CAAC;QALC,WAAM,GAAN,MAAM,CAAQ;QACd,WAAM,GAAN,MAAM,CAAQ;QACd,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAQ;QAG5B,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;IAED,IAAI,WAAW;QACb,OAAO,CACL,IAAI,CAAC,MAAM,KAAK,GAAG;YACnB,IAAI,CAAC,MAAM,KAAK,GAAG;YACnB,IAAI,CAAC,MAAM,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
8
8
|
import { z } from "zod";
|
|
9
|
+
/** Read-only tool: does not modify state. */
|
|
10
|
+
export declare const readOnly: {
|
|
11
|
+
readonly readOnlyHint: true;
|
|
12
|
+
readonly destructiveHint: false;
|
|
13
|
+
};
|
|
14
|
+
/** Destructive tool: permanently deletes data or shuts down services. */
|
|
15
|
+
export declare const destructive: {
|
|
16
|
+
readonly readOnlyHint: false;
|
|
17
|
+
readonly destructiveHint: true;
|
|
18
|
+
};
|
|
9
19
|
/**
|
|
10
20
|
* Shared Zod parameter for project directory targeting.
|
|
11
21
|
* When provided, sent as the x-opencode-directory header so the
|
|
@@ -20,6 +30,11 @@ export declare const directoryParam: z.ZodOptional<z.ZodString>;
|
|
|
20
30
|
export declare function formatMessageResponse(response: unknown): string;
|
|
21
31
|
/**
|
|
22
32
|
* Format a list of messages, extracting text content from each.
|
|
33
|
+
*
|
|
34
|
+
* When the assistant message has no text content (common with some providers
|
|
35
|
+
* that only emit tool calls), we show a concise summary of tool actions
|
|
36
|
+
* instead of blank output. Cost/token metadata from step-finish parts is
|
|
37
|
+
* appended when available.
|
|
23
38
|
*/
|
|
24
39
|
export declare function formatMessageList(messages: unknown[]): string;
|
|
25
40
|
/**
|
|
@@ -47,6 +62,36 @@ export declare function analyzeMessageResponse(response: unknown): {
|
|
|
47
62
|
hasError: boolean;
|
|
48
63
|
warning: string | null;
|
|
49
64
|
};
|
|
65
|
+
/**
|
|
66
|
+
* Redact values that look like API keys, tokens, or secrets.
|
|
67
|
+
* Replaces the value with the first 4 characters + "***REDACTED***".
|
|
68
|
+
* Works recursively on objects and arrays.
|
|
69
|
+
*
|
|
70
|
+
* Three layers of detection:
|
|
71
|
+
* 1. Key-name based: key names matching sensitive patterns (KEY, TOKEN, SECRET, etc.)
|
|
72
|
+
* 2. Value-based: string values matching known API key prefixes or long hex/base64 tokens
|
|
73
|
+
* 3. URL-based: query parameters in URL strings that contain secrets
|
|
74
|
+
*/
|
|
75
|
+
export declare function redactSecrets(value: unknown): unknown;
|
|
76
|
+
/**
|
|
77
|
+
* Determine whether a provider object from the OpenCode API is truly configured
|
|
78
|
+
* (i.e. has usable credentials), as opposed to being a built-in default.
|
|
79
|
+
*
|
|
80
|
+
* Detection layers:
|
|
81
|
+
* - source "env" / "config" / "api" → always configured
|
|
82
|
+
* - source "custom" with a non-empty apiKey → configured
|
|
83
|
+
* - source "custom" for "anthropic" with extra option keys (OAuth sets headers) → configured
|
|
84
|
+
* - Everything else → not configured
|
|
85
|
+
*/
|
|
86
|
+
export declare function isProviderConfigured(p: Record<string, unknown>): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Resolve a session status value from the OpenCode API.
|
|
89
|
+
*
|
|
90
|
+
* The API may return status as a plain string ("idle", "running") or as an
|
|
91
|
+
* object like `{ state: "running", ... }`. This helper normalises both forms
|
|
92
|
+
* into a human-readable string.
|
|
93
|
+
*/
|
|
94
|
+
export declare function resolveSessionStatus(raw: unknown): string;
|
|
50
95
|
/**
|
|
51
96
|
* Standard tool response builder.
|
|
52
97
|
*/
|