Skip to content

Conversation

@mattzcarey
Copy link
Contributor

No description provided.

@changeset-bot
Copy link

changeset-bot bot commented Dec 24, 2025

🦋 Changeset detected

Latest commit: c897ff1

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

@claude
Copy link

claude bot commented Dec 24, 2025

Claude Code Review

Summary: MCP SDK upgrade from v1.23.0 to v1.25.2 with enhanced error handling and event store resumability support.

Critical Issue

Race condition in SSE stream setup (worker-transport.ts:343-383):
The stream is added to streamMapping at line 343, but the priming event (retry interval) and event replay happen after at lines 354-383. If send() is called between these operations, it will write to the stream before priming/replay completes, potentially causing events to arrive out of order or before the client is ready.

Fix: Move the priming event write and replay logic before adding the stream to streamMapping, or use a flag to defer sends until setup completes.

Issues

  1. Missing error handling in resumability flow (worker-transport.ts:293-294):

    const eventStreamId = await this.eventStore.getStreamIdForEventId?.(lastEventId);

    The optional chaining suggests this method might not exist on all EventStore implementations, but there's no handling if the method exists but throws an error. Consider wrapping in try-catch.

  2. Potential memory leak in closeSSEStream (worker-transport.ts:785-789):
    The cleanup iterates over all entries to find matching streamIds. For large numbers of requests, this could be slow. Consider maintaining a reverse mapping streamIdToRequestIds.

  3. Example uses deprecated header casing (examples/mcp-server/src/index.ts:35):

    "Access-Control-Allow-Headers": "Content-Type, Accept, mcp-session-id, mcp-protocol-version"

    SDK uses MCP-Protocol-Version (PascalCase) per the constant MCP_PROTOCOL_VERSION_HEADER. The lowercase mcp-protocol-version may not match.

Minor

  • Consider documenting the behavior when eventStore.getStreamIdForEventId() is undefined vs when it returns undefined (different semantics)
  • The changeset mentions version 1.25.2 but shows changes from 1.25.1 features like jose and json-schema-typed dependencies

Testing

Good coverage added:

  • ✅ Error handling tests (errors.test.ts)
  • ✅ Worker transport tests (640 new lines)
  • ✅ Existing transport tests updated

Tests pass validation of the error code extraction logic and CORS handling.

agents-git-bot bot pushed a commit to cloudflare/cloudflare-docs that referenced this pull request Dec 24, 2025
This sync updates the documentation to reflect the following changes from
cloudflare/agents PR #752:

## API Changes

### WorkerTransportOptions (mcp-handler-api.mdx)
- Added `onsessionclosed` callback that fires when a session is closed via
  DELETE request
- Added `eventStore` option for SSE resumability support, enabling clients to
  reconnect and resume using Last-Event-ID header
- Added `retryInterval` option to control client reconnection timing for
  polling behavior
- Added `closeSSEStream()` method to WorkerTransport class for implementing
  polling behavior during long-running operations
- Updated `sessionIdGenerator` description to clarify it can return undefined
  for stateless mode

### MCPTransportOptions (mcp-client-api.mdx)
- Added `connectionTimeoutMs` option (default: 15000ms) to prevent infinite
  hangs when connecting to MCP servers. Particularly useful when proxies strip
  SSE newline terminators.

### New Example (transport.mdx)
- Added documentation for the new `mcp-server` example showing how to use
  `WebStandardStreamableHTTPServerTransport` from the MCP SDK directly without
  the agents package. This is the simplest way to create stateless MCP servers
  on Cloudflare Workers.

Related PR: cloudflare/agents#752

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

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
agents-git-bot bot pushed a commit to cloudflare/cloudflare-docs that referenced this pull request Dec 24, 2025
This commit documents the new stateless MCP server approach introduced in PR #752 (Upgrade MCP SDK to v1.25.1).

Changes:
- Add new stateless-mcp-server.mdx guide demonstrating WebStandardStreamableHTTPServerTransport usage
- Update MCP index page to explain both stateless and McpAgent-based approaches
- Update remote-mcp-server guide to clarify it uses McpAgent and link to stateless option
- Document the simplest way to create MCP servers on Cloudflare Workers

The new example (examples/mcp-server) uses the MCP SDK directly without the agents package, providing a zero-config stateless option that is simpler for basic use cases.

Related PR: cloudflare/agents#752
@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 24, 2025

Open in StackBlitz

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

commit: c897ff1

agents-git-bot bot pushed a commit to cloudflare/cloudflare-docs that referenced this pull request Dec 24, 2025
Document the MCP SDK upgrade from v1.23.0 to v1.25.1 with the following updates:

- Add new section on using MCP SDK directly without Agents SDK
- Document the new mcp-server example using WebStandardStreamableHTTPServerTransport
- Add documentation for new WorkerTransport options:
  - onsessionclosed callback for session cleanup
  - eventStore for connection resumability support
  - retryInterval for SSE polling behavior control

Related to cloudflare/agents#752

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

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
agents-git-bot bot pushed a commit to cloudflare/cloudflare-docs that referenced this pull request Dec 29, 2025
- Document new WorkerTransport features: eventStore, onsessionclosed, retryInterval
- Highlight new mcp-server example with stateless guide
- Explain improved error handling and migration notes

Related to cloudflare/agents#752

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

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
- Upgrade MCP SDK from 1.25.1 to 1.25.2
- Import EventStore, StreamId, EventId types from SDK instead of local definitions
- Regenerate package-lock.json
- Upgrade MCP SDK from 1.23.0 to 1.25.2
- Use caret range for automatic patch updates
agents-git-bot bot pushed a commit to cloudflare/cloudflare-docs that referenced this pull request Jan 12, 2026
This updates the documentation to reflect changes from PR #752 which
upgraded the MCP SDK from v1.23.0 to v1.25.2.

Key documentation changes:
- Add new WorkerTransport options: onsessionclosed, eventStore, retryInterval
- Document the closeSSEStream() method for polling behavior
- Add example showing how to use WebStandardStreamableHTTPServerTransport directly
- Update transport.mdx to present two approaches: Agents SDK vs MCP SDK directly
- Link to new mcp-server example on GitHub

These changes help developers understand the new transport features
including session lifecycle callbacks, event resumability, and direct
MCP SDK usage without the Agents SDK.

Related PR: cloudflare/agents#752

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Copy link
Contributor

@deathbyknowledge deathbyknowledge left a comment

Choose a reason for hiding this comment

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

Very positive changes :D


This example demonstrates how to use `createMcpHandler` to create an unauthenticated stateless MCP server.

This is THE simplest way to get started with MCP on Cloudflare.
Copy link
Contributor

Choose a reason for hiding this comment

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

Dethroned. Maybe worth a mention here that this is now supported directly in the mcp library and a link to the new example?

Just a nit, don't have to do this now

@mattzcarey mattzcarey merged commit 473e53c into main Jan 12, 2026
7 checks passed
@mattzcarey mattzcarey deleted the feat-upgrade-mcp branch January 12, 2026 12:08
@github-actions github-actions bot mentioned this pull request Jan 12, 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.

3 participants