15#include <unordered_map>
18#include "cxxmcp/core/executor.hpp"
25namespace mcp::server {
64 std::optional<protocol::TaskRequestParameters>
task;
100 const protocol::TaskListParams& params = {});
116 std::optional<protocol::ProgressToken> progress_token;
117 std::chrono::steady_clock::time_point started_at;
118 std::optional<std::chrono::steady_clock::time_point> terminal_at;
119 std::optional<std::chrono::seconds> timeout;
121 std::optional<protocol::Json> result;
122 std::optional<core::Error> failure;
127 std::optional<protocol::ProgressToken> progress_token;
130 static std::string now_timestamp();
133 std::string make_task_id();
134 core::Error task_not_found_error(std::string_view task_id)
const;
135 TaskRecord* find_task_locked(std::string_view task_id);
136 const TaskRecord* find_task_locked(std::string_view task_id)
const;
138 void refresh_locked(std::vector<TaskUpdate>* updates =
nullptr);
139 void trim_completed_locked();
140 void append_update_locked(std::vector<TaskUpdate>* updates,
141 const TaskRecord& record)
const;
142 void emit_updates(
const std::vector<TaskUpdate>& updates)
const;
144 TaskOperationProcessorOptions options_;
146 mutable std::mutex mutex_;
147 std::unordered_map<std::string, TaskRecord> tasks_;
148 std::vector<std::string> order_;
149 std::uint64_t next_task_index_ = 1;
Owner side of a cooperative cancellation token.
Definition cancellation.hpp:212
Copyable token observed by cancellation-aware SDK operations.
Definition cancellation.hpp:104
Thread pool executor with priority queues and a timer wheel.
Definition executor.hpp:55
Interface for integrating a JSON Schema validator implementation.
Definition schema_validator.hpp:35
RMCP-style operation processor for server-side task execution.
Definition task_manager.hpp:78
core::Result< protocol::Task > get_task(const protocol::TaskGetParams ¶ms)
Get one task snapshot.
core::Result< protocol::CreateTaskResult > submit_tool_call(const ToolRegistry &tools, protocol::ToolCall call, const SessionContext &context, const JsonSchemaValidator *schema_validator=nullptr)
Submit a tools/call request for background execution.
core::Result< protocol::TaskListResult > list_tasks(const protocol::TaskListParams ¶ms={})
List retained task snapshots.
core::Result< protocol::CreateTaskResult > submit_operation(TaskOperationDescriptor descriptor, TaskOperationHandler operation)
Submit a generic background operation.
core::Result< protocol::Task > cancel_task(const protocol::TaskCancelParams ¶ms)
Cancel a running task or return an existing terminal snapshot.
core::Result< protocol::Json > task_result(const protocol::TaskResultParams ¶ms)
Return the stored result JSON for a completed task.
void stop() noexcept
Stops accepting background work and waits for workers to finish.
In-memory registries and handler contracts for server capabilities.
Shared result and error primitives used by the public cxxmcp SDK.
tl::expected< T, Error > Result
Alias for the SDK result type.
Definition result.hpp:64
Server-side transport abstraction for MCP JSON-RPC traffic.
Structured error returned by fallible SDK operations.
Definition result.hpp:35
Parameters for notifications/progress.
Definition types.hpp:226
Parameters for tasks/cancel.
Definition task.hpp:234
Parameters for tasks/get.
Definition task.hpp:209
Snapshot of an asynchronous task.
Definition task.hpp:144
Per-message connection metadata supplied to server handlers.
Definition transport.hpp:42
Metadata for a background operation managed as an MCP task.
Definition task_manager.hpp:60
std::string name
Human-readable operation name used for diagnostics.
Definition task_manager.hpp:62
std::optional< protocol::TaskRequestParameters > task
Optional task request metadata supplied by the peer.
Definition task_manager.hpp:64
std::optional< protocol::ProgressToken > progress_token
Optional progress token from request _meta.progressToken.
Definition task_manager.hpp:66
Options for the SDK server task processor.
Definition task_manager.hpp:35
TaskStatusNotificationHook task_status_hook
Optional hook for automatic notifications/tasks/status emission.
Definition task_manager.hpp:51
TaskProgressNotificationHook task_progress_hook
Optional hook for automatic notifications/progress emission.
Definition task_manager.hpp:53
std::optional< std::int64_t > poll_interval
Recommended polling interval exposed in created task snapshots.
Definition task_manager.hpp:43
std::size_t worker_count
Worker threads used to execute background operations.
Definition task_manager.hpp:37
std::optional< std::chrono::milliseconds > completed_task_ttl
Optional age limit for terminal task records and stored results.
Definition task_manager.hpp:45
std::size_t list_page_size
Maximum tasks returned by one tasks/list page. Zero means unbounded.
Definition task_manager.hpp:49
std::size_t queue_size
Maximum queued background operations.
Definition task_manager.hpp:39
std::chrono::seconds default_timeout
Default timeout for task execution when a request omits ttl.
Definition task_manager.hpp:41
bool emit_progress_for_task_state_changes
Emit progress updates from task state changes when a progress token exists.
Definition task_manager.hpp:56
std::size_t max_completed_tasks
Maximum retained terminal task records.
Definition task_manager.hpp:47
Asynchronous task status and task-management payloads.
TaskStatus
Lifecycle status for an asynchronous MCP task.
Definition task.hpp:28
std::function< void(const protocol::ProgressNotificationParams &)> TaskProgressNotificationHook
Observer called when a task state change can be mapped to progress.
Definition task_manager.hpp:32
std::function< core::Result< protocol::Json >(const CancellationToken &)> TaskOperationHandler
Callable executed by the task processor.
Definition task_manager.hpp:71
std::function< void(const protocol::Task &)> TaskStatusNotificationHook
Observer called after a task snapshot changes.
Definition task_manager.hpp:28