Module: CompletionKit::McpTools::Metrics

Defined in:
app/services/completion_kit/mcp_tools/metrics.rb

Constant Summary collapse

TOOLS =
{
  "metrics_list" => {
    description: "List all metrics",
    inputSchema: {type: "object", properties: {}, required: []},
    handler: :list
  },
  "metrics_get" => {
    description: "Get a metric by ID",
    inputSchema: {type: "object", properties: {id: {type: "integer"}}, required: ["id"]},
    handler: :get
  },
  "metrics_create" => {
    description: "Create a metric with evaluation criteria",
    inputSchema: {
      type: "object",
      properties: {
        name: {type: "string"}, instruction: {type: "string"},
        evaluation_steps: {type: "array", items: {type: "string"}},
        rubric_bands: {type: "array", items: {type: "object", properties: {stars: {type: "integer"}, description: {type: "string"}}}}
      },
      required: ["name"]
    },
    handler: :create
  },
  "metrics_update" => {
    description: "Update a metric",
    inputSchema: {
      type: "object",
      properties: {
        id: {type: "integer"}, name: {type: "string"}, instruction: {type: "string"},
        evaluation_steps: {type: "array", items: {type: "string"}},
        rubric_bands: {type: "array", items: {type: "object", properties: {stars: {type: "integer"}, description: {type: "string"}}}}
      },
      required: ["id"]
    },
    handler: :update
  },
  "metrics_delete" => {
    description: "Delete a metric",
    inputSchema: {type: "object", properties: {id: {type: "integer"}}, required: ["id"]},
    handler: :delete
  }
}.freeze

Class Method Summary collapse

Class Method Details

.call(name, arguments) ⇒ Object



52
53
54
55
# File 'app/services/completion_kit/mcp_tools/metrics.rb', line 52

def self.call(name, arguments)
  tool = TOOLS.fetch(name)
  send(tool[:handler], arguments)
end

.create(args) ⇒ Object



65
66
67
68
69
70
71
72
# File 'app/services/completion_kit/mcp_tools/metrics.rb', line 65

def self.create(args)
  metric = Metric.new(args.slice("name", "instruction", "evaluation_steps", "rubric_bands"))
  if metric.save
    text_result(metric.as_json)
  else
    error_result(metric.errors.full_messages.join(", "))
  end
end

.definitionsObject



48
49
50
# File 'app/services/completion_kit/mcp_tools/metrics.rb', line 48

def self.definitions
  TOOLS.map { |name, config| {name: name, description: config[:description], inputSchema: config[:inputSchema]} }
end

.delete(args) ⇒ Object



83
84
85
86
# File 'app/services/completion_kit/mcp_tools/metrics.rb', line 83

def self.delete(args)
  Metric.find(args["id"]).destroy!
  text_result("Metric #{args["id"]} deleted")
end

.error_result(message) ⇒ Object



93
94
95
# File 'app/services/completion_kit/mcp_tools/metrics.rb', line 93

def self.error_result(message)
  {content: [{type: "text", text: message}], isError: true}
end

.get(args) ⇒ Object



61
62
63
# File 'app/services/completion_kit/mcp_tools/metrics.rb', line 61

def self.get(args)
  text_result(Metric.find(args["id"]).as_json)
end

.list(_args) ⇒ Object



57
58
59
# File 'app/services/completion_kit/mcp_tools/metrics.rb', line 57

def self.list(_args)
  text_result(Metric.order(created_at: :desc).map(&:as_json))
end

.text_result(data) ⇒ Object



88
89
90
91
# File 'app/services/completion_kit/mcp_tools/metrics.rb', line 88

def self.text_result(data)
  text = data.is_a?(String) ? data : data.to_json
  {content: [{type: "text", text: text}]}
end

.update(args) ⇒ Object



74
75
76
77
78
79
80
81
# File 'app/services/completion_kit/mcp_tools/metrics.rb', line 74

def self.update(args)
  metric = Metric.find(args["id"])
  if metric.update(args.except("id").slice("name", "instruction", "evaluation_steps", "rubric_bands"))
    text_result(metric.as_json)
  else
    error_result(metric.errors.full_messages.join(", "))
  end
end