Class: LittleGhost::MCP::Definition

Inherits:
Data
  • Object
show all
Defined in:
lib/little_ghost/mcp/types.rb,
lib/little_ghost/mcp/types.rb

Overview

Immutable server-advertised Tool metadata. source_name is always the name sent back to the server; name is the initially generated model-facing name and may later be customized on the generated Tool class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_name:, name:, description:, input_schema:, raw:, output_schema: nil, annotations: {}, title: nil, metadata: {}) ⇒ Definition

Returns a new instance of Definition.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/little_ghost/mcp/types.rb', line 60

def initialize(source_name:, name:, description:, input_schema:, raw:, output_schema: nil,
  annotations: {}, title: nil, metadata: {})
  source_name = String(source_name)
  name = String(name)
  raise ProtocolError, "MCP tool definition must include a name" if source_name.empty?
  raise ConfigurationError, "MCP tool name cannot be empty" if name.empty?

  super(
    source_name: source_name.freeze,
    name: name.freeze,
    description: String(description).freeze,
    input_schema: ImmutableValue.mapping(input_schema, field: "tool inputSchema"),
    output_schema: ImmutableValue.optional_mapping(output_schema, field: "tool outputSchema"),
    annotations: ImmutableValue.mapping(annotations, field: "tool annotations"),
    title: title.nil? ? nil : String(title).freeze,
    metadata: ImmutableValue.mapping(, field: "tool _meta"),
    raw: ImmutableValue.mapping(raw, field: "tool definition")
  )
rescue TypeError
  raise ProtocolError, "MCP tool definition is invalid"
end

Instance Attribute Details

#annotationsObject (readonly)

Returns the value of attribute annotations

Returns:

  • (Object)

    the current value of annotations



49
50
51
# File 'lib/little_ghost/mcp/types.rb', line 49

def annotations
  @annotations
end

#descriptionObject (readonly)

Returns the value of attribute description

Returns:

  • (Object)

    the current value of description



49
50
51
# File 'lib/little_ghost/mcp/types.rb', line 49

def description
  @description
end

#input_schemaObject (readonly)

Returns the value of attribute input_schema

Returns:

  • (Object)

    the current value of input_schema



49
50
51
# File 'lib/little_ghost/mcp/types.rb', line 49

def input_schema
  @input_schema
end

#metadataObject (readonly)

Returns the value of attribute metadata

Returns:

  • (Object)

    the current value of metadata



49
50
51
# File 'lib/little_ghost/mcp/types.rb', line 49

def 
  @metadata
end

#nameObject (readonly)

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



49
50
51
# File 'lib/little_ghost/mcp/types.rb', line 49

def name
  @name
end

#output_schemaObject (readonly)

Returns the value of attribute output_schema

Returns:

  • (Object)

    the current value of output_schema



49
50
51
# File 'lib/little_ghost/mcp/types.rb', line 49

def output_schema
  @output_schema
end

#rawObject (readonly)

Returns the value of attribute raw

Returns:

  • (Object)

    the current value of raw



49
50
51
# File 'lib/little_ghost/mcp/types.rb', line 49

def raw
  @raw
end

#source_nameObject (readonly)

Returns the value of attribute source_name

Returns:

  • (Object)

    the current value of source_name



49
50
51
# File 'lib/little_ghost/mcp/types.rb', line 49

def source_name
  @source_name
end

#titleObject (readonly)

Returns the value of attribute title

Returns:

  • (Object)

    the current value of title



49
50
51
# File 'lib/little_ghost/mcp/types.rb', line 49

def title
  @title
end

Instance Method Details

#[](key) ⇒ Object



82
# File 'lib/little_ghost/mcp/types.rb', line 82

def [](key) = raw[key]

#digObject



84
# File 'lib/little_ghost/mcp/types.rb', line 84

def dig(...) = raw.dig(...)

#fetchObject



83
# File 'lib/little_ghost/mcp/types.rb', line 83

def fetch(...) = raw.fetch(...)

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


85
# File 'lib/little_ghost/mcp/types.rb', line 85

def key?(key) = raw.key?(key)