Skip to content

Improve MCP client connection resilience with Promise.allSettled#374

Merged
threepointone merged 6 commits intocloudflare:mainfrom
laulauland:laulauland/failed-mcp-initialization-capabilities
Jul 31, 2025
Merged

Improve MCP client connection resilience with Promise.allSettled#374
threepointone merged 6 commits intocloudflare:mainfrom
laulauland:laulauland/failed-mcp-initialization-capabilities

Conversation

@laulauland
Copy link
Copy Markdown
Contributor

@laulauland laulauland commented Jul 21, 2025

Small change kinda addressing #320

Instead of failing the connection this would provide a fallback and log the error that registering a capability failed.

Another alternative would be:

  • try..catch on the Promise.all
  • mark the this.connectionState = failed and exit the function

Changes:

  • Replace Promise.all with Promise.allSettled in MCP client initialization to handle partial capability failures gracefully
  • Log failed capabilities instead of throwing errors that break entire connections

Replace Promise.all with Promise.allSettled in MCPClientConnection.init() to handle partial capability failures gracefully. This prevents entire connection failures when individual MCP server capabilities are unavailable.

Changes:
- Use Promise.allSettled for capability discovery operations
- Log failed capabilities with console.error instead of throwing
- Set fallback values for failed capabilities (empty arrays/undefined)
- Maintain connection ready state even with partial failures

🤖 Generated with [opencode](https://opencode.ai)

Co-Authored-By: opencode <noreply@opencode.ai>
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Jul 21, 2025

🦋 Changeset detected

Latest commit: dc1c450

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

This PR includes changesets to release 2 packages
Name Type
agents Patch
hono-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

@whoiskatrin
Copy link
Copy Markdown
Contributor

@laulauland can you please take a look at failed build? could we add some tests for this?
can i also ask you to add a changeset? thanks a ton!

laulauland and others added 3 commits July 24, 2025 00:14
…mentation

Resolve type inference issues by destructuring Promise.allSettled results directly instead of using a mixed-type operations array. This allows TypeScript to properly infer the individual result types.

🤖 Generated with [opencode](https://opencode.ai)

Co-Authored-By: opencode <noreply@opencode.ai>
@laulauland
Copy link
Copy Markdown
Contributor Author

Thanks @threepointone for the changeset! I pushed a little test for the client connection as well.

Copy link
Copy Markdown
Contributor

@threepointone threepointone left a comment

Choose a reason for hiding this comment

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

Looks good now, thanks so much for the PR! landing

@threepointone threepointone merged commit b63b4a6 into cloudflare:main Jul 31, 2025
1 check passed
@threepointone threepointone mentioned this pull request Jul 30, 2025
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.

3 participants