Class: GrowwMcp::Tools::GetInstrumentDetail

Inherits:
BaseTool
  • Object
show all
Defined in:
lib/groww_mcp/tools/instrument_tools.rb

Class Method Summary collapse

Class Method Details

.call(server_context:, trading_symbol:, exchange: "NSE", segment: "CASH") ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/groww_mcp/tools/instrument_tools.rb', line 69

def call(server_context:, trading_symbol:, exchange: "NSE", segment: "CASH")
  client = server_context[:client]
  result = client.instrument_detail(trading_symbol, exchange: exchange, segment: segment)
  if result.nil?
    return MCP::Tool::Response.new([{
      type: "text",
      text: "No instrument found for '#{trading_symbol}' (#{exchange}/#{segment}). " \
            "Try search_instruments to find the exact trading symbol.",
    }])
  end

  format_response(result)
rescue GrowwMcp::ApiError => e
  error_response(e)
end