Repository navigation
Conversation
## Motivation and Context SEP-2663 removed the experimental tasks of the 2025-11-25 specification from the core protocol and defined them again, not wire-compatibly, as the extension `io.modelcontextprotocol/tasks` for 2026-07-28: the server decides per request whether to answer with a task, `tasks/result` and `tasks/list` are gone, and the result is read through `tasks/get`. The SDK did not implement it. This adds its core; `tasks/update` and `notifications/tasks` follow separately. - `Server.new(task_augmentation:)` enables the extension. The callable decides per `tools/call` whether to answer with a `CreateTaskResult`; `:required` refuses a client that did not declare the extension with `-32021`, and any other request from such a client runs synchronously. The task is stored before the result is returned. - `tasks/get` returns the task with its `result` or `error`, and `tasks/cancel` cancels it cooperatively. Both exist on the 2026-07-28 lifecycle only (`-32601` elsewhere) and require the extension in the request's capabilities (`-32021`). - A task belongs to the principal that created it, the issuer, subject and client of the request's token. To anyone else it does not exist: the answer is the `-32602` of an unknown id. A token that names neither a subject nor a client gets no task, since its tasks could not be told apart from those of another such token. Without a token verifier the task id is all a caller presents. - The work runs on a `TaskExecutor` (at most 16 threads by default), and the process holds its tasks in memory. `task_ttl_ms:` and `max_tasks:` bound what is kept: expired tasks are dropped, and asked to stop when still running, whenever a task is looked up or created, and while the bound is reached a request runs synchronously, or is refused when it requires a task. Work that is scheduled and has not ended counts toward the bound. - A tool that raises fails the task, and the task's `error` is the JSON-RPC error a synchronous call would have answered: that of a `RequestHandlerError`, and an internal error that names the tool and nothing else for anything else. The tool does not start once the token of the request that created the task has expired. - A task method that finds no task for the caller is not reported to the exception reporter. - A completion and a cancellation that race record exactly one outcome. - `Server.new(task_store:)` takes an object that keeps a record of each task for the other processes of the server (`write`, `read` and `delete` of a String). Puma workers and instances behind a load balancer share no memory, and the 2026-07-28 lifecycle has no session to route by, so without it a `tasks/get` that reaches another process finds no task. The record is written before the `CreateTaskResult` is returned and after each change, and any process answers `tasks/get` from it once it has checked the owner and the retention itself. The work does not move: only the process that runs a task changes it, and a `tasks/cancel` that reaches another process is acknowledged without effect, which the specification allows. No store is bundled. - Client: `get_task`, `cancel_task`, `wait_task` (which waits at least 0.1 seconds between polls, unless its optional `timeout:` ends sooner) and `call_tool(wait_for_task: true)`. A cancellation ends the wait between polls. - The conformance server serves the fixtures of the scenarios this covers, so `tasks-lifecycle`, `tasks-wire-fields`, `tasks-request-state-removal` and `tasks-required-task-error` leave `conformance/expected_failures.yml`. Part of modelcontextprotocol#391. ## How Has This Been Tested? `test/mcp/server/task_test.rb`, `test/mcp/server/task_manager_test.rb`, `test/mcp/server/task_registry/in_memory_test.rb`, `test/mcp/server/task_executor/thread_test.rb`, `test/mcp/server_tasks_extension_test.rb` `test/mcp/server_task_store_test.rb` and `test/mcp/client_tasks_test.rb`. ## Breaking Changes None. A server without `task_augmentation:` and a client that does not declare the extension behave as before.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
SEP-2663 removed the experimental tasks of the 2025-11-25 specification from the core protocol and defined them again, not wire-compatibly, as the extension
io.modelcontextprotocol/tasksfor 2026-07-28: the server decides per request whether to answer with a task,tasks/resultandtasks/listare gone, and the result is read throughtasks/get. The SDK did not implement it. This adds its core;tasks/updateandnotifications/tasksfollow separately.Server.new(task_augmentation:)enables the extension. The callable decides pertools/callwhether to answer with aCreateTaskResult;:requiredrefuses a client that did not declare the extension with-32021, and any other request from such a client runs synchronously. The task is stored before the result is returned.tasks/getreturns the task with itsresultorerror, andtasks/cancelcancels it cooperatively. Both exist on the 2026-07-28 lifecycle only (-32601elsewhere) and require the extension in the request's capabilities (-32021).-32602of an unknown id. A token that names neither a subject nor a client gets no task, since its tasks could not be told apart from those of another such token. Without a token verifier the task id is all a caller presents.TaskExecutor(at most 16 threads by default), and the process holds its tasks in memory.task_ttl_ms:andmax_tasks:bound what is kept: expired tasks are dropped, and asked to stop when still running, whenever a task is looked up or created, and while the bound is reached a request runs synchronously, or is refused when it requires a task. Work that is scheduled and has not ended counts toward the bound.erroris the JSON-RPC error a synchronous call would have answered: that of aRequestHandlerError, and an internal error that names the tool and nothing else for anything else. The tool does not start once the token of the request that created the task has expired.Server.new(task_store:)takes an object that keeps a record of each task for the other processes of the server (write,readanddeleteof a String). Puma workers and instances behind a load balancer share no memory, and the 2026-07-28 lifecycle has no session to route by, so without it atasks/getthat reaches another process finds no task. The record is written before theCreateTaskResultis returned and after each change, and any process answerstasks/getfrom it once it has checked the owner and the retention itself. The work does not move: only the process that runs a task changes it, and atasks/cancelthat reaches another process is acknowledged without effect, which the specification allows. No store is bundled.get_task,cancel_task,wait_task(which waits at least 0.1 seconds between polls, unless its optionaltimeout:ends sooner) andcall_tool(wait_for_task: true). A cancellation ends the wait between polls.tasks-lifecycle,tasks-wire-fields,tasks-request-state-removalandtasks-required-task-errorleaveconformance/expected_failures.yml.Part of #391.
How Has This Been Tested?
test/mcp/server/task_test.rb,test/mcp/server/task_manager_test.rb,test/mcp/server/task_registry/in_memory_test.rb,test/mcp/server/task_executor/thread_test.rb,test/mcp/server_tasks_extension_test.rbtest/mcp/server_task_store_test.rbandtest/mcp/client_tasks_test.rb.Breaking Changes
None. A server without
task_augmentation:and a client that does not declare the extension behave as before.Types of changes
Checklist