opencode-mcp 1.1.0 → 1.3.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 CHANGED
@@ -5,6 +5,38 @@ 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.3.0] - 2025-02-08
9
+
10
+ ### Added
11
+
12
+ - **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.
13
+ - Checks the `/global/health` endpoint on startup
14
+ - Finds the `opencode` binary via `which`/`where`
15
+ - Spawns `opencode serve --port <port>` and polls until healthy
16
+ - Graceful shutdown: kills the managed child process on SIGINT/SIGTERM/exit
17
+ - Clear error messages with install instructions if the binary is not found
18
+ - **`OPENCODE_AUTO_SERVE` env var** — set to `"false"` to disable auto-start for users who prefer manual control
19
+ - **`src/server-manager.ts` module** — new module with `findBinary()`, `isServerRunning()`, `startServer()`, `stopServer()`, `ensureServer()`
20
+ - **140 tests** (up from 117) — 23 new tests for the server manager covering health checks, binary detection, auto-start, error cases, and shutdown
21
+
22
+ ### Changed
23
+
24
+ - Startup flow in `src/index.ts` now calls `ensureServer()` before connecting the MCP transport
25
+ - Updated README: removed manual "start opencode serve" step, added auto-serve documentation, updated env vars table and architecture section
26
+
27
+ ## [1.2.0] - 2025-02-08
28
+
29
+ ### Added
30
+
31
+ - **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.
32
+ - **`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.
33
+ - **117 tests** (up from 102) — new tests for directory header propagation, `opencode_setup` handler, and `directoryParam` validation
34
+
35
+ ### Changed
36
+
37
+ - `opencode_find_file` tool: renamed the search-root override parameter from `directory` to `searchDirectory` to avoid collision with the new project-scoping `directory` parameter
38
+ - Auth tools (`opencode_auth_set`, `opencode_provider_oauth_authorize`, `opencode_provider_oauth_callback`) do not accept `directory` — auth credentials are global, not project-scoped
39
+
8
40
  ## [1.1.0] - 2025-02-08
9
41
 
10
42
  ### Added
package/README.md CHANGED
@@ -5,19 +5,16 @@
5
5
  [![node](https://img.shields.io/node/v/opencode-mcp)](https://nodejs.org/)
6
6
  [![npm downloads](https://img.shields.io/npm/dm/opencode-mcp)](https://www.npmjs.com/package/opencode-mcp)
7
7
 
8
- An [MCP](https://modelcontextprotocol.io/) server that gives any MCP-compatible client full access to a running [OpenCode](https://opencode.ai/) instance. Manage sessions, send prompts, search files, review diffs, configure providers, control the TUI, and more.
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
- **70 tools** | **10 resources** | **5 prompts**
10
+ **71 tools** | **10 resources** | **5 prompts** | **Multi-project support** | **Auto-start**
11
11
 
12
12
  ## Quick Start
13
13
 
14
- ### 1. Start an OpenCode server
14
+ Add to your MCP client and go. The server **automatically detects and starts** the OpenCode server if it's not already running — no manual `opencode serve` step needed.
15
15
 
16
- ```bash
17
- opencode serve
18
- ```
19
-
20
- ### 2. Add to your MCP client
16
+ > **Prerequisite:** [OpenCode](https://opencode.ai/) must be installed on your system.
17
+ > Install: `curl -fsSL https://opencode.ai/install | bash` or `npm i -g opencode-ai` or `brew install sst/tap/opencode`
21
18
 
22
19
  Pick your client below. No authentication is needed by default — just add the config and restart your client.
23
20
 
@@ -137,7 +134,7 @@ claude mcp add opencode -- npx -y opencode-mcp
137
134
  }
138
135
  ```
139
136
 
140
- That's it. Your MCP client now has access to the entire OpenCode API.
137
+ That's it. Your MCP client now has access to the entire OpenCode API. The MCP server will auto-start `opencode serve` if it's not already running.
141
138
 
142
139
  ### Custom server URL or authentication (optional)
143
140
 
@@ -161,6 +158,16 @@ If the OpenCode server is on a different host/port or has auth enabled, pass env
161
158
  }
162
159
  ```
163
160
 
