Class: McpInspector::Data::InputAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/mcp_inspector/data/input_adapter.rb

Defined Under Namespace

Classes: ValidationError

Instance Method Summary collapse

Constructor Details

#initialize(args = [], options = {}) ⇒ InputAdapter

Returns a new instance of InputAdapter.



10
11
12
13
# File 'lib/mcp_inspector/data/input_adapter.rb', line 10

def initialize(args = [], options = {})
  @args = args
  @options = options
end

Instance Method Details

#parse_json_arguments(json_string) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/mcp_inspector/data/input_adapter.rb', line 15

def parse_json_arguments(json_string)
  return {} if json_string.nil? || json_string.empty?

  JSON.parse(json_string)
rescue JSON::ParserError => e
  raise ValidationError, "Invalid JSON arguments: #{e.message}\nExpected format: '{\"key\": \"value\"}'"
end

#transform_to_operation_params(command, subcommand = nil, *args) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/mcp_inspector/data/input_adapter.rb', line 55

def transform_to_operation_params(command, subcommand = nil, *args)
  {
    command: command,
    subcommand: subcommand,
    target: args.first,
    arguments: parse_json_arguments(@options[:args])
  }.compact
end

#validate_config_file!(config_path) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/mcp_inspector/data/input_adapter.rb', line 45

def validate_config_file!(config_path)
  unless File.exist?(config_path)
    raise ValidationError, "Configuration file not found: #{config_path}"
  end

  unless File.readable?(config_path)
    raise ValidationError, "Configuration file is not readable: #{config_path}"
  end
end

#validate_prompt_name!(prompt_name) ⇒ Object

Raises:



41
42
43
# File 'lib/mcp_inspector/data/input_adapter.rb', line 41

def validate_prompt_name!(prompt_name)
  raise ValidationError, "Prompt name is required" if prompt_name.nil? || prompt_name.empty?
end

#validate_resource_uri!(uri) ⇒ Object

Raises:



37
38
39
# File 'lib/mcp_inspector/data/input_adapter.rb', line 37

def validate_resource_uri!(uri)
  raise ValidationError, "Resource URI is required" if uri.nil? || uri.empty?
end

#validate_server_name!(server_name, available_servers) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/mcp_inspector/data/input_adapter.rb', line 23

def validate_server_name!(server_name, available_servers)
  return if available_servers.include?(server_name)

  if available_servers.empty?
    raise ValidationError, "No servers configured. Please add servers to your configuration file."
  else
    raise ValidationError, "Server '#{server_name}' not found. Available servers: #{available_servers.join(', ')}"
  end
end

#validate_tool_name!(tool_name) ⇒ Object

Raises:



33
34
35
# File 'lib/mcp_inspector/data/input_adapter.rb', line 33

def validate_tool_name!(tool_name)
  raise ValidationError, "Tool name is required" if tool_name.nil? || tool_name.empty?
end