Class: HTM::MCP::StatsTool

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

Overview

Tool: Get memory statistics

Instance Method Summary collapse

Instance Method Details

#callObject



430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
# File 'lib/htm/mcp/tools.rb', line 430

def call
  htm = Session.htm_instance
  robot = HTM::Models::Robot[htm.robot_id]
  Session.logger&.info "StatsTool called for robot=#{htm.robot_name}"

  # NOTE: Node uses set_dataset to exclude deleted, so .count returns active nodes
  total_nodes           = HTM::Models::Node.count
  deleted_nodes         = HTM::Models::Node.deleted.count
  nodes_with_embeddings = HTM::Models::Node.with_embeddings.count
  nodes_with_tags       = HTM::Models::Node
                          .join(:node_tags, node_id: :id)
                          .distinct
                          .count
  total_tags            = HTM::Models::Tag.count
  total_robots          = HTM::Models::Robot.count

  Session.logger&.info "StatsTool complete: #{total_nodes} active nodes, #{total_tags} tags"

  {
    success:       true,
    current_robot: {
      name:           htm.robot_name,
      id:             htm.robot_id,
      memory_summary: robot.memory_summary
    },
    statistics: {
      nodes: {
        active:          total_nodes,
        deleted:         deleted_nodes,
        with_embeddings: nodes_with_embeddings,
        with_tags:       nodes_with_tags
      },
      tags: {
        total: total_tags
      },
      robots: {
        total: total_robots
      }
    }
  }.to_json
rescue StandardError => e
  Session.logger&.error "StatsTool error: #{e.message}"
  { success: false, error: e.message }.to_json
end