Elicitation
Elicitation lets a tool request input from the client mid-execution. This is useful for confirmations, additional information, or interactive flows.
Requirements
Section titled “Requirements”Elicitation requires both adapters to be configured:
const transport = new StreamableHttpTransport({ sessionAdapter: new InMemorySessionAdapter({ maxEventBufferSize: 1024 }), clientRequestAdapter: new InMemoryClientRequestAdapter({ defaultTimeoutMs: 30000 })});Basic Example
Section titled “Basic Example”import { z } from "zod";
server.tool("delete_record", { inputSchema: z.object({ recordId: z.string(), tableName: z.string(), }), handler: async (args, ctx) => { // Check if client supports elicitation if (!ctx.client.supports("elicitation")) { throw new Error("Elicitation not supported"); }
// Request confirmation from client const response = await ctx.elicit({ message: `Delete record "${args.recordId}" from "${args.tableName}"?`, schema: z.object({ confirmed: z.boolean() }) });
if (response.action === "accept" && response.content.confirmed) { await deleteFromDatabase(args.tableName, args.recordId); return { content: [{ type: "text", text: "Record deleted" }] }; }
return { content: [{ type: "text", text: "Deletion cancelled" }] }; }});How It Works
Section titled “How It Works”- Tool execution starts: Handler begins processing
- Elicitation request: Handler calls
ctx.elicit() - Server pauses: Execution waits for client response
- Client responds: Client sends confirmation/input
- Execution resumes: Handler continues with the response
- Result returned: Tool completes normally
Distributed Deployments
Section titled “Distributed Deployments”For serverless or multi-instance deployments, implement a custom ClientRequestAdapter using persistent storage.
The Cloudflare KV adapter works by:
- Storing request metadata in KV - Only serializable data
- Keeping local promise handlers - In the instance that created the request
- Polling for responses - Each instance polls KV to see if responses arrived
- Cross-instance coordination - Any instance can resolve/reject requests by updating KV
- Automatic cleanup - Handles timeouts and cleans up both local state and KV entries
See examples/cloudflare-worker-kv/src/mcp/client-request-adapter.ts for the full implementation.