Class: TrakFlow::Mcp::Tools::BaseTool

Inherits:
FastMcp::Tool
  • Object
show all
Defined in:
lib/trak_flow/mcp/tools/base_tool.rb

Class Method Summary collapse

Class Method Details

.with_databaseObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/trak_flow/mcp/tools/base_tool.rb', line 8

def with_database
  TrakFlow.ensure_initialized!

  db = Storage::Database.new
  db.connect

  jsonl = Storage::Jsonl.new
  jsonl.import(db) if jsonl.exists?

  result = yield db

  jsonl.export(db) if db.dirty?

  result
ensure
  db&.close
end