161
+ To **disable** auto-start (if you prefer to manage the OpenCode server yourself):
162
+
163
+ ```json
164
+ {
165
+ "env": {
166
+ "OPENCODE_AUTO_SERVE": "false"
167
+ }
168
+ }
169
+ ```
170
+
164
171
  ## What Can It Do?
165
172
 
166
173
  ### Workflow Tools (start here)
@@ -169,6 +176,7 @@ High-level tools designed to be the easiest way for an LLM to interact with Open
169
176
 
170
177
  | Tool | What it does |
171
178
  |---|---|
179
+ | `opencode_setup` | Check server health, provider config, and project status — use as first step |
172
180
  | `opencode_ask` | Create session + send prompt + get answer in one call |
173
181
  | `opencode_reply` | Follow-up message in an existing session |
174
182
  | `opencode_conversation` | Formatted conversation history |
@@ -239,6 +247,7 @@ All environment variables are **optional**. You only need to set them if you've
239
247
  | `OPENCODE_BASE_URL` | URL of the OpenCode server | `http://127.0.0.1:4096` | No |
240
248
  | `OPENCODE_SERVER_USERNAME` | HTTP basic auth username | `opencode` | No |
241
249
  | `OPENCODE_SERVER_PASSWORD` | HTTP basic auth password | *(none — auth disabled)* | No |
250
+ | `OPENCODE_AUTO_SERVE` | Auto-start `opencode serve` if not running | `true` | No |
242
251
 
243
252
  > **Note:** Authentication is disabled by default. It only activates when `OPENCODE_SERVER_PASSWORD` is set on both the OpenCode server and the MCP server.
244
253
 
@@ -249,19 +258,57 @@ MCP Client <--stdio--> opencode-mcp <--HTTP--> OpenCode Server
249
258
  (Claude, Cursor, etc.) (this package) (opencode serve)
250
259
  ```
251
260
 
252
- The MCP server communicates over **stdio** using the Model Context Protocol. When a client invokes a tool, the server translates it into HTTP calls against the OpenCode headless API. The OpenCode server must be running separately (`opencode serve`).
261
+ The MCP server communicates over **stdio** using the Model Context Protocol. When a client invokes a tool, the server translates it into HTTP calls against the OpenCode headless API.
262
+
263
+ **Auto-start flow:** On startup, the MCP server checks if the OpenCode server is already running (via the `/global/health` endpoint). If not, it finds the `opencode` binary on your system and spawns `opencode serve` as a child process. The child is automatically cleaned up when the MCP server exits.
264
+
265
+ ## Working with Multiple Projects
266
+
267
+ Every tool accepts an optional `directory` parameter that targets a specific project directory. This lets you work on multiple projects from a single OpenCode server without restarting anything.
268
+
269
+ ```
270
+ # First-time setup: check server status and configure providers
271
+ opencode_setup()
272
+
273
+ # Set an API key (one-time, global — shared across all projects)
274
+ opencode_auth_set({ providerId: "anthropic", type: "api", key: "sk-ant-..." })
275
+
276
+ # Work on a mobile app
277
+ opencode_ask({
278
+ directory: "/home/user/projects/mobile-app",
279
+ prompt: "Set up navigation with React Navigation"
280
+ })
281
+
282
+ # Switch to a web app — same server, different directory
283
+ opencode_ask({
284
+ directory: "/home/user/projects/web-app",
285
+ prompt: "Add authentication to the Next.js app"
286
+ })
287
+
288
+ # Go back to the mobile app — no restart needed
289
+ opencode_reply({
290
+ directory: "/home/user/projects/mobile-app",
291
+ sessionId: "sess_abc123",
292
+ prompt: "Now add a login screen"
293
+ })
294
+ ```
295
+
296
+ When `directory` is omitted, the OpenCode server uses its own working directory (where `opencode serve` was started).
297
+
298
+ **How it works internally:** The `directory` parameter is sent as the `x-opencode-directory` HTTP header. The OpenCode server lazily initializes a separate instance per directory (with its own LSP, VCS, MCP servers, sessions, etc.) and caches them in memory.
253
299
 
254
300
  ## Architecture
255
301
 
256
302
  ```
257
303
  src/
258
304
  index.ts Entry point — wires everything together
305
+ server-manager.ts Auto-detect, find, and start OpenCode server
259
306
  client.ts HTTP client with retry, SSE, error categorization
