Skip to content
AnswerWell geo Documentation

Research · 7 min read · Answerwell

Stateless MCP Server Handler, Transport, Elicitation and Migration

How Cloudflare Workers serve MCP with createMcpHandler, Streamable HTTP on /mcp, elicitation, and migration from McpAgent to SDK v2.

This page summarizes Cloudflare documentation on running Model Context Protocol (MCP) servers on Workers with the Agents SDK: stateless handlers, MCP 2026-07-28, Streamable HTTP on /mcp, elicitation, and moving off deprecated McpAgent.

createMcpHandler: stateless MCP server on a Worker

Section titled “createMcpHandler: stateless MCP server on a Worker”

createMcpHandler serves an MCP SDK v2 server from a Worker without a Durable Object, protocol session, or WebSocket.

createMcpHandler from agents/mcp/server serves an MCP SDK v2 server from a Worker. The handler is stateless: it builds a fresh server for every request, so you do not need a Durable Object, protocol session, or WebSocket.

— Cloudflare, MCP Server

Each HTTP request gets a new McpServer from a factory function. Pass the factory itself—not a single global server instance:

import { McpServer } from "@modelcontextprotocol/server";
import { createMcpHandler } from "agents/mcp/server";
function createServer() {
return new McpServer({ name: "example", version: "1.0.0" });
}
export default {
fetch(request, env, ctx) {
return createMcpHandler(createServer)(request, env, ctx);
},
};

The default route is /mcp. Cross-request data belongs in KV, D1, R2, or a Durable Object keyed by the authenticated user, not in server memory. See Tools that need state and State without protocol sessions.

Aspect createMcpHandler (stateless) McpAgent (legacy)
Lifecycle New server per request Durable Object + session
MCP 2026-07-28 Supported Legacy SDK v1 path
In-memory tool state Not between requests Can persist in DO SQL
Status Recommended Deprecated, feature-frozen

McpAgent is deprecated and feature-frozen. Migrate existing McpAgent servers to the stateless handler at your earliest convenience.

— Cloudflare, Agents SDK adds MCP Specification 2026-07-28 support

MCP 2026-07-28 and /mcp: endpoint and transport

Section titled “MCP 2026-07-28 and /mcp: endpoint and transport”

Why clients should use /mcp instead of /sse

Section titled “Why clients should use /mcp instead of /sse”

Hosted product MCP servers and your own handlers should expose Streamable HTTP on /mcp. Legacy HTTP+SSE on /sse is retired for Cloudflare product servers.

Cloudflare’s product-specific MCP servers now serve only /mcp. A request to /sse returns 410 Gone with the server’s /mcp URL, which most MCP clients show in their connection error.

— Cloudflare, Cloudflare MCP servers no longer serve /sse

