Class: BioRuby::MCP::Server::KEGGCompoundTool

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

Overview

KEGG compound information 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



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/bioruby/mcp/server/kegg_tools.rb', line 102

def call(compound_id:, server_context: nil)
  # Clean up compound ID if needed
  compound_id = compound_id.gsub(/^(cpd:|compound:)/, '')
  
  # Get compound entry from KEGG REST API
  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

  # Parse the compound data using BioRuby
  compound = Bio::KEGG::COMPOUND.new(compound_data)
  
  ::MCP::Tool::Response.new([{
    type: 'text',
    text: "KEGG Compound: #{compound_id}\n" \
          "Name: #{compound.name}\n" \
          "Formula: #{compound.formula}\n" \
          "Mass: #{compound.mass}\n" \
          "Comment: #{compound.comment}\n" \
          "Pathways: #{compound.pathways&.length || 0} pathways\n" \
          "Enzymes: #{compound.enzymes&.length || 0} enzymes"
  }])
rescue => e
  ::MCP::Tool::Response.new([{
    type: 'text',
    text: "Error retrieving compound info: #{e.message}"
  }])
end