AI Docs
Chat & Streaming
Transports
Structured Outputs
Tools
Middleware
UI
Chat UI Recipes
Interrupts
MCP
- MCP Server ToolsUpdated
- Managed MCP with chat()Updated
- Manual MCPUpdated
- MCP Type GenerationUpdated
- MCP Client InputUpdated
- MCP Server Tools: AdvancedNew
- MCP EventsNew
- MCP AppsUpdated
- Serve Tools over HTTPUpdated
- Serve Resources and PromptsUpdated
- Ask for InputUpdated
- Draft Text from a ToolUpdated
- MCP Server TasksUpdated
- MCP Server AuthUpdated
- MCP Server SessionsUpdated
- MCP Server on stdioUpdated
Persistence
Persistence (Advanced)
Media
- GenerationsUpdated
- Realtime Voice ChatUpdated
- Text-to-SpeechUpdated
- TranscriptionUpdated
- Transcription: AdvancedNew
- Voice CreationUpdated
- Audio RecordingUpdated
- Audio GenerationUpdated
- Image GenerationUpdated
- Image Generation: AdvancedNew
- Video GenerationUpdated
- Video Generation: AdvancedNew
- Live GenerationUpdated
- World GenerationUpdated
- Generation HooksUpdated
Embeddings
Reranking
Evaluate
Code Mode
Sandboxes
- OverviewUpdated
- Quick StartUpdated
- ProvidersUpdated
- HarnessesUpdated
- Harness AuthUpdated
- WorkspaceUpdated
- ToolsUpdated
- PolicyUpdated
- Lifecycle & SnapshotsUpdated
- Portable SnapshotsUpdated
- Keep Files After ReloadUpdated
- Save a Named VersionUpdated
- Branch From a VersionUpdated
- Send a Frozen FileUpdated
- Let the Agent Save and ForkUpdated
- Pick Which Files to KeepUpdated
- What a Snapshot StoresUpdated
- Instance DurabilityUpdated
- Durable RunsUpdated
- EventsUpdated
Sandboxes (Advanced)
Advanced
- Runtime ContextUpdated
- Bring Your Own KeyUpdated
- Debug LoggingUpdated
- Multimodal ContentUpdated
- Files APIUpdated
- Per-Model Type SafetyUpdated
- Runtime Adapter SwitchingUpdated
- Tree-ShakingUpdated
- Extend AdapterUpdated
- Extend Adapter: AdvancedNew
- Typed Pre-Configured OptionsUpdated
- Test with a Fake ModelUpdated
- Prompt CachingUpdated
- Mid-Conversation ChangesUpdated
- Approval Flow ProcessingUpdated
AI/LLM: This documentation page is available in plain markdown format at/ai/latest/docs/mcp/server-input.md
MCP
Ask for Input
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.
Quick setup#
You need an MCP server first. If you do not have one, start with Serve Tools over HTTP.
- Give .server() the type MCPToolContext, so ctx.context.requestInput type-checks.
- Call requestInput with the message for the user.
- Act on the answer.
ts
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.
How it works#
- ctx is the second argument of the function that you pass to .server().
- requestInput returns the string that the user sends.
- If the user declines or cancels, requestInput throws an Error. The tool call then ends with a tool error.
A TanStack chat() host pauses on the request and shows it to the user. MCP Client Input shows how the user answers.
Advanced#
Spec 2025 and spec 2026#
The two MCP spec versions ask for input in different ways.
On spec 2025:
- requestInput needs sessions: 'memory'. Without a session, it throws. See MCP Server Sessions.
- requestInput waits on the open session. The same tool call then continues with the answer.
On spec 2026:
- The handler returns input_required. Then the client runs the tool again with the answer.
- The code before requestInput runs on each call, so it can run more than once. If work must run once, put it after requestInput returns.
- A tool asks one question per call. A second requestInput in the same call throws an Error. To ask two questions, use two tools.
Task tools#
requestInput does not work in an execution: 'task' tool. MCP Server Tasks has the details.