Skip to content

Conversation

@mattzcarey
Copy link
Contributor

@mattzcarey mattzcarey commented Nov 21, 2025

also fail fast with promise.all

Deployed to: https://workers-ai-playground.mattzcarey.workers.dev/

@changeset-bot
Copy link

changeset-bot bot commented Nov 21, 2025

🦋 Changeset detected

Latest commit: d6c1796

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 21, 2025

Open in StackBlitz

npm i https://pkg.pr.new/cloudflare/agents@672

commit: d6c1796

@claude
Copy link

claude bot commented Nov 21, 2025

Claude Code Review

Issues Found:

  1. Race condition in discoverAndRegister() (client-connection.ts:306-382): Uses Promise.all() which fails fast on first error, but the parallel operations may still complete after the function returns failure. This could leave partial state (e.g., tools registered but resources failed). Consider using Promise.allSettled() if you want to collect partial results, or document that this is intentional fail-fast behavior.

  2. Missing error message in init() failure path (client-connection.ts:177): When res.state === MCPConnectionState.FAILED but res.error is undefined, the code returns undefined instead of an error message. Add a fallback: return errorMessage || "Connection failed with unknown error".

  3. Timeout cleanup not guaranteed (client-connection.ts:272-283): If abortPromise rejects before timeoutPromise, the timeout may not be cleared. Move clearTimeout to a finally block or ensure it runs in all error paths.

  4. Type inconsistency in tryConnect (client-connection.ts:614-661): Returns MCPClientConnectionResult with state: MCPConnectionState.FAILED on the final fallthrough, but this should be impossible if transports array is non-empty. Consider throwing an error instead or adding a comment explaining why this is defensive programming.

  5. Redundant capability checks (client-connection.ts:489, 506, 525): registerTools(), registerPrompts(), and registerResources() are only called when serverCapabilities.tools/prompts/resources exist (checked in discoverAndRegister), but they re-check with optional chaining. Remove the redundant checks since they create dead code paths.

Testing: Comprehensive test coverage for the connection lifecycle, OAuth flows, discovery timeout/cancellation, and edge cases. Good focus on state machine transitions.

The PR successfully addresses the discovery hanging issue and crash-looping DO problem. The separation of init/discover is architecturally sound.

agents-git-bot bot pushed a commit to cloudflare/cloudflare-docs that referenced this pull request Nov 21, 2025
Synchronizes documentation with cloudflare/agents PR #672 which introduces
enum-based connection state management.

Changes:
- Document new MCPConnectionState enum export with usage examples
- Update getMcpServers() return type to use MCPConnectionState enum
- Add examples showing type-safe state checking with enum constants
- Document fail-fast behavior during capability discovery

Related PR: cloudflare/agents#672

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
agents-git-bot bot pushed a commit to cloudflare/cloudflare-docs that referenced this pull request Nov 21, 2025
This documentation sync corresponds to PR #672 in cloudflare/agents:
cloudflare/agents#672

Changes:
- Document new MCPConnectionState enum for type-safe connection states
- Update all code examples to use enum constants instead of string literals
- Add migration guide for transitioning from string literals
- Document improved error handling with fail-fast behavior
- Create changelog entry for the release
- Update OAuth flow documentation with enum usage

The MCPConnectionState enum provides better type safety when working with
MCP server connection states (AUTHENTICATING, CONNECTING, DISCOVERING,
READY, FAILED).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@mattzcarey mattzcarey marked this pull request as draft November 23, 2025 13:27
@mattzcarey
Copy link
Contributor Author

needs changeset.

@mattzcarey mattzcarey marked this pull request as ready for review November 24, 2025 13:58
@mattzcarey mattzcarey changed the title feat: enums connection state feat: enums connection state and standardise tool discovery Nov 24, 2025
agents-git-bot bot pushed a commit to cloudflare/cloudflare-docs that referenced this pull request Nov 24, 2025
Updates documentation for PR #672 (feat: enums connection state)

## Changes

- Added new "connected" state to MCPConnectionState enum
- Documented new discoverIfConnected() method for manual capability discovery
- Updated connection state machine documentation with detailed descriptions
- Added note about discovery failures now throwing errors immediately
- Updated getMcpServers() return type to include "connected" state

## API Changes

- New connection state "connected" for servers with transport connected but capabilities not yet discovered
- New method discoverIfConnected(serverId) for refreshing server capabilities
- Discovery failures now throw errors immediately instead of continuing with empty arrays

Related PR: cloudflare/agents#672

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
agents-git-bot bot pushed a commit to cloudflare/cloudflare-docs that referenced this pull request Nov 24, 2025
Adds comprehensive documentation for MCP connection state improvements:
- Add changelog entry for MCP connection state improvements
- Enhance connection state descriptions with better explanations
- Add version note about new 'connected' state (v0.0.24)
- Document fail-fast error handling behavior

Builds on existing discoverIfConnected() documentation already in the branch.

Related PR: cloudflare/agents#672
Copy link
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.

bit confusing to follow, but stamping to unblock

agents-git-bot bot pushed a commit to cloudflare/cloudflare-docs that referenced this pull request Nov 25, 2025
Synced from cloudflare/agents PR #672

- Document new MCPConnectionState enum with type-safe constants
- Add new 'connected' state to connection state machine
- Update state transition documentation
- Document improved discovery error handling
- Add changelog entry for breaking changes and new features

Related PR: cloudflare/agents#672

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
agents-git-bot bot pushed a commit to cloudflare/cloudflare-docs that referenced this pull request Nov 25, 2025
This sync updates the documentation to reflect changes from cloudflare/agents PR #672:

- Documented new connection state machine with separate CONNECTED and READY states
- ClientConnection.init() no longer automatically discovers capabilities

- Added MCPConnectionState enum documentation with all possible states
- Documented new CONNECTED state for transport connection without capabilities
- Added detailed state transition flows for OAuth and non-OAuth connections

- Updated error handling section to reflect fail-fast behavior with Promise.all
- Added explanations for each connection state
- Clarified the difference between CONNECTED and READY states

Related PR: cloudflare/agents#672

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
agents-git-bot bot pushed a commit to cloudflare/cloudflare-docs that referenced this pull request Nov 26, 2025
Updates documentation for PR cloudflare/agents#672

## Changes

- Updated addMcpServer() return type to discriminated union
- Added MCPConnectionState enum documentation
- Documented new "connected" state in connection lifecycle
- Added connection state transition diagrams
- Documented new discovery behavior with timeout and cancellation
- Created comprehensive changelog with migration guide

## Breaking Changes

- MCPClientConnection.init() no longer auto-discovers capabilities
- addMcpServer() return type changed to discriminated union
- New "connected" state added to connection lifecycle

🤖 Generated with Claude Code

Co-Authored-By: Claude <[email protected]>
@whoiskatrin whoiskatrin merged commit 7c9f8b0 into main Nov 26, 2025
5 checks passed
@whoiskatrin whoiskatrin deleted the feat-enums-connection-state branch November 26, 2025 15:14
@github-actions github-actions bot mentioned this pull request Nov 26, 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