Revert MCP POST routing and restore server examples#1532
Conversation
This reverts commit 0371a6f.
Bring back the server-only MCP elicitation and raw transport examples that were lost during the full-stack example migration. Also document that focused MCP protocol examples may stay Wrangler-only, refresh the workspace lockfile for the restored mcp-server workspace, and add a patch changeset noting the PR #1514 routing revert. Co-authored-by: Cursor <cursoragent@cursor.com>
🦋 Changeset detectedLatest commit: d335334 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
| const connection = Array.from( | ||
| agent.getConnections<{ requestIds?: RequestId[] }>() | ||
| ).find((conn) => conn.state?.requestIds?.includes(requestId)); | ||
| agent.getConnections<{ requestIds?: number[] }>() | ||
| ).find((conn) => conn.state?.requestIds?.includes(requestId as number)); |
There was a problem hiding this comment.
🔴 RequestId narrowed to number[] breaks string request IDs
At line 354-355, the code types requestIds as number[] and casts requestId as number. However, RequestId in the MCP SDK (and JSON-RPC 2.0 spec) is string | number. If a client sends a request with a string ID (e.g. "req-1"), Array.prototype.includes() uses strict equality (===), so ["req-1"].includes("req-1" as number) would never match—it compares a string against the number type expectation. This causes a runtime error: "No connection established for request ID: req-1". The old code correctly used RequestId[] without any cast (packages/agents/src/mcp/transport.ts:354-355 in the base).
| const connection = Array.from( | |
| agent.getConnections<{ requestIds?: RequestId[] }>() | |
| ).find((conn) => conn.state?.requestIds?.includes(requestId)); | |
| agent.getConnections<{ requestIds?: number[] }>() | |
| ).find((conn) => conn.state?.requestIds?.includes(requestId as number)); | |
| const connection = Array.from( | |
| agent.getConnections<{ requestIds?: RequestId[] }>() | |
| ).find((conn) => conn.state?.requestIds?.includes(requestId)); |
Was this helpful? React with 👍 or 👎 to provide feedback.
| for (const id of relatedIds) { | ||
| this._requestResponseMap.delete(id); | ||
| } | ||
| connection.setState({ requestIds: [] }); | ||
| } |
There was a problem hiding this comment.
🟡 Removing setState({ requestIds: [] }) leaves stale request IDs on closed connections
When all responses for a batched POST have been sent (shouldClose = true), the old code cleared the connection's request IDs via connection.setState({ requestIds: [] }). This cleanup was removed at the end of the send() method. Without it, a connection that has been signaled to close still retains its old requestIds in its state. If a subsequent send() call races before the connection is fully torn down, the stale requestIds could cause the lookup at line 353-355 to match the wrong (closing) connection, routing a message to a stream that's about to close.
(Refers to lines 376-381)
Was this helpful? React with 👍 or 👎 to provide feedback.
| @@ -1,25 +1,25 @@ | |||
| { | |||
There was a problem hiding this comment.
🟡 Missing $schema in mcp-elicitation wrangler.jsonc violates examples/AGENTS.md convention
The examples/AGENTS.md convention states wrangler.jsonc must include "$schema": "../../node_modules/wrangler/config-schema.json". The mcp-elicitation example's wrangler.jsonc had this field in the old version but it was removed in this PR.
| { | |
| { | |
| "$schema": "../../node_modules/wrangler/config-schema.json", |
Was this helpful? React with 👍 or 👎 to provide feedback.
| @@ -0,0 +1,11 @@ | |||
| { | |||
There was a problem hiding this comment.
🟡 Missing $schema in mcp-server wrangler.jsonc violates examples/AGENTS.md convention
The examples/AGENTS.md convention states wrangler.jsonc must include "$schema": "../../node_modules/wrangler/config-schema.json". The new mcp-server example's wrangler.jsonc is missing this field.
| { | |
| { | |
| "$schema": "../../node_modules/wrangler/config-schema.json", |
Was this helpful? React with 👍 or 👎 to provide feedback.
agents
@cloudflare/ai-chat
@cloudflare/codemode
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
Summary
mcp-elicitationas a focused server-only Wrangler example for MCP elicitation clients.mcp-serverexample and update example guidance/README metadata to allow minimal server-only MCP examples.agentsdocumenting the Fix streamable HTTP server-to-client MCP routing #1514 revert.Test plan
npx tsc --noEmit -p examples/mcp-elicitation/tsconfig.json && npx tsc --noEmit -p examples/mcp-server/tsconfig.jsonnpx oxlint examples/mcp-elicitation/src/index.ts examples/mcp-server/src/index.tsnpx oxfmt --check README.md examples/AGENTS.md examples/TODO.md examples/mcp-elicitation/README.md examples/mcp-elicitation/package.json examples/mcp-elicitation/src/index.ts examples/mcp-elicitation/tsconfig.json examples/mcp-elicitation/wrangler.jsonc examples/mcp-server/README.md examples/mcp-server/package.json examples/mcp-server/src/index.ts examples/mcp-server/tsconfig.json examples/mcp-server/wrangler.jsonc package-lock.json .changeset/bright-buses-route.mdNote: local
npm run checkis currently blocked by unrelated local workspace state:sherifwarns aboutexamples/think-slide-deck/package.json, andoxfmt --check .reports formatting issues inpackages/codemode/CHANGELOG.mdandpackages/think/CHANGELOG.md.Made with Cursor