Module: CompletionKit::McpTools::Metrics

Extended by:
Base
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"},
        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"},
        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

Methods included from Base

call, definitions, error_result, text_result

Class Method Details

.create(args) ⇒ Object



56
57
58
59
60
61
62
63
# File 'app/services/completion_kit/mcp_tools/metrics.rb', line 56

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

.delete(args) ⇒ Object



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

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

.get(args) ⇒ Object



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

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

.list(_args) ⇒ Object



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

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

.update(args) ⇒ Object



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

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