Module: ActionMCP::Server::Handlers::TaskHandler

Includes:
ErrorAware
Included in:
JsonRpcHandler
Defined in:
lib/action_mcp/server/handlers/task_handler.rb

Overview

Handler for MCP 2025-11-25 Tasks feature Tasks provide durable state machines for tracking async request execution

Instance Method Summary collapse

Instance Method Details

#process_tasks(rpc_method, id, params) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/action_mcp/server/handlers/task_handler.rb', line 11

def process_tasks(rpc_method, id, params)
  params ||= {}

  with_error_handling(id) do
    unless params.is_a?(Hash)
      raise JSON_RPC::JsonRpcError.new(:invalid_params, message: "Task params must be an object")
    end

    unless transport.session.protocol_version == "2025-11-25"
      raise JSON_RPC::JsonRpcError.new(:method_not_found,
                                       message: "Tasks are only available in MCP 2025-11-25")
    end

    task_capabilities = negotiated_task_capabilities
    unless task_capabilities
      raise JSON_RPC::JsonRpcError.new(:method_not_found,
                                       message: "Tasks are not available for this session")
    end

    if rpc_method == JsonRpcHandlerBase::Methods::TASKS_LIST && !task_capabilities.key?(:list)
      raise JSON_RPC::JsonRpcError.new(:method_not_found,
                                       message: "Task listing is not available for this session")
    end

    if rpc_method == JsonRpcHandlerBase::Methods::TASKS_CANCEL && !task_capabilities.key?(:cancel)
      raise JSON_RPC::JsonRpcError.new(:method_not_found,
                                       message: "Task cancellation is not available for this session")
    end

    handler = task_method_handlers[rpc_method]
    if handler
      send(handler, id, params)
    else
      Rails.logger.warn("Unknown tasks method: #{rpc_method}")
      raise JSON_RPC::JsonRpcError.new(:method_not_found, message: "Unknown tasks method: #{rpc_method}")
    end
  end
end