feat(mcp): append-drift mid-session reconnect (refs #110)#117
Merged
Conversation
Stage E2 of the C2b follow-ups: when /mcp reconnect finds the server added new tools at the END of its tool list, register them mid-session and addTool the prefix instead of refusing. Drift kinds the reconnect now accepts: - identity → free swap, ~95% cache hit (was already shipped in #115) - append → register new tools, ~95% cache hit (the new chunks land in cache too, per benchmarks/spike-mcp-reconnect data) - edit / reorder / remove → still refused with "restart Reasonix" Touch: - src/mcp/registry.ts — extract `registerSingleMcpTool(mcpTool, env)` + new `BridgeEnv` type (resolved bridge environment captured at first-bridge time). bridgeMcpTools' return shape gains `env` so reconnect can re-use the same options. - src/cli/ui/slash/types.ts — McpServerSummary gains `bridgeEnv: BridgeEnv` so the append handler has everything it needs to register a new tool without redoing the whole bridge. - src/cli/commands/chat.tsx — captures bridge.env onto the summary. - src/mcp/reconnect.ts — accepts identity (always) plus append (if caller passes accept: ["identity", "append"]). On append, returns addedTools so the caller can register them. Identity is forced- accepted regardless of `accept` because it's free. - src/cli/ui/mcp-append.ts (new) — `applyMcpAppend(loop, target, addedTools)` calls registerSingleMcpTool + prefix.addTool + refreshes target.report. Accepted-tools-only counting handles the unnamed-tool defensive case. - src/cli/ui/mcp-reconnect-kickoff.ts — gains optional `applyAppend` callback. When set, opts the reconnect into ["identity", "append"]; when missing, behaviour is unchanged from #115. - src/cli/ui/slash/handlers/mcp.ts + src/cli/ui/McpBrowser.tsx + src/cli/ui/App.tsx — both surfaces wire applyMcpAppend through. - tests/mcp-append.test.ts (new) — 4 cases: registry registration, fingerprint invalidation, summary refresh, defensive skip on unnamed tools. Closes most of #110. Edit / reorder / remove mid-session remain as follow-up issues — each requires new ImmutablePrefix API (replaceTool / removeTool) + cache-reset announcement.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #110.
What
/mcp reconnect <name>(andrin browser) now accept append-drift mid-session — when the reconnected server has new tools at the end of its list, register them in the registry andaddToolthe prefix instead of refusing.Drift kinds the reconnect handles:
Touch
Registry refactor:
src/mcp/registry.ts— extractedregisterSingleMcpTool(mcpTool, env)+ newBridgeEnvtype (resolved bridge environment captured at first-bridge time).bridgeMcpToolsreturn shape gainsenv.State plumbing:
src/cli/ui/slash/types.ts—McpServerSummarygainsbridgeEnv: BridgeEnv.src/cli/commands/chat.tsx— capturesbridge.envon the summary.Reconnect surface:
src/mcp/reconnect.ts— accepts identity (always) + append (opt-in viaaccept: ["identity", "append"]). On append, returnsaddedTools.src/cli/ui/mcp-append.ts(new) —applyMcpAppend(loop, target, addedTools)does the prefix + registry + summary mutations.src/cli/ui/mcp-reconnect-kickoff.ts— gains optionalapplyAppendcallback. When set, opts into the append flow; when missing, behaviour is unchanged from feat(mcp): /mcp reconnect <name> for identity drift (closes part of #110) #115.src/cli/ui/slash/handlers/mcp.ts+src/cli/ui/McpBrowser.tsx+src/cli/ui/App.tsx— both surfaces wireapplyMcpAppendthrough.Tests:
tests/mcp-append.test.ts— 4 cases (registry registration, fingerprint invalidation, summary refresh, defensive skip on unnamed tools).What's still in #110
Edit / reorder / remove mid-session — each needs new
ImmutablePrefixAPI (replaceTool/removeTool) plus a cache-reset announcement card. Edge cases that the spike showed are catastrophic for cache anyway, so refusing them with a clear "restart" message is the right default for now. Will file follow-up issues if real demand surfaces.Test plan
npm run verifypasses (1782 tests, +4 new)applyMcpAppendmutates loop.tools + loop.prefix + summary.report correctly/mcp reconnect <name>, confirm the new tool shows up in/mcpbrowser without a Reasonix restart