Class: RobotLab::MCP::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/robot_lab/mcp/server.rb

Overview

Configuration for an MCP server connection

Examples:

WebSocket transport

Server.new(
  name: "neon",
  transport: { type: "ws", url: "ws://localhost:8080" }
)

StdIO transport

Server.new(
  name: "filesystem",
  transport: {
    type: "stdio",
    command: "mcp-server-filesystem",
    args: ["--root", "/data"]
  }
)

Constant Summary collapse

VALID_TRANSPORT_TYPES =

Valid transport types for MCP connections

%w[stdio sse ws websocket streamable-http http].freeze
DEFAULT_TIMEOUT =

Default timeout for MCP requests (in seconds)

15

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, transport:, timeout: nil, description: nil, **_extra) ⇒ Server

Creates a new Server configuration.

Parameters:

  • name (String)

    the server name

  • transport (Hash)

    the transport configuration

  • timeout (Numeric, nil) (defaults to: nil)

    request timeout in seconds (default: 15)

  • description (String, nil) (defaults to: nil)

    human-readable description for server discovery

  • _extra (Hash)

    additional keys are silently ignored for forward compatibility

Raises:

  • (ArgumentError)

    if transport type is invalid or required fields are missing



48
49
50
51
52
53
54
# File 'lib/robot_lab/mcp/server.rb', line 48

def initialize(name:, transport:, timeout: nil, description: nil, **_extra)
  @name = name.to_s
  @description = description.to_s
  @transport = normalize_transport(transport)
  @timeout = normalize_timeout(timeout)
  validate!
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



38
# File 'lib/robot_lab/mcp/server.rb', line 38

attr_reader :name, :transport, :timeout, :description

#nameString (readonly)

Returns the server name.

Returns:

  • (String)

    the server name



38
39
40
# File 'lib/robot_lab/mcp/server.rb', line 38

def name
  @name
end

#timeoutNumeric (readonly)

Returns request timeout in seconds.

Returns:

  • (Numeric)

    request timeout in seconds



38
# File 'lib/robot_lab/mcp/server.rb', line 38

attr_reader :name, :transport, :timeout, :description

#transportHash (readonly)

Returns the transport configuration.

Returns:

  • (Hash)

    the transport configuration



38
# File 'lib/robot_lab/mcp/server.rb', line 38

attr_reader :name, :transport, :timeout, :description

Instance Method Details

#to_hHash

Converts the server configuration to a hash.

Returns:

  • (Hash)


66
67
68
69
70
71
72
73
# File 'lib/robot_lab/mcp/server.rb', line 66

def to_h
  {
    name: name,
    description: description,
    transport: transport,
    timeout: timeout
  }
end

#transport_typeString

Returns the transport type.

Returns:

  • (String)

    the transport type (stdio, sse, ws, etc.)



59
60
61
# File 'lib/robot_lab/mcp/server.rb', line 59

def transport_type
  @transport[:type]
end