ExperimentalExperimentalExperimentalCancels a running task.
The task identifier
Optionaloptions: RequestOptionsOptional request options
ExperimentalSends a sampling request and returns an AsyncGenerator that yields response messages. The generator is guaranteed to end with either a 'result' or 'error' message.
For task-augmented requests, yields 'taskCreated' and 'taskStatus' messages before the final result.
The sampling request parameters
Optional_meta?: {See General fields: _meta for notes on _meta usage.
Optionalio.modelcontextprotocol/related-task?: { taskId: string }If specified, this request is related to the provided task.
OptionalprogressToken?: string | numberIf specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
OptionalincludeContext?: "none" | "thisServer" | "allServers"A request to include context from one or more MCP servers (including the caller), to be attached to the prompt. The client MAY ignore this request.
Default is "none". Values "thisServer" and "allServers" are soft-deprecated. Servers SHOULD only use these values if the client declares ClientCapabilities.sampling.context. These values may be removed in future spec releases.
The requested maximum number of tokens to sample (to prevent runaway completions).
The client MAY choose to sample fewer tokens than the requested maximum.
Optionalmetadata?: objectOptional metadata to pass through to the LLM provider. The format of this metadata is provider-specific.
OptionalmodelPreferences?: {The server's preferences for which model to select. The client MAY modify or omit this request.
OptionalcostPriority?: numberHow much to prioritize cost when selecting a model.
Optionalhints?: { name?: string }[]Optional hints to use for model selection.
OptionalintelligencePriority?: numberHow much to prioritize intelligence and capabilities when selecting a model.
OptionalspeedPriority?: numberHow much to prioritize sampling speed (latency) when selecting a model.
OptionalstopSequences?: string[]OptionalsystemPrompt?: stringAn optional system prompt the server wants to use for sampling. The client MAY modify or omit this prompt.
Optionaltask?: { ttl?: number }If specified, the caller is requesting task-augmented execution for this request. The request will return a CreateTaskResult immediately, and the actual result can be retrieved later via tasks/result.
Task augmentation is subject to capability negotiation - receivers MUST declare support for task augmentation of specific request types in their capabilities.
Optionaltemperature?: numberOptionaltoolChoice?: { mode?: "required" | "none" | "auto" }Controls how the model uses tools.
The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
Default is { mode: "auto" }.
Optionalmode?: "required" | "none" | "auto"Controls when tools are used:
Optionaltools?: {Tools that the model may use during generation. The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
Optionaloptions: RequestOptionsOptional request options (timeout, signal, task creation params, onprogress, etc.)
AsyncGenerator that yields ResponseMessage objects
const stream = server.experimental.tasks.createMessageStream({
messages: [{ role: 'user', content: { type: 'text', text: 'Hello' } }],
maxTokens: 100
}, {
onprogress: (progress) => {
// Handle streaming tokens via progress notifications
console.log('Progress:', progress.message);
}
});
for await (const message of stream) {
switch (message.type) {
case 'taskCreated':
console.log('Task created:', message.task.taskId);
break;
case 'taskStatus':
console.log('Task status:', message.task.status);
break;
case 'result':
console.log('Final result:', message.result);
break;
case 'error':
console.error('Error:', message.error);
break;
}
}
ExperimentalSends an elicitation request and returns an AsyncGenerator that yields response messages. The generator is guaranteed to end with either a 'result' or 'error' message.
For task-augmented requests (especially URL-based elicitation), yields 'taskCreated' and 'taskStatus' messages before the final result.
The elicitation request parameters
Optional_meta?: {See General fields: _meta for notes on _meta usage.
Optionalio.modelcontextprotocol/related-task?: { taskId: string }If specified, this request is related to the provided task.
OptionalprogressToken?: string | numberIf specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
The message to present to the user describing what information is being requested.
Optionalmode?: "form"The elicitation mode.
Optional for backward compatibility. Clients MUST treat missing mode as "form".
A restricted subset of JSON Schema. Only top-level properties are allowed, without nesting.
Optionaltask?: { ttl?: number }If specified, the caller is requesting task-augmented execution for this request. The request will return a CreateTaskResult immediately, and the actual result can be retrieved later via tasks/result.
Task augmentation is subject to capability negotiation - receivers MUST declare support for task augmentation of specific request types in their capabilities.
Optional_meta?: {See General fields: _meta for notes on _meta usage.
Optionalio.modelcontextprotocol/related-task?: { taskId: string }If specified, this request is related to the provided task.
OptionalprogressToken?: string | numberIf specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
The ID of the elicitation, which must be unique within the context of the server. The client MUST treat this ID as an opaque value.
The message to present to the user explaining why the interaction is needed.
The elicitation mode.
Optionaltask?: { ttl?: number }If specified, the caller is requesting task-augmented execution for this request. The request will return a CreateTaskResult immediately, and the actual result can be retrieved later via tasks/result.
Task augmentation is subject to capability negotiation - receivers MUST declare support for task augmentation of specific request types in their capabilities.
The URL that the user should navigate to.
Optionaloptions: RequestOptionsOptional request options (timeout, signal, task creation params, etc.)
AsyncGenerator that yields ResponseMessage objects
const stream = server.experimental.tasks.elicitInputStream({
mode: 'url',
message: 'Please authenticate',
elicitationId: 'auth-123',
url: 'https://example.com/auth'
}, {
task: { ttl: 300000 } // Task-augmented for long-running auth flow
});
for await (const message of stream) {
switch (message.type) {
case 'taskCreated':
console.log('Task created:', message.task.taskId);
break;
case 'taskStatus':
console.log('Task status:', message.task.status);
break;
case 'result':
console.log('User action:', message.result.action);
break;
case 'error':
console.error('Error:', message.error);
break;
}
}
ExperimentalGets the current status of a task.
The task identifier
Optionaloptions: RequestOptionsOptional request options
The task status
ExperimentalRetrieves the result of a completed task.
The task identifier
OptionalresultSchema: TZod schema for validating the result
Optionaloptions: RequestOptionsOptional request options
The task result
ExperimentalLists tasks with optional pagination.
Optionalcursor: stringOptional pagination cursor
Optionaloptions: RequestOptionsOptional request options
List of tasks with optional next cursor
ExperimentalSends a request and returns an AsyncGenerator that yields response messages. The generator is guaranteed to end with either a 'result' or 'error' message.
This method provides streaming access to request processing, allowing you to observe intermediate task status updates for task-augmented requests.
The request to send
Zod schema for validating the result
Optionaloptions: RequestOptionsOptional request options (timeout, signal, task creation params, etc.)
AsyncGenerator that yields ResponseMessage objects
Experimental task features for low-level MCP servers.
Access via
server.experimental.tasks:For high-level server usage with task-based tools, use
McpServer.experimental.tasksinstead.