Class: LinearToonMcp::Tools::Get

Inherits:
Base
  • Object
show all
Defined in:
lib/linear_toon_mcp/tools/get.rb

Overview

Base class for single-entity read tools. Queries by id and extracts the named entity field; raises a labeled not-found error when the field is nil. The entity field name derives from the class name:

GetIssue.entity_name    # => "issue"
GetProject.entity_name  # => "project"

Subclasses define the QUERY constant and override #variables when the lookup key needs resolving first (e.g., name/slug → UUID).

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

call, #call, error_response, success_response

Class Method Details

.entity(name) ⇒ Object

Overrides the derived GraphQL entity field name.



18
19
20
# File 'lib/linear_toon_mcp/tools/get.rb', line 18

def entity(name)
  @entity = name.to_s
end

.entity_labelObject

Returns the entity label for not-found messages.

GetIssue.entity_label  # => "Issue"


30
31
32
# File 'lib/linear_toon_mcp/tools/get.rb', line 30

def entity_label
  @entity_label ||= name.split("::").last.sub(/\AGet/, "")
end

.entity_nameObject

Returns the GraphQL entity field name.



23
24
25
# File 'lib/linear_toon_mcp/tools/get.rb', line 23

def entity_name
  @entity ||= derive_entity_name
end

.query_stringObject

Returns the GraphQL query — the QUERY constant on the subclass.



35
36
37
# File 'lib/linear_toon_mcp/tools/get.rb', line 35

def query_string
  const_get(:QUERY)
end

Instance Method Details

#not_found_message(id: nil) ⇒ Object

Subclass hook. Returns the not-found error message.



64
65
66
# File 'lib/linear_toon_mcp/tools/get.rb', line 64

def not_found_message(id: nil, **)
  "#{self.class.entity_label} not found: #{id}"
end

#perform(**params) ⇒ Object

Queries query_string with #variables and extracts the entity field.

Raises:

  • (Error)

    when the entity is not found



51
52
53
54
# File 'lib/linear_toon_mcp/tools/get.rb', line 51

def perform(**params)
  data = client.query(self.class.query_string, variables: variables(**params))
  data[self.class.entity_name] or raise Error, not_found_message(**params)
end

#variables(id:) ⇒ Object

Subclass hook. Returns the GraphQL variables hash for #perform. Defaults to {id: id}; override when the lookup key needs resolving first (e.g., name/slug → UUID).



59
60
61
# File 'lib/linear_toon_mcp/tools/get.rb', line 59

def variables(id:, **)
  {id: id}
end