Skip to content

Commit 66b6e5d

Browse files
author
exe.dev user
committed
feat(core): keep MCP tools and reconnect after a dropped connection
Behind the mcp_resilience flag. A server whose connection drops on its own (process exit, closed transport, expired session) keeps offering its last tools and reconnects at once, then with backoff from 1 s up to 30 s, until it connects, needs authorization, or the user acts on it. Each server's last tool list is cached on disk, keyed by a hash of its connection identity, and offered while it starts.
1 parent da8c021 commit 66b6e5d

6 files changed

Lines changed: 562 additions & 10 deletions

File tree

‎packages/client/src/promise/generated/types.ts‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/core/src/mcp/connection.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ export interface Events {
3232
readonly settled: Effect.Effect<void>
3333
/** The live connection closed on its own. Runs under the lock; the owner decides how to stop. */
3434
readonly closed: (reason: string) => Effect.Effect<void>
35+
/**
36+
* The server no longer knows this connection's session. Runs under the lock. Resolves true when the owner took over
37+
* reconnecting; otherwise the connection stops and starts again in place.
38+
*/
39+
readonly expired?: Effect.Effect<boolean>
3540
/** A catalog changed: the server said so, or the connection was torn down and every catalog emptied. */
3641
readonly changed: (kind: Kind) => Effect.Effect<void>
3742
/**
@@ -132,6 +137,7 @@ export function make(input: Input): Connection {
132137
Effect.gen(function* () {
133138
if (state.client !== client) return
134139
yield* Effect.logInfo("mcp session expired, reconnecting", { server: input.name })
140+
if (input.events.expired && (yield* input.events.expired)) return
135141
yield* stop
136142
yield* start
137143
}).pipe(input.lock)

0 commit comments

Comments
 (0)