Class: KairosMcp::Tools::ChainExport

Inherits:
BaseTool
  • Object
show all
Defined in:
lib/kairos_mcp/tools/chain_export.rb

Instance Method Summary collapse

Methods inherited from BaseTool

#initialize, #invoke_tool, #to_full_schema, #to_schema

Constructor Details

This class inherits a constructor from KairosMcp::Tools::BaseTool

Instance Method Details

#call(arguments) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/kairos_mcp/tools/chain_export.rb', line 54

def call(arguments)
  # Check if SQLite backend is enabled
  unless SkillsConfig.storage_backend_sqlite?
    return text_content("Error: chain_export only works with SQLite backend. Current backend: #{SkillsConfig.storage_backend}")
  end

  require_relative '../storage/exporter'

  sqlite_config = SkillsConfig.sqlite_config
  db_path = File.expand_path(sqlite_config['path'] || 'storage/kairos.db', base_dir)
  output_dir = arguments['output_dir'] || File.expand_path('storage/export', base_dir)

  # Check if database exists
  unless File.exist?(db_path)
    return text_content("Error: SQLite database not found at #{db_path}")
  end

  # Perform export
  result = Storage::Exporter.export(db_path: db_path, output_dir: output_dir)

  if result[:error]
    return text_content("Export failed: #{result[:error]}")
  end

  output = <<~OUTPUT
    Export completed successfully!

    Output directory: #{output_dir}
    
    Exported:
    - Blocks: #{result[:blocks]}
    - Action logs: #{result[:action_logs]}
    - Knowledge metadata: #{result[:knowledge_meta]}

    Files created:
    - blockchain.json
    - action_log.jsonl
    - knowledge_meta.json
    - manifest.json
  OUTPUT

  text_content(output)
end

#categoryObject



17
18
19
# File 'lib/kairos_mcp/tools/chain_export.rb', line 17

def category
  :chain
end

#descriptionObject



13
14
15
# File 'lib/kairos_mcp/tools/chain_export.rb', line 13

def description
  'Export data from SQLite database to human-readable files (blockchain.json, action_log.jsonl, knowledge_meta.json). Only works when using SQLite backend.'
end

#examplesObject



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/kairos_mcp/tools/chain_export.rb', line 25

def examples
  [
    {
      title: 'Export to default directory',
      code: 'chain_export()'
    },
    {
      title: 'Export to custom directory',
      code: 'chain_export(output_dir: "/path/to/export")'
    }
  ]
end

#input_schemaObject



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/kairos_mcp/tools/chain_export.rb', line 42

def input_schema
  {
    type: 'object',
    properties: {
      output_dir: {
        type: 'string',
        description: 'Directory to export files to. Defaults to storage/export/'
      }
    }
  }
end

#nameObject



9
10
11
# File 'lib/kairos_mcp/tools/chain_export.rb', line 9

def name
  'chain_export'
end


38
39
40
# File 'lib/kairos_mcp/tools/chain_export.rb', line 38

def related_tools
  %w[chain_import chain_status]
end

#usecase_tagsObject



21
22
23
# File 'lib/kairos_mcp/tools/chain_export.rb', line 21

def usecase_tags
  %w[export backup sqlite files blockchain]
end