Class: SwarmSDK::V3::MCP::ServerDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/swarm_sdk/v3/mcp/server_definition.rb

Overview

Immutable value object for MCP server configuration

Supports two transport types:

  • ‘:stdio` — spawns a subprocess and communicates via JSON-RPC over stdin/stdout

  • ‘:http` — connects to an HTTP MCP endpoint

Examples:

Stdio server

ServerDefinition.new(
  name: :filesystem,
  type: :stdio,
  command: "npx",
  args: ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"],
)

HTTP server with tool filtering

ServerDefinition.new(
  name: :api,
  type: :http,
  url: "https://example.com/mcp",
  headers: { "Authorization" => "Bearer token" },
  tools: [:read_file, :list_directory],
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, type:, tools: nil, **options) ⇒ ServerDefinition

Create a new server definition

Examples:

ServerDefinition.new(name: :api, type: :http, url: "https://example.com/mcp")

Disable SSL verification

ServerDefinition.new(name: :api, type: :http, url: "https://localhost/mcp", ssl_verify: false)

Parameters:

  • name (Symbol, String)

    Server identifier

  • type (Symbol, String)

    Transport type (:stdio or :http)

  • tools (Array<Symbol, String>, nil) (defaults to: nil)

    Tool names to expose (nil = all)

  • command (String, nil)

    Subprocess command (stdio)

  • args (Array<String>)

    Subprocess arguments (stdio)

  • env (Hash)

    Subprocess environment variables (stdio)

  • url (String, nil)

    HTTP endpoint URL (http)

  • headers (Hash)

    HTTP headers (http)

  • ssl_verify (Boolean, nil)

    Override global SSL verification (nil = use global)

Raises:



75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/swarm_sdk/v3/mcp/server_definition.rb', line 75

def initialize(name:, type:, tools: nil, **options)
  @name = name.to_sym
  @type = type.to_sym
  @command = options[:command]
  @args = Array(options[:args]).freeze
  @env = (options[:env] || {}).transform_keys(&:to_s).freeze
  @url = options[:url]
  @headers = (options[:headers] || {}).freeze
  @ssl_verify = options[:ssl_verify]
  @tools = tools ? Array(tools).map(&:to_sym).freeze : nil

  validate!
  freeze
end

Instance Attribute Details

#argsArray<String> (readonly)

Returns Subprocess arguments (stdio only).

Returns:

  • (Array<String>)

    Subprocess arguments (stdio only)



42
43
44
# File 'lib/swarm_sdk/v3/mcp/server_definition.rb', line 42

def args
  @args
end

#commandString? (readonly)

Returns Subprocess command (stdio only).

Returns:

  • (String, nil)

    Subprocess command (stdio only)



39
40
41
# File 'lib/swarm_sdk/v3/mcp/server_definition.rb', line 39

def command
  @command
end

#envHash<String, String> (readonly)

Returns Subprocess environment variables (stdio only).

Returns:

  • (Hash<String, String>)

    Subprocess environment variables (stdio only)



45
46
47
# File 'lib/swarm_sdk/v3/mcp/server_definition.rb', line 45

def env
  @env
end

#headersHash<String, String> (readonly)

Returns HTTP headers (http only).

Returns:

  • (Hash<String, String>)

    HTTP headers (http only)



51
52
53
# File 'lib/swarm_sdk/v3/mcp/server_definition.rb', line 51

def headers
  @headers
end

#nameSymbol (readonly)

Returns Server identifier.

Returns:

  • (Symbol)

    Server identifier



30
31
32
# File 'lib/swarm_sdk/v3/mcp/server_definition.rb', line 30

def name
  @name
end

#ssl_verifyBoolean? (readonly)

Returns Per-server SSL verification override (nil = use global config).

Returns:

  • (Boolean, nil)

    Per-server SSL verification override (nil = use global config)



54
55
56
# File 'lib/swarm_sdk/v3/mcp/server_definition.rb', line 54

def ssl_verify
  @ssl_verify
end

#toolsArray<Symbol>? (readonly)

Returns Tool names to expose (nil = all).

Returns:

  • (Array<Symbol>, nil)

    Tool names to expose (nil = all)



36
37
38
# File 'lib/swarm_sdk/v3/mcp/server_definition.rb', line 36

def tools
  @tools
end

#typeSymbol (readonly)

Returns Transport type (:stdio or :http).

Returns:

  • (Symbol)

    Transport type (:stdio or :http)



33
34
35
# File 'lib/swarm_sdk/v3/mcp/server_definition.rb', line 33

def type
  @type
end

#urlString? (readonly)

Returns HTTP endpoint URL (http only).

Returns:

  • (String, nil)

    HTTP endpoint URL (http only)



48
49
50
# File 'lib/swarm_sdk/v3/mcp/server_definition.rb', line 48

def url
  @url
end

Instance Method Details

#filter_tools?Boolean

Whether this definition filters exposed tools

Examples:

defn = ServerDefinition.new(name: :api, type: :http, url: "...", tools: [:echo])
defn.filter_tools? #=> true

defn = ServerDefinition.new(name: :api, type: :http, url: "...")
defn.filter_tools? #=> false

Returns:

  • (Boolean)

    true if a specific tool list was provided



100
101
102
# File 'lib/swarm_sdk/v3/mcp/server_definition.rb', line 100

def filter_tools?
  !@tools.nil?
end