260
307
  helpers.ts Smart response formatting for LLM-friendly output
261
308
  resources.ts MCP Resources (10 browseable data endpoints)
262
309
  prompts.ts MCP Prompts (5 guided workflow templates)
263
310
  tools/
264
- workflow.ts High-level workflow tools (7)
311
+ workflow.ts High-level workflow tools (8)
265
312
  session.ts Session management tools (18)
266
313
  message.ts Message/prompt tools (6)
267
314
  file.ts File and search tools (6)
@@ -289,7 +336,7 @@ npm run dev # watch mode
289
336
 
290
337
  - [Getting Started](docs/getting-started.md) — step-by-step setup guide
291
338
  - [Configuration](docs/configuration.md) — all env vars and MCP client configs
292
- - [Tools Reference](docs/tools.md) — detailed reference for all 70 tools
339
+ - [Tools Reference](docs/tools.md) — detailed reference for all 71 tools
293
340
  - [Resources Reference](docs/resources.md) — all 10 MCP resources
294
341
  - [Prompts Reference](docs/prompts.md) — all 5 MCP prompts
295
342
  - [Usage Examples](docs/examples.md) — real workflow examples
package/dist/client.d.ts CHANGED
@@ -31,13 +31,14 @@ export declare class OpenCodeClient {
31
31
  private buildUrl;
32
32
  private headers;
33
33
  private request;
34
- get<T = unknown>(path: string, query?: Record<string, string>): Promise<T>;
34
+ get<T = unknown>(path: string, query?: Record<string, string>, directory?: string): Promise<T>;
35
35
  post<T = unknown>(path: string, body?: unknown, opts?: {
36
36
  timeout?: number;
37
+ directory?: string;
37
38
  }): Promise<T>;
38
- patch<T = unknown>(path: string, body?: unknown): Promise<T>;
39
- put<T = unknown>(path: string, body?: unknown): Promise<T>;
40
- delete<T = unknown>(path: string, query?: Record<string, string>): Promise<T>;
39
+ patch<T = unknown>(path: string, body?: unknown, directory?: string): Promise<T>;
40
+ put<T = unknown>(path: string, body?: unknown, directory?: string): Promise<T>;
41
+ delete<T = unknown>(path: string, query?: Record<string, string>, directory?: string): Promise<T>;
41
42
  /**
42
43
  * Subscribe to SSE events. Returns an async iterable of parsed events.
43
44
  * The caller should break out of the loop when done.
package/dist/client.js CHANGED
@@ -62,7 +62,7 @@ export class OpenCodeClient {
62
62
  }
63
63
  return url.toString();
64
64
  }
65
- headers(accept) {
65
+ headers(accept, directory) {
66
66
  const h = {
67
67
  "Content-Type": "application/json",
68
68
  Accept: accept ?? "application/json",
@@ -70,6 +70,9 @@ export class OpenCodeClient {
70
70
  if (this.authHeader) {
71
71
  h["Authorization"] = this.authHeader;
72
72
  }
73
+ if (directory) {
74
+ h["x-opencode-directory"] = directory;
75
+ }
73
76
  return h;
74
77
  }
75
78
  async request(method, path, opts) {
@@ -87,7 +90,7 @@ export class OpenCodeClient {
87
90
  : undefined;
88
91
  const res = await fetch(url, {
89
92
  method,
90
- headers: this.headers(),
93
+ headers: this.headers(undefined, opts?.directory),
91
94
  body: opts?.body !== undefined ? JSON.stringify(opts.body) : undefined,
92
95
  signal: controller.signal,
93
96
  });
@@ -123,20 +126,24 @@ export class OpenCodeClient {
123
126
  }
124
127
  throw lastError ?? new Error(`${method} ${path} failed after retries`);
125
128
  }
126
- async get(path, query) {
127
- return this.request("GET", path, { query });
129
+ async get(path, query, directory) {
130
+ return this.request("GET", path, { query, directory });
128
131
  }
129
132
  async post(path, body, opts) {
130
- return this.request("POST", path, { body, timeout: opts?.timeout });
133
+ return this.request("POST", path, {
134
+ body,
135
+ timeout: opts?.timeout,
136
+ directory: opts?.directory,
137
+ });
131
138
  }
132
- async patch(path, body) {
133
- return this.request("PATCH", path, { body });
139
+ async patch(path, body, directory) {
140
+ return this.request("PATCH", path, { body, directory });
134
141
  }
135
- async put(path, body) {
136
- return this.request("PUT", path, { body });
142
+ async put(path, body, directory) {
143
+ return this.request("PUT", path, { body, directory });
137
144
  }
138
- async delete(path, query) {
139
- return this.request("DELETE", path, { query });
145
+ async delete(path, query, directory) {
146
+ return this.request("DELETE", path, { query, directory });
140
147
  }
141
148
  /**
142
149
  * Subscribe to SSE events. Returns an async iterable of parsed events.
@@ -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,CAA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AK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;gBAC5C,IAAI,IAAI;oBAAE,MAAM;gBAEhB,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;gBAClD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBACjC,MAAM,GAAG,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC;gBAE3B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;oBACzB,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;wBAC9B,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;oBACtC,CAAC;yBAAM,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;wBACpC,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;oBACrC,CAAC;yBAAM,IAAI,IAAI,KAAK,EAAE,EAAE,CAAC;wBACvB,IAAI,WAAW,EAAE,CAAC;4BAChB,MAAM,EAAE,KAAK,EAAE,YAAY,IAAI,SAAS,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;4BAC9D,YAAY,GAAG,EAAE,CAAC;4BAClB,WAAW,GAAG,EAAE,CAAC;wBACnB,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,MAAM,CAAC,WAAW,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;CACF"}
package/dist/helpers.d.ts CHANGED
@@ -5,6 +5,13 @@
5
5
  * meaningful content from OpenCode API responses so the LLM can reason
6
6
  * about them efficiently.
7
7
  */
8
+ import { z } from "zod";
9
+ /**
10
+ * Shared Zod parameter for project directory targeting.
11
+ * When provided, sent as the x-opencode-directory header so the
12
+ * OpenCode server scopes the request to that project.
13
+ */
14
+ export declare const directoryParam: z.ZodOptional<z.ZodString>;
8
15
  /**
9
16
  * Extract a human-readable summary from a message response.
10
17
  * Pulls text content from parts, summarizes tool calls, etc.
package/dist/helpers.js CHANGED
@@ -5,7 +5,19 @@
5
5
  * meaningful content from OpenCode API responses so the LLM can reason
6
6
  * about them efficiently.
7
7
  */
8
+ import { z } from "zod";
8
9
  /* eslint-disable @typescript-eslint/no-explicit-any */
10
+ /**
11
+ * Shared Zod parameter for project directory targeting.
12
+ * When provided, sent as the x-opencode-directory header so the
13
+ * OpenCode server scopes the request to that project.
14
+ */
15
+ export const directoryParam = z
16
+ .string()
17
+ .optional()
18
+ .describe("Absolute path to the project directory. " +
19
+ "When provided, the request targets that project. " +
20
+ "If omitted, the OpenCode server uses its own working directory.");
9
21
  /**
10
22
  * Extract a human-readable summary from a message response.
11
23
  * Pulls text content from parts, summarizes tool calls, etc.
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,uDAAuD;AAEvD;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,QAAiB;IACrD,MAAM,CAAC,GAAG,QAAe,CAAC;IAC1B,MAAM,QAAQ,GAAa,EAAE,CAAC;IAE9B,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC;QACZ,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC;QACvC,QAAQ,CAAC,IAAI,CACX,IAAI,IAAI,IAAI,SAAS,aAAa,EAAE,IAAI,GAAG,GAAG,SAAS,CAAC,CAAC,CAAC,OAAO,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CACpF,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,EAAE,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;QACvC,KAAK,MAA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covering the entire OpenCode API surface
11
+ * - 70+ tools covering the entire OpenCode API surface
12
12
  * - High-level workflow tools (opencode_ask, opencode_reply, etc.)
13
13
  * - Smart response formatting for LLM-friendly output
14
14
  * - MCP Resources for browseable project data
@@ -16,10 +16,12 @@
16
16
  * - SSE event polling
17
17
  * - TUI control tools
18
18
  * - Retry logic with exponential backoff
19
+ * - Auto-detection and auto-start of the OpenCode server
19
20
  *
20
21
  * Environment variables:
21
22
  * OPENCODE_BASE_URL - Base URL of the OpenCode server (default: http://127.0.0.1:4096)
22
23
  * OPENCODE_SERVER_USERNAME - Username for HTTP basic auth (default: opencode)
23
24
  * OPENCODE_SERVER_PASSWORD - Password for HTTP basic auth (optional)
25
+ * OPENCODE_AUTO_SERVE - Set to "false" to disable auto-start (default: true)
24
26
  */
25
27
  export {};
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@
8
8
  * providers, and more.
9
9
  *
10
10
  * Features:
11
- * - 60+ tools covering the entire OpenCode API surface
11
+ * - 70+ tools covering the entire OpenCode API surface
12
12
  * - High-level workflow tools (opencode_ask, opencode_reply, etc.)
13
13
  * - Smart response formatting for LLM-friendly output
14
14
  * - MCP Resources for browseable project data
@@ -16,15 +16,18 @@
16
16
  * - SSE event polling
17
17
  * - TUI control tools
18
18
  * - Retry logic with exponential backoff
19
+ * - Auto-detection and auto-start of the OpenCode server
19
20
  *
20
21
  * Environment variables:
21
22
  * OPENCODE_BASE_URL - Base URL of the OpenCode server (default: http://127.0.0.1:4096)
22
23
  * OPENCODE_SERVER_USERNAME - Username for HTTP basic auth (default: opencode)
23
24
  * OPENCODE_SERVER_PASSWORD - Password for HTTP basic auth (optional)
25
+ * OPENCODE_AUTO_SERVE - Set to "false" to disable auto-start (default: true)
24
26
  */
25
27
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
26
28
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
27
29
  import { OpenCodeClient } from "./client.js";
30
+ import { ensureServer } from "./server-manager.js";
28
31
  // Tool groups
29
32
  import { registerGlobalTools } from "./tools/global.js";
30
33
  import { registerConfigTools } from "./tools/config.js";
@@ -43,16 +46,19 @@ import { registerPrompts } from "./prompts.js";
43
46
  const baseUrl = process.env.OPENCODE_BASE_URL ?? "http://127.0.0.1:4096";
44
47
  const username = process.env.OPENCODE_SERVER_USERNAME;
45
48
  const password = process.env.OPENCODE_SERVER_PASSWORD;
49
+ const autoServe = process.env.OPENCODE_AUTO_SERVE !== "false";
46
50
  const client = new OpenCodeClient({ baseUrl, username, password });
47
51
  const server = new McpServer({
48
52
  name: "opencode-mcp",
49
- version: "1.1.0",
53
+ version: "1.3.0",
50
54
  description: "Full-featured MCP server wrapping the OpenCode AI headless HTTP server. " +
51
- "Provides 60+ tools, resources, and prompts to manage sessions, send " +
55
+ "Provides 70+ tools, resources, and prompts to manage sessions, send " +
52
56
  "prompts, search files, configure providers, control the TUI, monitor " +
53
57
  "events, and interact with the full OpenCode API. " +
54
- "Start with opencode_ask for one-shot questions, or opencode_context " +
55
- "to understand the current project.",
58
+ "All tools support a directory parameter for multi-project workflows. " +
59
+ "Auto-detects and starts the OpenCode server if not already running. " +
60
+ "Start with opencode_setup for onboarding, opencode_ask for one-shot " +
61
+ "questions, or opencode_context to understand the current project.",
56
62
  });
57
63
  // ── Low-level API tools ─────────────────────────────────────────────
58
64
  registerGlobalTools(server, client);
@@ -75,9 +81,20 @@ registerResources(server, client);
75
81
  registerPrompts(server);
76
82
  // ── Start ───────────────────────────────────────────────────────────
77
83
  async function main() {
84
+ // Step 1: Ensure OpenCode server is available (auto-start if needed).
85
+ try {
86
+ await ensureServer({ baseUrl, autoServe });
87
+ }
88
+ catch (err) {
89
+ // Log the error but don't prevent MCP from starting — tools will
90
+ // report connection errors individually, and the server may come
91
+ // up later.
92
+ console.error(`Warning: ${err instanceof Error ? err.message : String(err)}`);
93
+ }
94
+ // Step 2: Connect the MCP transport.
78
95
  const transport = new StdioServerTransport();
79
96
  await server.connect(transport);
80
- console.error(`opencode-mcp v1.0.2 started (connecting to OpenCode at ${baseUrl})`);
97
+ console.error(`opencode-mcp v1.3.0 started (OpenCode server at ${baseUrl})`);
81
98
  }
82
99
  main().catch((err) => {
83
100
  console.error("Fatal error starting opencode-mcp:", err);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,cAAc;AACd,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,wBAAwB;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,MAAM,OAAO,GACX,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,uBAAuB,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,MAAM,CAAC,CAAC;AAEtC,uEAAuE;AACvE,gBAAgB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEjC,uEAAuE;AACvE,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEnC,uEAAuE;AACvE,iBAAiB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAElC,uEAAuE;AACvE,eAAe,CAAC,MAAM,CAAC,CAAC;AAExB,uEAAuE;AACvE,KAAK,UAAU,IAAI;IACjB,sEAAsE;IACtE,IAAI,CAAC;QACH,MAAM,YAAY,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;IAC7C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,iEAAiE;QACjE,iEAAiE;QACjE,YAAY;QACZ,OAAO,CAAC,KAAK,CACX,YAAY,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAC/D,CAAC;IACJ,CAAC;IAED,qCAAqC;IACrC,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,OAAO,CAAC,KAAK,CACX,mDAAmD,OAAO,GAAG,CAC9D,CAAC;AACJ,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,GAAG,CAAC,CAAC;IACzD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Auto-detection and auto-start of the OpenCode headless server.
3
+ *
4
+ * This module handles:
5
+ * 1. Checking if `opencode serve` is already running (health check)
6
+ * 2. Finding the `opencode` binary on the system
7
+ * 3. Spawning `opencode serve` as a child process if needed
8
+ * 4. Graceful shutdown of the child process on exit
9
+ *
10
+ * Controlled via environment variables:
11
+ * OPENCODE_AUTO_SERVE - Set to "false" to disable auto-start (default: true)
12
+ * OPENCODE_BASE_URL - Base URL of the server (default: http://127.0.0.1:4096)
13
+ */
14
+ export interface ServerManagerOptions {
15
+ baseUrl: string;
16
+ /** Disable auto-start entirely. */
17
+ autoServe?: boolean;
18
+ /** Max time (ms) to wait for the server to become healthy after spawning. */
19
+ startupTimeoutMs?: number;
20
+ }
21
+ export interface ServerStatus {
22
+ running: boolean;
23
+ version?: string;
24
+ managedByUs: boolean;
25
+ }
26
+ /**
27
+ * Check if the OpenCode server is already running by hitting the health endpoint.
28
+ * Returns `{ healthy: true, version }` or `{ healthy: false }`.
29
+ */
30
+ export declare function isServerRunning(baseUrl: string): Promise<{
31
+ healthy: boolean;
32
+ version?: string;
33
+ }>;
34
+ /**
35
+ * Attempt to find the `opencode` binary on the system.
36
+ * Returns the full path or null if not found.
37
+ */
38
+ export declare function findBinary(): Promise<string | null>;
39
+ /**
40
+ * Get the installed OpenCode version. Returns null if not installed.
41
+ */
42
+ export declare function getInstalledVersion(binaryPath: string): Promise<string | null>;
43
+ /**
44
+ * Build installation instructions for when the binary is not found.
45
+ */
46
+ export declare function getInstallInstructions(): string;
47
+ /**
48
+ * Spawn `opencode serve` as a background child process.
49
+ * Waits until the health endpoint responds or the timeout elapses.
50
+ *
51
+ * @throws Error if the binary is not found or the server fails to start.
52
+ */
53
+ export declare function startServer(binaryPath: string, baseUrl: string, timeoutMs?: number): Promise<{
54
+ version?: string;
55
+ }>;
56
+ /**
57
+ * Stop the managed child process (if we started one).
58
+ */
59
+ export declare function stopServer(): void;
60
+ /**
61
+ * Main entry point: ensure the OpenCode server is available.
62
+ *
63
+ * Returns a status object describing the result.
64
+ * Logs progress to stderr (MCP servers use stdout for the transport).
65
+ *
66
+ * @throws Error if the server cannot be reached and auto-start fails.
67
+ */
68
+ export declare function ensureServer(opts: ServerManagerOptions): Promise<ServerStatus>;