Class: BioRuby::MCP::Server::KEGGPathwayTool

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

Overview

KEGG pathway information tool

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

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



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/bioruby/mcp/server/kegg_tools.rb', line 28

def call(pathway_id:, server_context: nil)
  # Clean up pathway ID if needed
  pathway_id = pathway_id.gsub(/^(pathway:|path:|map:)/, '')
  
  # Get pathway entry from KEGG REST API
  pathway_data = kegg_get_entry(pathway_id)
  
  if pathway_data.nil? || pathway_data.empty?
    return ::MCP::Tool::Response.new([{
      type: 'text',
      text: "Pathway not found: #{pathway_id}"
    }])
  end

  # Parse the pathway data using BioRuby
  pathway = Bio::KEGG::PATHWAY.new(pathway_data)
  
  result = []
  result << {
    type: 'text',
    text: "KEGG Pathway: #{pathway_id}\n" \
          "Name: #{pathway.name}\n" \
          "Description: #{pathway.description}\n" \
          "Class: #{pathway.pathway_class}\n" \
          "Genes: #{pathway.genes&.length || 0} genes\n" \
          "Compounds: #{pathway.compounds&.length || 0} compounds"
  }
  
  if pathway.genes && !pathway.genes.empty?
    gene_list = pathway.genes.first(10).map { |gene_id, name| "#{gene_id}: #{name}" }
    result << {
      type: 'text',
      text: "Sample genes (first 10):\n#{gene_list.join("\n")}"
    }
  end

  ::MCP::Tool::Response.new(result)
rescue => e
  ::MCP::Tool::Response.new([{
    type: 'text',
    text: "Error retrieving pathway info: #{e.message}"
  }])
end