Class: Puppeteer::WebMCPTool

Inherits:
Object
  • Object
show all
Includes:
EventCallbackable
Defined in:
lib/puppeteer/web_mcp.rb,
sig/puppeteer/web_mcp.rbs

Overview

rbs_inline: enabled

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from EventCallbackable

#add_event_listener, #emit_event, #observe_first, #off, #on_event, #remove_event_listener

Constructor Details

#initialize(web_mcp, tool, frame) ⇒ Object

Parameters:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/puppeteer/web_mcp.rb', line 10

def initialize(web_mcp, tool, frame)
  @web_mcp = web_mcp
  @name = tool['name']
  @description = tool['description']
  @input_schema = tool['inputSchema']
  @annotations = tool['annotations']
  @frame = frame
  @backend_node_id = tool['backendNodeId']
  @raw_stack_trace = tool['stackTrace']
  @form_element = nil

  call_frame = @raw_stack_trace&.fetch('callFrames', [])&.first
  if call_frame
    @location = Puppeteer::ConsoleMessage::Location.new(
      url: call_frame['url'],
      line_number: call_frame['lineNumber'],
      column_number: call_frame['columnNumber'],
    )
  end
end

Instance Attribute Details

#annotationsObject (readonly)

Returns the value of attribute annotations.

Returns:

  • (Object)


31
32
33
# File 'lib/puppeteer/web_mcp.rb', line 31

def annotations
  @annotations
end

#descriptionObject (readonly)

Returns the value of attribute description.

Returns:

  • (Object)


31
32
33
# File 'lib/puppeteer/web_mcp.rb', line 31

def description
  @description
end

#frameObject (readonly)

Returns the value of attribute frame.

Returns:

  • (Object)


31
32
33
# File 'lib/puppeteer/web_mcp.rb', line 31

def frame
  @frame
end

#input_schemaObject (readonly)

Returns the value of attribute input_schema.

Returns:

  • (Object)


31
32
33
# File 'lib/puppeteer/web_mcp.rb', line 31

def input_schema
  @input_schema
end

#locationObject (readonly)

Returns the value of attribute location.

Returns:

  • (Object)


31
32
33
# File 'lib/puppeteer/web_mcp.rb', line 31

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.

Returns:

  • (Object)


31
32
33
# File 'lib/puppeteer/web_mcp.rb', line 31

def name
  @name
end

#raw_stack_traceObject (readonly)

Returns the value of attribute raw_stack_trace.

Returns:

  • (Object)


31
32
33
# File 'lib/puppeteer/web_mcp.rb', line 31

def raw_stack_trace
  @raw_stack_trace
end

Instance Method Details

#execute(input = {}) ⇒ Puppeteer::WebMCPToolCallResult

Parameters:

  • input (Hash[untyped, untyped]) (defaults to: {})

Returns:



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/puppeteer/web_mcp.rb', line 44

def execute(input = {})
  invocation_id = @web_mcp.invoke_tool(self, input).fetch('invocationId')
  promise = Async::Promise.new
  listener = nil
  listener = @web_mcp.add_event_listener('toolresponded') do |result|
    next unless result.id == invocation_id

    @web_mcp.remove_event_listener(listener)
    promise.resolve(result)
  end
  promise.wait
end

#form_elementPuppeteer::ElementHandle?

Returns:



35
36
37
38
39
40
# File 'lib/puppeteer/web_mcp.rb', line 35

def form_element
  return @form_element if @form_element && !@form_element.disposed?
  return nil unless @backend_node_id

  @form_element = @frame.main_world.adopt_backend_node(@backend_node_id)
end