Class: Foobara::McpConnector::Request

Inherits:
JsonrpcRequest show all
Defined in:
foobara-mcp-connector-0.0.4/src/request.rb

Defined Under Namespace

Classes: FoobaraCommandsDoNotAcceptArraysError, MethodNotYetSupportedError

Constant Summary

Constants included from TruncatedInspect

TruncatedInspect::MAX_LENGTH

Instance Attribute Summary

Attributes inherited from JsonrpcRequest

#batch, #is_batch_child, #parsed_request_body, #raw_request_json, #request_id

Attributes inherited from CommandConnector::Request

#command, #command_class, #command_connector, #error, #response, #serializers

Instance Method Summary collapse

Methods inherited from JsonrpcRequest

#batch?, #batch_child?, #error?, #initialize, #method, #notification?, #params, #set_parsed_json, #valid_batch?, #validate_batch_not_empty, #validate_request_structure, #verify_jsonrpc_version

Methods inherited from CommandConnector::Request

#error_collection, #initialize, #outcome, #response_body, #result, #serializer

Methods included from TruncatedInspect

#inspect, truncating

Constructor Details

This class inherits a constructor from Foobara::McpConnector::JsonrpcRequest

Instance Method Details

#actionObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'foobara-mcp-connector-0.0.4/src/request.rb', line 49

def action
  case method
  when "tools/call"
    "run"
  when "tools/list"
    "list"
  when "initialize", "ping",
    "notifications/initialized", "notifications/cancelled", "notifications/progress",
    "notifications/roots/list_changed"
    method
  when "completion/complete", "logging/setLevel", "prompts/get", "prompts/list",
    "resources/list", "resources/read", "resources/subscribe", "resources/unsubscribe"
    raise MethodNotYetSupportedError, "#{method} not yet supported!"
  else
    self.error = InvalidJsonrpcMethodError.new("Unknown method: #{method}")
    error.set_backtrace(caller)
    nil
  end
end

#full_command_nameObject



9
10
11
12
13
14
15
# File 'foobara-mcp-connector-0.0.4/src/request.rb', line 9

def full_command_name
  return if error || batch?

  return @full_command_name if defined?(@full_command_name)

  @full_command_name = parsed_request_body&.[]("params")&.[]("name")
end

#inputsObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'foobara-mcp-connector-0.0.4/src/request.rb', line 17

def inputs
  return if error || batch?

  return @inputs if defined?(@inputs)

  @inputs = parsed_request_body&.[]("params")&.[]("arguments") || {}

  unless inputs.is_a?(::Hash)
    self.error = if inputs.is_a?(::Array)
                   FoobaraCommandsDoNotAcceptArraysError.new(
                     "Foobara commands do not accept arrays as inputs"
                   )
                 else
                   InvalidJsonrpcParamsError.new(
                     "Invalid MCP arguments structure. Expected a hash got a #{inputs.class}"
                   )
                 end

    error.set_backtrace(caller)
  end

  inputs
end

#success?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'foobara-mcp-connector-0.0.4/src/request.rb', line 45

def success?
  !error && super
end

#tool_call?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'foobara-mcp-connector-0.0.4/src/request.rb', line 41

def tool_call?
  !batch? && method == "tools/call"
end