|
| 1 | +--- |
| 2 | +title: Agents SDK adds MCP Elicitation support, http-streamable suppport, task queues, email integration and more |
| 3 | +description: Major update brings MCP elicitation, enhanced transport options,auto transport selection, improved error handling, and reliable prop updates, task queues, and email support |
| 4 | +products: |
| 5 | + - agents |
| 6 | + - workers |
| 7 | +date: 2025-08-05 |
| 8 | +--- |
| 9 | + |
| 10 | +The latest releases of [@cloudflare/agents](https://github.com/cloudflare/agents) brings major improvements to MCP transport protocols support and agents connectivity. Key updates include: |
| 11 | + |
| 12 | +### MCP elicitation support |
| 13 | + |
| 14 | +MCP servers can now request user input during tool execution, enabling interactive workflows like confirmations, forms, and multi-step processes. This feature uses durable storage to preserve elicitation state even during agent hibernation, ensuring seamless user interactions across agent lifecycle events. |
| 15 | + |
| 16 | +```ts |
| 17 | +// Request user confirmation via elicitation |
| 18 | +const confirmation = await this.elicitInput({ |
| 19 | + message: `Are you sure you want to increment the counter by ${amount}?`, |
| 20 | + requestedSchema: { |
| 21 | + type: "object", |
| 22 | + properties: { |
| 23 | + confirmed: { |
| 24 | + type: "boolean", |
| 25 | + title: "Confirm increment", |
| 26 | + description: "Check to confirm the increment", |
| 27 | + }, |
| 28 | + }, |
| 29 | + required: ["confirmed"], |
| 30 | + }, |
| 31 | +}); |
| 32 | +``` |
| 33 | + |
| 34 | +Check out our [demo](https://github.com/whoiskatrin/agents/tree/main/examples/mcp-elicitation-demo) to see elicitation in action. |
| 35 | + |
| 36 | +### HTTP streamable transport for MCP |
| 37 | + |
| 38 | +MCP now supports HTTP streamable transport which is recommended over SSE. This transport type offers: |
| 39 | + |
| 40 | +- **Better performance**: More efficient data streaming and reduced overhead |
| 41 | +- **Improved reliability**: Enhanced connection stability and error recover- **Automatic fallback**: If streamable transport is not available, it gracefully falls back to SSE |
| 42 | + |
| 43 | +```ts |
| 44 | +export default MyMCP.serve("/mcp", { |
| 45 | + binding: "MyMCP", |
| 46 | +}); |
| 47 | +``` |
| 48 | + |
| 49 | +The SDK automatically selects the best available transport method, gracefully falling back from streamable-http to SSE when needed. |
| 50 | + |
| 51 | +### Enhanced MCP connectivity |
| 52 | + |
| 53 | +Significant improvements to MCP server connections and transport reliability: |
| 54 | + |
| 55 | +- **Auto transport selection**: Automatically determines the best transport method, falling back from streamable-http to SSE as needed |
| 56 | +- **Improved error handling**: Better connection state management and error reporting for MCP servers |
| 57 | +- **Reliable prop updates**: Centralized agent property updates ensure consistency across different contexts |
| 58 | + |
| 59 | +### Lightweight .queue for fast task deferral |
| 60 | + |
| 61 | +You can use `.queue()` to enqueue background work — ideal for tasks like processing user messages, sending notifications etc. |
| 62 | + |
| 63 | +```ts |
| 64 | +class MyAgent extends Agent { |
| 65 | + doSomethingExpensive(payload) { |
| 66 | + // a long running process that you want to run in the background |
| 67 | + } |
| 68 | + |
| 69 | + queueSomething() { |
| 70 | + await this.queue("doSomethingExpensive", somePayload); // this will NOT block further execution, and runs in the background |
| 71 | + await this.queue("doSomethingExpensive", someOtherPayload); // the callback will NOT run until the previous callback is complete |
| 72 | + // ... call as many times as you want |
| 73 | + } |
| 74 | +} |
| 75 | +``` |
| 76 | + |
| 77 | +Want to try it yourself? Just define a method like processMessage in your agent, and you’re ready to scale. |
| 78 | + |
| 79 | +### New email adapter |
| 80 | + |
| 81 | +Want to build an AI agent that can receive and respond to emails automatically? With the new email adapter and onEmail lifecycle method, now you can. |
| 82 | + |
| 83 | +```ts |
| 84 | +export class EmailAgent extends Agent { |
| 85 | + async onEmail(email: AgentEmail) { |
| 86 | + const raw = await email.getRaw(); |
| 87 | + const parsed = await PostalMime.parse(raw); |
| 88 | + |
| 89 | + // create a response based on the email contents |
| 90 | + // and then send a reply |
| 91 | + |
| 92 | + await this.replyToEmail(email, { |
| 93 | + fromName: "Email Agent", |
| 94 | + body: `Thanks for your email! You've sent us "${parsed.subject}". We'll process it shortly.`, |
| 95 | + }); |
| 96 | + } |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +You route incoming mail like this: |
| 101 | + |
| 102 | +```ts |
| 103 | +export default { |
| 104 | + async email(email, env) { |
| 105 | + await routeAgentEmail(email, env, { |
| 106 | + resolver: createAddressBasedEmailResolver("EmailAgent"), |
| 107 | + }); |
| 108 | + }, |
| 109 | +}; |
| 110 | +``` |
| 111 | + |
| 112 | +You can find a full example [here](https://github.com/cloudflare/agents/tree/main/examples/email-agent). |
| 113 | + |
| 114 | +### Automatic context wrapping for custom methods |
| 115 | + |
| 116 | +Custom methods are now automatically wrapped with the agent's context, so calling `getCurrentAgent()` should work regardless of where in an agent's lifecycle it's called. Previously this would not work on RPC calls, but now just works out of the box. |
| 117 | + |
| 118 | +```ts |
| 119 | +export class MyAgent extends Agent { |
| 120 | + async suggestReply(message) { |
| 121 | + // getCurrentAgent() now correctly works, even when called inside an RPC method |
| 122 | + const { agent } = getCurrentAgent()!; |
| 123 | + return generateText({ |
| 124 | + prompt: `Suggest a reply to: "${message}" from "${agent.name}"`, |
| 125 | + tools: [replyWithEmoji], |
| 126 | + }); |
| 127 | + } |
| 128 | +} |
| 129 | +``` |
| 130 | + |
| 131 | +Try it out and tell us what you build! |
0 commit comments