Skip to content

fix(mcp): harden connection recovery#1924

Merged
mattzcarey merged 1 commit into
mainfrom
fix/mcp-reconnect-hardening
Jul 22, 2026
Merged

fix(mcp): harden connection recovery#1924
mattzcarey merged 1 commit into
mainfrom
fix/mcp-reconnect-hardening

Conversation

@mattzcarey

@mattzcarey mattzcarey commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Harden three supported MCP connection-recovery paths:

  • apply persisted retry budgets when connectToServer() reports { state: "failed" } instead of throwing;
  • finish in-flight restore/discovery work before migrating an auto-generated server id to a caller-supplied stable id;
  • close a connection replaced through the legacy connect() path and clear its terminated persisted session id.

Why this is needed

tryN() only retries thrown errors, while MCP connection failures normally resolve as a failed result. Documented retry options therefore stopped after one attempt. Stable-id migration could also rename a connection while restore still addressed the old id, orphaning discovery. Finally, the internally-used legacy reconnect path dropped replaced transports without closing them.

The minimized regression tests still fail on current main for all three symptoms and pass with this branch.

Validation

  • pnpm --filter agents exec vitest run src/tests/mcp — 30 files, 553 tests passed
  • focused package lint and both Agents TypeScript projects passed
  • build, exports, formatting, and repo lint passed
  • repo-wide typecheck remains blocked by unchanged main voice errors in examples/voice-agent and voice-providers/assemblyai

Includes a patch changeset for agents.

@changeset-bot

changeset-bot Bot commented Jul 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 94d0911

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
agents Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

@pkg-pr-new

pkg-pr-new Bot commented Jul 10, 2026

Copy link
Copy Markdown

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@1924

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@1924

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@1924

create-think

npm i https://pkg.pr.new/create-think@1924

hono-agents

npm i https://pkg.pr.new/hono-agents@1924

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@1924

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@1924

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@1924

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@1924

commit: 94d0911

Honor retry budgets when connectToServer returns a failed result, drain old-id connection work before stable-id migration, and close connections replaced by the legacy connect path.
@mattzcarey
mattzcarey force-pushed the fix/mcp-reconnect-hardening branch from f1ac7be to 94d0911 Compare July 22, 2026 10:34
@mattzcarey
mattzcarey merged commit c19d58a into main Jul 22, 2026
7 checks passed
@mattzcarey
mattzcarey deleted the fix/mcp-reconnect-hardening branch July 22, 2026 14:52
@github-actions github-actions Bot mentioned this pull request Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant