Class: BioRuby::MCP::Server::KEGGPathwayFinderTool

Inherits:
MCP::Tool
  • Object
show all
Defined in:
lib/bioruby/mcp/server/kegg_tools.rb

Overview

KEGG pathway finder tool

Constant Summary collapse

KEGG_REST_BASE =
'http://rest.kegg.jp'

Class Method Summary collapse

Class Method Details

.call(compound_id:, server_context: nil) ⇒ Object



293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# File 'lib/bioruby/mcp/server/kegg_tools.rb', line 293

def call(compound_id:, server_context: nil)
  # Clean up compound ID
  compound_id = compound_id.gsub(/^(cpd:|compound:)/, '')
  
  # Get compound info first to find associated pathways
  compound_data = kegg_get_entry(compound_id)
  
  if compound_data.nil? || compound_data.empty?
    return ::MCP::Tool::Response.new([{
      type: 'text',
      text: "Compound not found: #{compound_id}"
    }])
  end

  compound = Bio::KEGG::COMPOUND.new(compound_data)
  
  if compound.pathways.nil? || compound.pathways.empty?
    return ::MCP::Tool::Response.new([{
      type: 'text',
      text: "No pathways found for compound: #{compound_id}"
    }])
  end

  pathway_list = compound.pathways.map do |pathway_id, pathway_name|
    "#{pathway_id}: #{pathway_name}"
  end

  ::MCP::Tool::Response.new([{
    type: 'text',
    text: "Pathways containing compound #{compound_id}:\n#{pathway_list.join("\n")}"
  }])
rescue => e
  ::MCP::Tool::Response.new([{
    type: 'text',
    text: "Error finding pathways: #{e.message}"
  }])
end