Class: Mcp::HealthCheck

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

Overview

Probes an MCP server to verify connectivity and count available tools. Used by the CLI list command to show server health status.

Examples:

result = Mcp::HealthCheck.call(name: "sentry", url: "https://mcp.sentry.dev/mcp", headers: {})
result #=> { status: :connected, tools: 5 }

Constant Summary collapse

TIMEOUT =

Health check probe timeout in seconds. Balances responsiveness (CLI shouldn’t hang) vs. giving slow servers a fair chance.

5

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server) ⇒ HealthCheck

Returns a new instance of HealthCheck.



25
26
27
28
# File 'lib/mcp/health_check.rb', line 25

def initialize(server)
  @server = server
  @stdio_transport = nil
end

Class Method Details

.call(server) ⇒ Hash

Returns { status: :connected, tools: Integer } or { status: :failed, error: String }.

Parameters:

  • server (Hash)

    interpolated server config with symbol keys (:name, :url/:command, and :transport)

Returns:

  • (Hash)

    { status: :connected, tools: Integer } or { status: :failed, error: String }



21
22
23
# File 'lib/mcp/health_check.rb', line 21

def self.call(server)
  new(server).call
end

Instance Method Details

#callObject



30
31
32
33
34
35
36
37
38
# File 'lib/mcp/health_check.rb', line 30

def call
  Timeout.timeout(TIMEOUT) { check }
rescue Timeout::Error
  {status: :failed, error: "connection timeout"}
rescue KeyError => key_error
  {status: :failed, error: "missing credential #{key_error.message}"}
rescue => error
  {status: :failed, error: error.message}
end