Class: PromptObjects::MCP::Tools::RespondToRequest

Inherits:
MCP::Tool
  • Object
show all
Defined in:
lib/prompt_objects/mcp/tools/respond_to_request.rb

Overview

Respond to a pending capability-approval request.

Class Method Summary collapse

Class Method Details

.call(request_id:, response:, server_context:) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/prompt_objects/mcp/tools/respond_to_request.rb', line 26

def self.call(request_id:, response:, server_context:)
  env = server_context[:env]
  queue = env.human_queue

  # Find the request first to give better error messages
  request = queue.all_pending.find { |r| r.id == request_id }

  unless request
    return ::MCP::Tool::Response.new([{
      type: "text",
      text: JSON.generate({
        error: "Request not found",
        request_id: request_id,
        hint: "Use get_pending_requests to see available requests"
      })
    }])
  end

  # Respond (this unblocks the waiting thread)
  queue.respond(request_id, response)

  # Log to message bus
  env.bus.publish(
    from: "mcp_client",
    to: request.capability,
    message: "[response to pending request] #{response}"
  )

  ::MCP::Tool::Response.new([{
    type: "text",
    text: JSON.generate({
      success: true,
      request_id: request_id,
      capability: request.capability,
      question: request.question,
      response: response
    })
  }])
end