fix/serve: one list_changed per source on reload and log dropped notifications #84

Merged
pti merged 1 commit from fix/reload-batched-list-changed into main 2026-10-19 21:37:41 +02:00
Owner

Refs #53. A policy reload used to call DeleteTools and then one AddTool per CLI tool, so mcp-go broadcast one tools/list_changed per tool plus one, and a session queue of 100 could fill up across two reloads close together. mcp-go drops the overflow silently unless an OnError hook exists, and wraptool had none. Each source is now re-registered with one batched AddTools call first, then DeleteTools only for the names that went away, so an approval reload sends exactly one notification, a reload that removed tools sends two, and tools never vanish from tools/list during the swap. A CLI listing error on reload fails closed and removes the CLI tools, since the swapped policy and the old handlers' tool config must not mix. New cmd/notifyhooks.go registers an OnError hook that logs a dropped notification with the session id and method. One log line per touched source reports registered and removed counts. Tests count notifications through a fake client session for add, remove, unchanged, reregister, fail-closed and the drop hook, and a reviewer pass with mutation checks is done. Docs updated in CLAUDE.md, docs/hot-reload.qmd, design/mcp-server-wrapping.md and the CHANGELOG. The issue stays open until a few approvals in a row reach a live Claude Code session without a reconnect. 🤖 Generated with Claude Code

Refs #53. A policy reload used to call DeleteTools and then one AddTool per CLI tool, so mcp-go broadcast one tools/list_changed per tool plus one, and a session queue of 100 could fill up across two reloads close together. mcp-go drops the overflow silently unless an OnError hook exists, and wraptool had none. Each source is now re-registered with one batched AddTools call first, then DeleteTools only for the names that went away, so an approval reload sends exactly one notification, a reload that removed tools sends two, and tools never vanish from tools/list during the swap. A CLI listing error on reload fails closed and removes the CLI tools, since the swapped policy and the old handlers' tool config must not mix. New cmd/notifyhooks.go registers an OnError hook that logs a dropped notification with the session id and method. One log line per touched source reports registered and removed counts. Tests count notifications through a fake client session for add, remove, unchanged, reregister, fail-closed and the drop hook, and a reviewer pass with mutation checks is done. Docs updated in CLAUDE.md, docs/hot-reload.qmd, design/mcp-server-wrapping.md and the CHANGELOG. The issue stays open until a few approvals in a row reach a live Claude Code session without a reconnect. 🤖 Generated with Claude Code
fix(serve): one list_changed per source on reload and log dropped notifications
All checks were successful
Lint / lint (pull_request) Successful in 1m3s
Lint / sonarqube (pull_request) Has been skipped
44c786077f
A reload deleted a source's tools and re-added them one AddTool at a time,
so mcp-go broadcast 1 + N tools/list_changed notifications. A client queue
that filled up made mcp-go drop the last one, reported only through an
OnError hook wraptool never registered, so Claude Code could miss the final
update. Between the delete and the last add, tools/list also saw a partial
list.

Each source is now re-registered with one batched AddTools (same-named
entries are overwritten in place), after which only the names that went
away are deleted, so an addition-only change sends exactly one
notification and no tool ever disappears. A CLI listing error on reload
keeps the previous registrations, matching reregister. Reload logs the
registered and removed counts per source, and a new OnError hook logs
notifications mcp-go drops, with the session id.

Refs #53.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
pti merged commit 94f35c5104 into main 2026-10-19 21:37:41 +02:00
pti deleted branch fix/reload-batched-list-changed 2026-10-19 21:37:41 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
pti/wraptool!84
No description provided.