Skip to content

Commit c925afb

Browse files
JohanYPclaude
andcommitted
fix(cli): restart opencode automatically when src/mcp/ changes
OpenCode caches the MCP tool list at connect time. When the bot adds or modifies tools (anything under src/mcp/), the bot rebuild updates the server but OpenCode keeps serving the stale list — new tools don't show up in /mcps until something kicks the connection. The --update flow now detects diffs in src/mcp/ and runs \`docker compose restart opencode\` after the bot rebuild. ~2s extra, no full rebuild of opencode (its image is unchanged), and the next prompt sees the fresh tool list. Skipped when rebuild_opencode is already true (a full rebuild includes the restart anyway). CLI doc updated to mention the new behavior. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 38bf378 commit c925afb

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

bin/opencode-assistant

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ cmd_update() {
202202
changed_files=$(git -C "$REPO_DIR" diff --name-only HEAD..origin/main)
203203

204204
local rebuild_bot=false rebuild_opencode=false rebuild_workspace=false
205+
local restart_opencode=false
205206
if echo "$changed_files" | grep -qE '^(src/|package(-lock)?\.json|tsconfig\.json|Dockerfile$|docker-compose\.yml$)'; then
206207
rebuild_bot=true
207208
fi
@@ -213,6 +214,15 @@ cmd_update() {
213214
rebuild_workspace=true
214215
fi
215216

217+
# The MCP server lives inside the bot container — when its tools list
218+
# changes (src/mcp/*), the bot rebuild updates the server but OpenCode
219+
# caches the old tool list at connect time and won't see new tools
220+
# until it reconnects. Force a restart to drop the cached list.
221+
# Skip when rebuild_opencode is already true (a full rebuild includes restart).
222+
if echo "$changed_files" | grep -qE '^src/mcp/' && ! $rebuild_opencode; then
223+
restart_opencode=true
224+
fi
225+
216226
# 4. Resumen
217227
echo ""
218228
echo "Changed files:"
@@ -232,6 +242,9 @@ cmd_update() {
232242
else
233243
info "Will rebuild: ${BOLD}${rebuilds[*]}${NC}"
234244
fi
245+
if $restart_opencode; then
246+
info "Will restart opencode to pick up new MCP tools"
247+
fi
235248

236249
# 5. Pull
237250
info "Pulling..."
@@ -253,6 +266,10 @@ cmd_update() {
253266
info "Rebuilding workspace-mcp..."
254267
dc_workspace up -d --build
255268
fi
269+
if $restart_opencode; then
270+
info "Restarting opencode (MCP tool list refresh)..."
271+
dc restart opencode
272+
fi
256273

257274
# 7. Healthcheck post-update
258275
echo ""

docs/CLI_USAGE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ What it does, in order:
3434
- Changed `src/`, `package*.json`, `tsconfig.json`, `Dockerfile`, or `docker-compose.yml` → rebuild **bot**.
3535
- Changed `Dockerfile.opencode` or `docker/opencode-entrypoint.sh` → rebuild **opencode**.
3636
- Changed `Dockerfile.workspace-mcp` (if you have the side-car) → rebuild **workspace-mcp**.
37+
- Changed `src/mcp/` (new MCP tools added) → restart **opencode** (no rebuild) so it re-fetches the tool list.
3738
- Anything else (docs, README, GitHub Actions) → no rebuild needed.
3839
4. `git pull --ff-only`.
3940
5. Rebuilds only the services that need it (`docker compose up -d --build <service>` for each).

0 commit comments

Comments
 (0)