Class: LinearToonMcp::Tools::Base

Inherits:
MCP::Tool
  • Object
show all
Defined in:
lib/linear_toon_mcp/tools/base.rb

Overview

Base class for all MCP tools. Subclasses implement #perform; responses are TOON-encoded and Error is caught at the boundary. The Linear client is read from LinearToonMcp.client.

class ListTeams < Tools::List
  description "..."
  input_schema(...)
  QUERY = "..."
end

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(server_context: nil, **params) ⇒ MCP::Tool::Response

Entry point invoked by the MCP server. Instantiates the tool and dispatches to its #perform. Any Error raised along the way becomes an error response.

Returns:

  • (MCP::Tool::Response)


23
24
25
26
27
# File 'lib/linear_toon_mcp/tools/base.rb', line 23

def call(server_context: nil, **params)
  new.call(**params)
rescue Error => e
  error_response(e.message)
end

.error_response(message) ⇒ MCP::Tool::Response

Returns an error MCP response carrying message.

Returns:

  • (MCP::Tool::Response)


37
38
39
# File 'lib/linear_toon_mcp/tools/base.rb', line 37

def error_response(message)
  MCP::Tool::Response.new([{type: "text", text: message}], error: true)
end

.success_response(data) ⇒ MCP::Tool::Response

Returns a successful MCP response with TOON-encoded data.

Returns:

  • (MCP::Tool::Response)


31
32
33
# File 'lib/linear_toon_mcp/tools/base.rb', line 31

def success_response(data)
  MCP::Tool::Response.new([{type: "text", text: Toon.encode(data)}])
end

Instance Method Details

#call(**params) ⇒ Object

Runs the tool with validated parameters and returns the MCP response. Subclasses override #perform, not this method. When #perform returns an MCP::Tool::Response, it is passed through unchanged.



46
47
48
49
50
51
# File 'lib/linear_toon_mcp/tools/base.rb', line 46

def call(**params)
  result = perform(**params)
  result.is_a?(MCP::Tool::Response) ? result : self.class.success_response(result)
rescue Error => e
  self.class.error_response(e.message)
end

#performObject

Subclass hook. Returns the Ruby value to TOON-encode, or a pre-built MCP::Tool::Response.

Raises:

  • (NotImplementedError)


55
56
57
# File 'lib/linear_toon_mcp/tools/base.rb', line 55

def perform(**)
  raise NotImplementedError, "#{self.class.name} must implement #perform"
end