Class: McpInspector::Transport::ServerConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/mcp_inspector/transport/server_config.rb

Defined Under Namespace

Classes: ValidationError

Constant Summary collapse

REQUIRED_FIELDS =
%w[name transport].freeze
STDIO_REQUIRED_FIELDS =
%w[command].freeze
URL_REQUIRED_FIELDS =
%w[url].freeze
VALID_TRANSPORTS =
%w[stdio sse websocket].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_hash) ⇒ ServerConfig

Returns a new instance of ServerConfig.



17
18
19
20
# File 'lib/mcp_inspector/transport/server_config.rb', line 17

def initialize(config_hash)
  @raw_config = config_hash
  validate_and_parse_config!
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



15
16
17
# File 'lib/mcp_inspector/transport/server_config.rb', line 15

def args
  @args
end

#commandObject (readonly)

Returns the value of attribute command.



15
16
17
# File 'lib/mcp_inspector/transport/server_config.rb', line 15

def command
  @command
end

#envObject (readonly)

Returns the value of attribute env.



15
16
17
# File 'lib/mcp_inspector/transport/server_config.rb', line 15

def env
  @env
end

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/mcp_inspector/transport/server_config.rb', line 15

def name
  @name
end

#transportObject (readonly)

Returns the value of attribute transport.



15
16
17
# File 'lib/mcp_inspector/transport/server_config.rb', line 15

def transport
  @transport
end

#urlObject (readonly)

Returns the value of attribute url.



15
16
17
# File 'lib/mcp_inspector/transport/server_config.rb', line 15

def url
  @url
end

#working_directoryObject (readonly)

Returns the value of attribute working_directory.



15
16
17
# File 'lib/mcp_inspector/transport/server_config.rb', line 15

def working_directory
  @working_directory
end

Class Method Details

.from_json(json_string) ⇒ Object



22
23
24
25
26
27
# File 'lib/mcp_inspector/transport/server_config.rb', line 22

def self.from_json(json_string)
  config_hash = JSON.parse(json_string)
  new(config_hash)
rescue JSON::ParserError => e
  raise ValidationError, "Invalid JSON: #{e.message}"
end

Instance Method Details

#sse?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/mcp_inspector/transport/server_config.rb', line 33

def sse?
  transport == "sse"
end

#stdio?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/mcp_inspector/transport/server_config.rb', line 29

def stdio?
  transport == "stdio"
end

#to_hObject



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/mcp_inspector/transport/server_config.rb', line 41

def to_h
  {
    name: name,
    transport: transport,
    command: command,
    args: args,
    env: env,
    working_directory: working_directory,
    url: url
  }.compact
end

#to_json(*args) ⇒ Object



53
54
55
# File 'lib/mcp_inspector/transport/server_config.rb', line 53

def to_json(*args)
  to_h.to_json(*args)
end

#websocket?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/mcp_inspector/transport/server_config.rb', line 37

def websocket?
  transport == "websocket"
end