Class: McpInspector::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/mcp_inspector/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = [], local_options = {}, config = {}) ⇒ CLI

Returns a new instance of CLI.



27
28
29
30
# File 'lib/mcp_inspector/cli.rb', line 27

def initialize(args = [], local_options = {}, config = {})
  super
  setup_global_options
end

Class Method Details

.exit_on_failure?Boolean

Returns:



16
17
18
# File 'lib/mcp_inspector/cli.rb', line 16

def exit_on_failure?
  true
end

Instance Method Details

#config(action, name_or_path = nil) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/mcp_inspector/cli.rb', line 109

def config(action, name_or_path = nil)
  case action
  when "list"
    config_list
  when "show"
    config_show(name_or_path)
  when "init"
    config_init(name_or_path)
  else
    warn "Invalid config action '#{action}'. Valid options: list, show, init"
    exit(1)
  end
end

#execute(tool_name) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/mcp_inspector/cli.rb', line 49

def execute(tool_name)
  with_server_connection do |adapter, output_adapter|
    input_adapter = McpInspector::Data::InputAdapter.new
    input_adapter.validate_tool_name!(tool_name)
    
    arguments = input_adapter.parse_json_arguments(options[:args])
    result = adapter.execute_tool(tool_name, arguments)
    
     = ("execute_tool", tool_name)
    output_adapter.output_tool_result(result, )
  end
rescue => e
  handle_error(e)
end

#infoObject



97
98
99
100
101
102
103
104
105
106
# File 'lib/mcp_inspector/cli.rb', line 97

def info
  with_server_connection do |adapter, output_adapter|
    server_info = adapter.server_info
    
     = ("server_info")
    output_adapter.output_server_info(server_info, )
  end
rescue => e
  handle_error(e)
end

#list(type) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/mcp_inspector/cli.rb', line 33

def list(type)
  case type
  when "tools"
    list_tools
  when "resources"
    list_resources
  when "prompts"
    list_prompts
  else
    warn "Invalid list type '#{type}'. Valid options: tools, resources, prompts"
    exit(1)
  end
end

#prompt(prompt_name) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/mcp_inspector/cli.rb', line 81

def prompt(prompt_name)
  with_server_connection do |adapter, output_adapter|
    input_adapter = McpInspector::Data::InputAdapter.new
    input_adapter.validate_prompt_name!(prompt_name)
    
    arguments = input_adapter.parse_json_arguments(options[:args])
    result = adapter.get_prompt(prompt_name, arguments)
    
     = ("get_prompt", prompt_name)
    output_adapter.output_prompt_result(result, )
  end
rescue => e
  handle_error(e)
end

#read(resource_uri) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/mcp_inspector/cli.rb', line 65

def read(resource_uri)
  with_server_connection do |adapter, output_adapter|
    input_adapter = McpInspector::Data::InputAdapter.new
    input_adapter.validate_resource_uri!(resource_uri)
    
    content = adapter.read_resource(resource_uri)
    
     = ("read_resource", resource_uri)
    output_adapter.output_resource_content(content, )
  end
rescue => e
  handle_error(e)
end