An MCP tool can stop and ask the user before it runs. Use that when the tool deletes a file or sends data.
Call ctx.context.requestInput inside the tool. The host shows your message to the user, and the call returns the answer.
You need an MCP server first. If you do not have one, start with Serve Tools over HTTP.
import { toolDefinition } from '@tanstack/ai'
import { createMCPServer } from '@tanstack/ai-mcp/server'
import type { MCPToolContext } from '@tanstack/ai-mcp/server'
import { z } from 'zod'
const deleteFile = toolDefinition({
name: 'delete_file',
description: 'Delete a file after the user says yes',
inputSchema: z.object({
path: z.string(),
}),
}).server<MCPToolContext>(async ({ path }, ctx) => {
const answer = await ctx.context.requestInput({
message: `Delete ${path}? Type yes to continue.`,
})
if (answer !== 'yes') {
return `Kept ${path}.`
}
return `Deleted ${path}.`
})
const server = createMCPServer({
name: 'files',
version: '1.0.0',
tools: [deleteFile],
})
export function fetch(request: Request) {
return server.fetch(request)
}If the user sends yes, the tool returns Deleted plus the file path. Any other answer returns Kept plus the path.
A TanStack chat() host pauses on the request and shows it to the user. MCP Client Input shows how the user answers.
The two MCP spec versions ask for input in different ways.
On spec 2025:
On spec 2026:
requestInput does not work in an execution: 'task' tool. MCP Server Tasks has the details.