For new connections, use /mcp (for example https://docs.mcp.cloudflare.com/mcp). If a client forces SSE transport, switch it to Streamable HTTP or automatic detection per Cloudflare MCP servers support the new MCP 2026-07-28 Specification.

Server-Sent Events (SSE) was previously used for remote MCP connections but has been deprecated in favor of Streamable HTTP. createMcpHandler serves Streamable HTTP only.

— Cloudflare, Transport

Agents connecting as MCP clients can set transport explicitly or use auto:

Transport Role
streamable-http Recommended for remote servers
auto Default; picks from server response
sse Legacy compatibility only

See Transport options on the MCP Client API page.

MCP server portals (upstream compatibility)

Section titled “MCP server portals (upstream compatibility)”

Cloudflare One MCP server portals accept stateless MCP 2026-07-28 and 2025 Streamable HTTP clients on /mcp. Client and upstream protocol versions are chosen independently; SSE upstream always uses the legacy protocol on the portal path.

Elicitation lets an MCP server ask the user for input mid–tool-call. Form mode collects structured non-sensitive data; URL mode asks consent before opening an out-of-band flow (authorization, payment).

Elicitation lets an MCP server request user input while it handles a tool call. Form mode collects structured, non-sensitive data. URL mode asks for consent before opening an out-of-band flow, such as third-party authorization or payment.

— Cloudflare, Agents can respond to MCP elicitation requests

Server side (stateless): MRTR, not pushed requests

Section titled “Server side (stateless): MRTR, not pushed requests”

On createMcpHandler, elicitation returns input_required and completes through multi-round-trip requests (MRTR). The Worker does not stay suspended while the user responds.

Elicitation through a stateless handler returns input_required and completes through multi-round-trip requests (MRTR). On each retry, the SDK echoes the latest requestState and sends responses for the immediately preceding input round.

— Cloudflare, Elicitation with a stateless handler

Use inputRequired(...) and read accepted form content from context.mcpReq.inputResponses. Seal trusted intermediate values in integrity-protected requestState.

Client side: configureElicitationHandlers in Agents

Section titled “Client side: configureElicitationHandlers in Agents”

Agents that call remote servers with addMcpServer register handlers in onStart():

this.mcp.configureElicitationHandlers({
form: (request, serverId) => this.forwardToUser(request, serverId),
url: (request, serverId) => this.forwardToUser(request, serverId),
});

The SDK advertises only modes that have handlers. Modes are stored with each server registration so they survive Durable Object hibernation. Details: MCP Client — Elicitation and Human-in-the-loop patterns — MCP elicitation.

Charging for MCP tools with mppx still uses SDK v1 createLegacyMcpHandler and Transport.mcpSdk() until those integrations emit SDK v2 servers. See Accept payments with MPP and Integration compatibility.

Migrate from McpAgent and MCP SDK v1 to SDK v2

Section titled “Migrate from McpAgent and MCP SDK v1 to SDK v2”

Agents SDK v0.20.0 adds client and server support for MCP 2026-07-28. Ordinary tools, prompts, and resources can share one route:

The same createMcpHandler(createServer)(request, env, ctx) route serves MCP 2026-07-28 clients and legacy clients that use stateless requests. You do not need separate routes or tool definitions for ordinary tools, prompts, and resources.

— Cloudflare, Backward compatibility

Keep McpAgent or createLegacyMcpHandler only if the endpoint depends on sessionful features: protocol sessions, transport replay, standalone GET streams, pushed elicitation/sampling/roots, or session DELETE. Map replacements in Plan stateless equivalents for stateful features.

Route by request type with isLegacyRequest():

import { isLegacyRequest } from "@modelcontextprotocol/server";
import { createMcpHandler } from "agents/mcp/server";
const stateless = createMcpHandler(createServer, { route: "/mcp", legacy: "reject" });
const legacy = MyMcpAgent.serve("/mcp");
export default {
async fetch(request, env, ctx) {
if (await isLegacyRequest(request)) {
return legacy.fetch(request, env, ctx);
}
return stateless(request, env, ctx);
},
};

Install packages per role (Install the MCP packages): @modelcontextprotocol/server for stateless servers; @modelcontextprotocol/sdk only for the legacy lane.

Legacy compatibility limits on the stateless handler

Section titled “Legacy compatibility limits on the stateless handler”

Default legacy: "stateless" supports ordinary legacy tools, prompts, and resources but not full sessions: each POST gets a new server; GET/DELETE return 405; pushed elicitation fails immediately. Set legacy: "reject" for stateless-only endpoints. Full table: Compatibility with legacy clients.

addMcpServer can take a Durable Object binding instead of a URL (RPC transport for MCP). This is experimental, connects only to McpAgent, and has no OAuth—prefer Streamable HTTP to a createMcpHandler URL for new work per RPC transport.

The Workers wrapper validates browser Origin headers and rejects malformed or non-HTTP origins with 403. CORS headers are not authentication; protect /mcp with OAuth or another auth layer. For custom domains, set allowedHostnames and allowedOriginHostnames explicitly—see Origin validation and CORS and Origin validation on Workers.

  • Pointing MCP clients at /sse after product servers return 410 with the /mcp URL (retire SSE).
  • Passing createServer() instead of createServer to createMcpHandler (SDK v2 expects a factory).
  • Expecting in-memory state across tool calls on a stateless server without KV/D1/R2/DO (Tools that need state).
  • Advertising elicitation modes without matching handlers (Capability behavior).
  • Running dual routes without legacy: "reject" on the stateless handler, so legacy traffic never reaches McpAgent (Run stateless and legacy lanes together).
  • Creating a new handler instance per request when using notify or subscriptions/listen—construct the handler once at module scope (Keep one handler for notifications).
  1. Upgrade the Agents SDK and pin MCP packages as in Migrate to MCP SDK v2, then deploy with Wrangler configuration (npx wrangler deploy).

  2. Confirm your MCP client URL ends in /mcp and uses Streamable HTTP or auto, following Transport options and Build a Remote MCP server.

  3. Call a registered tool; if elicitation is enabled, verify form or URL prompts through handlers described in MCP Client — Elicitation.

  4. For a hosted reference connection, test against Cloudflare API MCP features documented in step-up authorization if your client supports them.

  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact sentence you are asking about.