Skip to Content
onedef

Elicitation workflow

MCP tools that stop to ask the user or the agent, and continue exactly where they stopped. For any MCP SDK server, with or without onedef.

@onedef/elicitation-workflow lets an MCP tool pause for an answer and then pick up where it stopped, without running anything twice. It works on any MCP TypeScript SDK server. You don't need the rest of onedef.

A tool can ask two kinds of questions:

  • the user: approve a deploy, fill in a form. These are native MCP elicitation forms.
  • the agent: do a piece of the work, such as write a section or translate a part, and answer in a schema you define.

The problem it solves

With MCP elicitation (protocol 2026-07-28), a tool that asks the user returns input_required. The client shows the form, then calls the tool again with the answer. So everything before the question runs again:

server.registerTool('deploy', { inputSchema }, async ({ env }, ctx) => {
  const build = await buildApp()   // runs on the first call AND on the retry
  const answer = acceptedContent(ctx.mcpReq.inputResponses, 'confirm')
  if (!answer) {
    return inputRequired({ inputRequests: { confirm: inputRequired.elicit({ … }) } })
  }
  return ship(build)               // ships the second build, not the one the user saw
})

We ran this through Claude Code, with a hook answering "yes":

plain deploy: BUILD ran (total 1)
USER asked: Deploy build-1 to staging?
plain deploy: BUILD ran (total 2)
plain deploy: SHIPPED build-2 to staging        ← not the build the user approved

The build ran twice, and the user approved one build while another shipped.

The same tool, as an elicitation workflow

deploy.ts
import { createWorkflow, memoryRunStore } from '@onedef/elicitation-workflow'
import { registerWorkflowTool } from '@onedef/elicitation-workflow/mcp'
import { z } from 'zod'

const deploy = createWorkflow({
  id: 'deploy',
  description: 'Build the app and deploy it, after the user confirms.',
  input: z.object({ env: z.string() }),
}).handler(async (ctx) => {
  const build = await ctx.step('build', () => buildApp())   // runs once

  const answer = await ctx.elicitHumanInput({               // the same params as MCP elicitation
    message: `Deploy ${build.id} to ${ctx.input.env}?`,
    requestedSchema: { type: 'object', properties: { confirm: { type: 'boolean' } }, required: ['confirm'] },
  })
  if (answer.action !== 'accept' || !answer.content?.confirm) return { deployed: false }

  return ctx.step('ship', () => ship(build))
})

// registered like server.registerTool(name, config, handler), with the workflow as the handler
registerWorkflowTool(server, 'deploy', { runStore: memoryRunStore() }, deploy)
workflow deploy: BUILD ran (total 1)
USER asked: Deploy build-1 to staging?
workflow deploy: SHIPPED build-1 to staging

The tool still returns input_required, and the client still calls it again. But the call carries the run's id, and the run replays from where it was. The finished build step returns its recorded result instead of running, and the user's answer goes to the question that was waiting.

What you get

  • Nothing runs twice. Work before a question is a recorded step.
  • Native forms. The user sees the client's own elicitation UI, in Claude Code, Claude and other MCP clients.
  • The agent can do the work. ctx.elicitAgentInput hands a piece of work to the connected model and checks its answer against your schema.
  • Durable runs. A run lives in a store (memory, files, Redis), not in a process. It survives restarts, deploys and serverless instances, and can wait for days.
  • Durable steps from TanStack Workflow. createWorkflow is TanStack Workflow's, with the questions added, so ctx.step and the rest of TanStack's ctx are there. Everything comes from one package.

Install

pnpm add @onedef/elicitation-workflow @modelcontextprotocol/server zod

Registering it

A workflow tool registers the way a native tool does:

server.ts
import { McpServer } from '@modelcontextprotocol/server'
import { memoryRunStore } from '@onedef/elicitation-workflow'
import { registerWorkflowTool } from '@onedef/elicitation-workflow/mcp'

const server = new McpServer({ name: 'deploys', version: '1.0.0' })

// native:   server.registerTool('deploy', { title, description, inputSchema }, handler)
registerWorkflowTool(server, 'deploy', { title, description, inputSchema, runStore }, deploy)

The config takes what registerTool's does (title, description, inputSchema, annotations), plus runStore, where runs wait between calls. description and inputSchema default to the workflow's own.

The tool is deploy. It also gets a companion, deploy_next, where the agent sends its answers to ctx.elicitAgentInput. Questions for the user need no second tool: they go through MCP elicitation.

A complete server with a scripted test and an eve eval is in examples/mcp-workflow, including the comparison above as one script.

On this page