Class: Foobara::McpConnector::Request

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

Defined Under Namespace

Classes: FoobaraCommandsDoNotAcceptArraysError, MethodNotYetSupportedError

Constant Summary

Constants included from TruncatedInspect

TruncatedInspect::MAX_LENGTH

Instance Attribute Summary collapse

Attributes inherited from JsonrpcRequest

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

Attributes inherited from CommandConnector::Request

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

Instance Method Summary collapse

Methods inherited from JsonrpcRequest

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

Methods inherited from CommandConnector::Request

#authenticate, #authenticator, #error_collection, #initialize, #mutate_request, #outcome, #relevant_entity_classes, #response_body, #result, #serializer

Methods included from NestedTransactionable

#auto_detect_current_transactions, #commit_transaction, #commit_transaction_if_open, #open_transaction, #opened_transactions, #relevant_entity_classes, relevant_entity_classes_for_type, #relevant_entity_classes_for_type, #rollback_transaction, #transactions, #use_transaction, with_needed_transactions_for_type

Methods included from Concern

foobara_class_methods_module_for, foobara_concern?, included

Methods included from TruncatedInspect

#inspect, truncating

Constructor Details

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

Instance Attribute Details

#action_loadedObject

Returns the value of attribute action_loaded.



14
15
16
# File 'foobara-mcp-connector-0.0.5/src/request.rb', line 14

def action_loaded
  @action_loaded
end

Instance Method Details

#actionObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'foobara-mcp-connector-0.0.5/src/request.rb', line 61

def action
  self.action_loaded = true

  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.new(message: "#{method} not yet supported!")
  else
    self.error = InvalidJsonrpcMethodError.new(message: "Unknown method: #{method}")
    error.set_backtrace(caller)
    nil
  end
end

#error?Boolean

Returns:

  • (Boolean)


56
57
58
59
# File 'foobara-mcp-connector-0.0.5/src/request.rb', line 56

def error?
  action unless action_loaded
  super
end

#full_command_nameObject



16
17
18
19
20
21
22
# File 'foobara-mcp-connector-0.0.5/src/request.rb', line 16

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



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'foobara-mcp-connector-0.0.5/src/request.rb', line 24

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(
                     message: "Foobara commands do not accept arrays as inputs"
                   )
                 else
                   InvalidJsonrpcParamsError.new(
                     message: "Invalid MCP arguments structure. Expected a hash got a #{inputs.class}"
                   )
                 end

    error.set_backtrace(caller)
  end

  inputs
end

#success?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'foobara-mcp-connector-0.0.5/src/request.rb', line 52

def success?
  !error && super
end

#tool_call?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'foobara-mcp-connector-0.0.5/src/request.rb', line 48

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