While a tool, a resource or a prompt runs, the server can run it in the background, tell the client how far it got, send it logs, and ask the user or the model of the client.
Tasks
With @mcpTask optional, a client may run the tool as a
task, as the specification’s tasks utility, still experimental in
2025-11-25, defines it; with @mcpTask required, it must,
and a call without task gets -32601. The server answers a call with a
task at once, with the task’s ID, drawn from a cryptographically secure
generator, and runs the call in a background R process: a worker of the
pool, which the task holds until it ends, so that the tool calls wait in
the queue rather than behind it. The client follows it with
tasks/get, gets its result with tasks/result,
which waits for the end of the task, and stops it with
tasks/cancel. A task keeps its result for the time to live
the client asks, at most an hour; at most
run_mcp_server(tasks = ) tasks run at once, one less than
the workers by default so that a worker stays free for the calls, and
the task that comes beyond gets an error asking to retry later.
timeout does not stop a task: its time to live does. The
server answers each session at most task_requests = task
requests per second, 20 by default. A task belongs to the HTTP session
that created it, or to the stdio client: another session gets “Task not
found”, and tasks/list lists the tasks of the session,
oldest first, by pages of 100, with the ID of the last task as cursor.
Without a session, a task is reached by its ID alone, and
tasks/list gets -32603, since it would show the tasks of
every client without a session. When the worker of a task ends, or stops
after tasks/cancel, the server sends the session that
created it notifications/tasks/status, with the task as
tasks/get shows it: a line over stdio, an event of the
stream of the GET over HTTP (see Listening). A 2025-11-25 task never asks
for input (input_required): a tool that asks the user does
it before the task starts. call_tool() runs as a task a
tool that requires one, or any tool with task = TRUE.
A tool that may run as a task:
#' Rebuild the statistics
#'
#' Computes the statistics of every year again, which takes minutes.
#'
#' @mcpTool
#' @mcpReturns text
#' @mcpTask optional
#' @export
rebuild_statistics <- function() {
Sys.sleep(
120
)
"Statistics rebuilt."
}Progress
A tool, a resource, a prompt or a completion function tells the user
how far it got with
mordew::report_progress(progress, total, message): when the
client asked for the progress of the call (a progressToken
in _meta), the worker sends it to the front, which sends
the client a notifications/progress with that token: a line
over stdio, an event of the SSE stream that the answer to the POST
becomes over HTTP. progress must increase at each call; the
server sends at most ten notifications per second for a call, and none
after its answer. A task sends its progress until it ends, with its ID
in _meta["io.modelcontextprotocol/related-task"], as its
logs: a line over stdio, an event of the stream of the GET over HTTP,
which a client without that stream does not get. Outside a server, or
when the client did not ask, report_progress() only checks
its arguments.
Logging
mordew::log_message(data, level, logger) sends the
client a notifications/message while a tool, a resource, a
prompt or a completion function runs. data is a string, a
number, a logical or a list; level one of the eight syslog
levels, from debug to emergency;
logger the name of the package unless another is given. The
client gets the level it set with logging/setLevel and
above, info and above until it sets one. The level is kept
for the stdio connection or for the HTTP session, and a
logging/setLevel without a session gets -32603. A
2026-07-28 request gets logs only when it carries a level in
_meta["io.modelcontextprotocol/logLevel"], at that level
and above, and an unknown level gets -32602. Messages travel like
progress, at most ten per second for a call and none after its answer.
The server sends only what log_message() sends, and removes
control characters from its text: a message must hold no secret, no
personal data and no internal detail that would help an attack. Outside
a server, log_message() only checks its arguments.
Tracing
A client may send an OpenTelemetry trace context in the
_meta of a request: traceparent,
tracestate and baggage.
mordew::trace_context() gives it to the function that runs,
which can make it the parent of its own spans, with
otel::extract_http_context(mordew::trace_context()), or
send it on to the services it calls. mordew creates no
span itself.
Asking the user
@mcpConfirm Delete run {run_id}? makes the server ask
the user before the tool runs, through the client (an
elicitation/create request, in form mode), with the
arguments of the model in the message; each
@mcpElicit <param> adds a field to that form, which
the user fills instead of the model: the parameter leaves the schema the
model sees, and its default value in the signature becomes the default
of the field. A field takes a string (with a format, a
length), a number, an integer, a boolean, or choices
(type_enum(), titled or not, or an array of them for
several; enum_names = TRUE writes the titles in the
deprecated enumNames rather than oneOf, for
the clients that read only it). The server checks the answer against the
form, then runs the tool with it; when the user declines or dismisses
the question, or the answer does not fit, the tool does not run and the
model gets an isError result saying why. A client that did
not declare elicitation, or a request without session over HTTP, gets
such a result at once. A cancellation of the call cancels its question,
and only the client that was asked can answer it. Over HTTP, the
question is an event of the SSE stream of the tool call, and the answer
comes in a POST of its own, accepted with 202. A tool that runs as a
task asks before the task starts.
A form must never ask for a password, an API key, a token or a
payment: the specification forbids it. For those, the tool calls
elicit_url(url, message, id), which ends the call with the
error -32042: the client offers the user to open the page, where the
package takes what it needs, out of the client, and the client calls
again. The page must check that the user who opens it is the one who
made the call. A client that cannot open a page gets an error saying so
instead. Over HTTP, the session keeps the ID of the elicitation, and
once the user is done, the server of the page can send
{"elicitationId": "<id>"} in a POST to
/elicitation/complete, with the token if the MCP server has
one: the client that got that ID, and no other, gets
notifications/elicitation/complete on the stream of its
GET, so it can call again by itself. The POST gets 200, 404 for an ID
that no session holds or that was already completed, and 400 without an
ID. Over stdio, the server has no port for that POST, and sends no such
notification. call_tool(answer = ) answers the questions of
a tool in tests: a named list of fields, list() to confirm,
"decline" or "cancel".
A tool that asks before it deletes, and takes its reason from the user:
#' Delete a run
#'
#' Deletes the run of a day.
#'
#' @param date Day of the run.
#' @param reason Why the run is deleted.
#'
#' @mcpTool
#' @mcpType date type_string(format = "date")
#' @mcpType reason type_string()
#' @mcpReturns text
#' @mcpConfirm Delete the run of {date}?
#' @mcpElicit reason
#' @export
delete_run <- function(date, reason) {
paste0(
"Run of ",
date,
" deleted: ",
reason
)
}Asking the model of the client
@mcpSample summary Summarise run {run_id} in one sentence.
makes the server ask the model of the client for a text before the tool
runs (a sampling/createMessage request, of 1000 tokens at
most), with the arguments of the model in the message; the text goes to
the summary parameter, a string that leaves the schema the
model sees. A tool asks the model or the user, not both. When the client
refuses, or the model answers without text, the tool does not run and
the model gets an isError result saying why; a client that
did not declare sampling gets such a result at once, and a 2026-07-28
one gets -32021. In tests, call_tool(sample = ) answers
with the text it is given.
A tool whose note is written by the model of the client:
#' Add a note to a run
#'
#' Adds a note to the run of a day.
#'
#' @param date Day of the run.
#' @param note Note to add.
#'
#' @mcpTool
#' @mcpType date type_string(format = "date")
#' @mcpType note type_string()
#' @mcpReturns text
#' @mcpSample note Write one sentence that cheers a runner up.
#' @export
add_note <- function(date, note) {
paste0(
"Note added to the run of ",
date,
": ",
note
)
}Asking the client while the function runs
mordew::ask() asks the client while a tool, a resource
or a prompt runs. It takes named requests, made by
input_form() (a form for the user, its fields made by the
exported type_*() functions), input_sample()
(a text from the model of the client) and input_roots()
(the roots of the client), and returns the answers of the client by
name:
pick_shoes <- function(run_id) {
answers <- mordew::ask(
shoes = mordew::input_form(
"Which shoes did you wear?",
model = mordew::type_string()
)
)
paste("Run", run_id, "in", answers$shoes$content$model)
}While one answer is missing, the call stops: the server sends the
client the requests not answered yet, and runs the function again from
the start once it has them, so the code before ask() runs
once per round and must not change anything. A 2026-07-28 client gets
them in an input_required result, with the answers so far
in requestState, signed with HMAC-SHA256 together with the
method, the name or URI, a digest of the arguments and an expiry an hour
later: a retry with a requestState the server did not give
for that call, or that has expired, gets -32602. The key is
MORDEW_STATE_KEY, or a random one per process. A 2025-11-25
client gets each request as elicitation/create,
sampling/createMessage or roots/list, and the
server runs the function again with the answers. ask()
checks the answer to a form before it gives it to the function: an
action other than accept, decline
or cancel, or an accepted content that does
not fit the fields of the form, ends the call with an
isError result naming the field. input_form()
takes the types of an MCP form only: strings, numbers, integers,
booleans and choices. A pattern goes in the form, where a
client may ignore it: the server applies it to the answer.
can_ask() tells whether the client declared what a request
needs; a request it did not declare gets -32021 for 2026-07-28 and an
isError result for 2025-11-25. A completion cannot ask. A
task of a 2026-07-28 client that asks waits in
input_required, its requests in the
inputRequests of tasks/get, until
tasks/update has answered them all, then runs the tool
again with the answers; a task of a 2025-11-25 client that asks fails.
In tests, call_tool(), get_prompt() and
read_resource() answer every form with answer,
every text of the model with sample and the roots with
roots, a character vector of URIs; a client given none of
them declares none of these capabilities.
Cancellation
A client that no longer needs an answer sends
notifications/cancelled with the ID of its request: the
server takes the call out of the queue, or stops the worker running it,
which then serves the next call, and sends no answer; over HTTP, the
POST gets an empty SSE stream. It writes the reason on stderr. It
ignores a cancellation of a request it does not know or has answered, of
a request from another client or without a session, and of a call that
runs as a task, which tasks/cancel stops. A worker that
ignores the interrupt (compiled code) keeps running the call, as at its
timeout.