Skip to content

Commit 36b1800

Browse files
committed
fix(plugin): declare the MCP server in plugin.json instead of a root .mcp.json
A root .mcp.json doubles as this repo's project-scope MCP config, where CLAUDE_PLUGIN_ROOT is unset (claude doctor: Missing environment variables).
1 parent 1cdf07c commit 36b1800

7 files changed

Lines changed: 33 additions & 26 deletions

File tree

‎.claude-plugin/plugin.json‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
"repository": "https://github.com/lehcode/claude-opencode-delegate",
1111
"license": "MIT",
1212
"hooks": "./plugin-hooks/hooks.json",
13+
"mcpServers": {
14+
"opencode": {
15+
"command": "bun",
16+
"args": [
17+
"${CLAUDE_PLUGIN_ROOT}/dist/index.js"
18+
]
19+
}
20+
},
1321
"keywords": [
1422
"opencode",
1523
"delegate",

‎.mcp.json‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Configure after clone: `git config core.hooksPath hooks/`
2525

2626
## Architecture
2727

28-
Claude Code plugin with a bundled MCP server (`.mcp.json` → `dist/index.js`, built from `src/index.ts` with `bun run build`; commit the bundle, CI checks it is current). Core modules:
28+
Claude Code plugin with a bundled MCP server (`.claude-plugin/plugin.json` `mcpServers` → `dist/index.js`, built from `src/index.ts` with `bun run build`; commit the bundle, CI checks it is current). Core modules:
2929

3030
| File | Role |
3131
| ------------- | --------------------------------------------------------------------------------------------------------------------------- |

‎CLAUDE.md‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ Bun runs `.ts` directly. Nothing is compiled or bundled (`tsconfig` sets `noEmit
1515

1616
The plugin's runtime behaviour lives in the markdown files below plus the bundled MCP server:
1717

18-
| Surface | File | Role |
19-
| --------- | --------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
20-
| Skill | `skills/opencode-delegate/SKILL.md` | Model picking, brief template, review-after-return rules |
21-
| Agent | `agents/opencode-worker.md` | Thin forwarder: one `opencode run` (write: `build --auto`; read: `plan`), report |
22-
| Command | `commands/opencode.md` | `/opencode <model> -- <task>`: splits on `--`, spawns `opencode-worker` |
23-
| Hook | `scripts/route-to-opencode.sh`, `plugin-hooks/hooks.json` | PreToolUse `Agent\|Task`: rewrites only built-in subagent calls (general-purpose, claude, Explore, Plan, claude-code-guide, statusline-setup) to `opencode-worker` on Haiku (Explore/Plan/claude-code-guide forced read-only); custom, plugin, reviewer and SDD agents never routed; pass-through guards: `OPENCODE_DELEGATE_ROUTE=off`, missing opencode, `[no-opencode]`, no `jq` |
24-
| MCP | `.mcp.json`, `src/index.ts`, `dist/index.js` | `opencode` MCP server (stdio, `bun ${CLAUDE_PLUGIN_ROOT}/dist/index.js`) exposing `delegate`, `delegate_async`, `task_result`, `task_list`, `task_cancel`, `list_models`, `list_sessions` to the main thread; its `instructions` (always in the system prompt) make delegation the default for implementation |
25-
| Manifests | `.claude-plugin/plugin.json`, `marketplace.json` | Plugin identity; `plugin.json` carries homepage/repository shown by Claude Code |
18+
| Surface | File | Role |
19+
| --------- | ----------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
20+
| Skill | `skills/opencode-delegate/SKILL.md` | Model picking, brief template, review-after-return rules |
21+
| Agent | `agents/opencode-worker.md` | Thin forwarder: one `opencode run` (write: `build --auto`; read: `plan`), report |
22+
| Command | `commands/opencode.md` | `/opencode <model> -- <task>`: splits on `--`, spawns `opencode-worker` |
23+
| Hook | `scripts/route-to-opencode.sh`, `plugin-hooks/hooks.json` | PreToolUse `Agent\|Task`: rewrites only built-in subagent calls (general-purpose, claude, Explore, Plan, claude-code-guide, statusline-setup) to `opencode-worker` on Haiku (Explore/Plan/claude-code-guide forced read-only); custom, plugin, reviewer and SDD agents never routed; pass-through guards: `OPENCODE_DELEGATE_ROUTE=off`, missing opencode, `[no-opencode]`, no `jq` |
24+
| MCP | `plugin.json` `mcpServers`, `src/index.ts`, `dist/index.js` | `opencode` MCP server (stdio, `bun ${CLAUDE_PLUGIN_ROOT}/dist/index.js`) exposing `delegate`, `delegate_async`, `task_result`, `task_list`, `task_cancel`, `list_models`, `list_sessions` to the main thread; its `instructions` (always in the system prompt) make delegation the default for implementation |
25+
| Manifests | `.claude-plugin/plugin.json`, `marketplace.json` | Plugin identity; `plugin.json` carries homepage/repository shown by Claude Code |
2626

2727
`src/` backs the MCP server (`src/index.ts`). The installed plugin cache has no `node_modules`, so what runs is the committed bundle `dist/index.js`: changing `src/` changes plugin behaviour only after `bun run build`, and CI fails if `dist/` is stale. Its exports (`delegate`, `resolveModel`, `buildArgs`, `EventCollector`) are also the reference for how `opencode run` must be invoked and how its JSON stream is parsed; `opencode-worker` shells out to `opencode run` itself, so keep its command consistent with `buildArgs`.
2828

‎README.md‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ claude ▸ reads git diff, runs tests, reports which model did what and a verdic
1111

1212
## What ships
1313

14-
| Surface | File | Role |
15-
| ------- | ----------------------------------- | -------------------------------------------------------------------------------------------------- |
16-
| Skill | `skills/opencode-delegate/SKILL.md` | Model picking, brief template, review-after-return rules |
17-
| Agent | `agents/opencode-worker.md` | Thin forwarder (`tools: Bash`, `model: haiku`): one `opencode run` |
18-
| Command | `commands/opencode.md` | `/opencode <model> -- <task>`: splits on `--`, spawns `opencode-worker` |
19-
| Hook | `scripts/route-to-opencode.sh` | PreToolUse hook (`plugin-hooks/hooks.json`): reroutes built-in subagent calls to `opencode-worker` |
20-
| MCP | `.mcp.json`, `dist/index.js` | `opencode` MCP server (bundled from `src/index.ts`): `delegate` and friends as main-thread tools |
14+
| Surface | File | Role |
15+
| ------- | ------------------------------------------- | -------------------------------------------------------------------------------------------------- |
16+
| Skill | `skills/opencode-delegate/SKILL.md` | Model picking, brief template, review-after-return rules |
17+
| Agent | `agents/opencode-worker.md` | Thin forwarder (`tools: Bash`, `model: haiku`): one `opencode run` |
18+
| Command | `commands/opencode.md` | `/opencode <model> -- <task>`: splits on `--`, spawns `opencode-worker` |
19+
| Hook | `scripts/route-to-opencode.sh` | PreToolUse hook (`plugin-hooks/hooks.json`): reroutes built-in subagent calls to `opencode-worker` |
20+
| MCP | `plugin.json` `mcpServers`, `dist/index.js` | `opencode` MCP server (bundled from `src/index.ts`): `delegate` and friends as main-thread tools |
2121

2222
The MCP server exposes seven tools: `delegate` (run and wait), `delegate_async` (background run, returns a task id), `task_result`, `task_list`, `task_cancel`, `list_models` and `list_sessions`. Claude can call `delegate` directly for implementation work without launching an agent. `dist/index.js` is a committed bundle (the installed plugin cache has no `node_modules`); rebuild it with `bun run build` after changing `src/`, CI fails if it is stale. Claude Desktop is not supported.
2323

‎package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
".claude-plugin",
3434
"scripts",
3535
"plugin-hooks",
36-
".mcp.json",
3736
"README.md",
3837
"LICENSE"
3938
],

‎test/package.test.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ describe("npm package", () => {
1717
const files: string[] = (report as { files: { path: string }[] }).files.map((f) => f.path);
1818
for (const f of [
1919
"dist/index.js",
20-
".mcp.json",
2120
".claude-plugin/plugin.json",
2221
".claude-plugin/marketplace.json",
2322
"agents/opencode-worker.md",
@@ -45,6 +44,15 @@ describe("npm package", () => {
4544
expect(readFileSync(p, "utf8").startsWith("#!/usr/bin/env bun\n")).toBe(true);
4645
});
4746

47+
// A root .mcp.json doubles as this repo's project MCP config, where ${CLAUDE_PLUGIN_ROOT} is unset
48+
// (`claude doctor`: "Missing environment variables: CLAUDE_PLUGIN_ROOT"). Declare it in plugin.json.
49+
test("the MCP server is declared inline in plugin.json, not in a root .mcp.json", () => {
50+
expect(() => accessSync(join(root, ".mcp.json"))).toThrow();
51+
expect(readJson(".claude-plugin/plugin.json").mcpServers).toEqual({
52+
opencode: { command: "bun", args: ["${CLAUDE_PLUGIN_ROOT}/dist/index.js"] },
53+
});
54+
});
55+
4856
test("versions are in sync across manifests", () => {
4957
const v = readJson("package.json").version;
5058
expect(readJson(".claude-plugin/plugin.json").version).toBe(v);

0 commit comments

Comments
 (0)