Skip to content

Support the core of the Tasks extension - #745

Open
koic wants to merge 1 commit into
modelcontextprotocol:mainfrom
koic:tasks_extension_core
Open

koic wants to merge 1 commit into
modelcontextprotocol:mainfrom
koic:tasks_extension_core

Conversation

@koic

@koic koic commented Dec 3, 2026

Copy link
Copy Markdown
Member

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 #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.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Test update (non-breaking change which adds or updates tests)
  • Refactoring (non-breaking change which makes things better)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • CI/build script update (update CI workflow or build scripts)

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • I have added automated tests for my change
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

## 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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant