Module: CompletionKit::McpTools::Runs

Extended by:
Base
Defined in:
app/services/completion_kit/mcp_tools/runs.rb

Constant Summary collapse

TOOLS =
{
  "runs_list" => {
    description: "List all runs",
    inputSchema: {type: "object", properties: {}, required: []},
    handler: :list
  },
  "runs_get" => {
    description: "Get a run by ID",
    inputSchema: {type: "object", properties: {id: {type: "integer"}}, required: ["id"]},
    handler: :get
  },
  "runs_create" => {
    description: "Create a run",
    inputSchema: {
      type: "object",
      properties: {
        name: {type: "string"}, prompt_id: {type: "integer"},
        dataset_id: {type: "integer"}, judge_model: {type: "string"},
        metric_ids: {type: "array", items: {type: "integer"}}
      },
      required: ["name", "prompt_id"]
    },
    handler: :create
  },
  "runs_update" => {
    description: "Update a run",
    inputSchema: {
      type: "object",
      properties: {
        id: {type: "integer"}, name: {type: "string"},
        dataset_id: {type: "integer"}, judge_model: {type: "string"},
        metric_ids: {type: "array", items: {type: "integer"}}
      },
      required: ["id"]
    },
    handler: :update
  },
  "runs_delete" => {
    description: "Delete a run",
    inputSchema: {type: "object", properties: {id: {type: "integer"}}, required: ["id"]},
    handler: :delete
  },
  "runs_generate" => {
    description: "Generate responses for a run using its prompt and dataset",
    inputSchema: {type: "object", properties: {id: {type: "integer"}}, required: ["id"]},
    handler: :generate
  }
}.freeze

Class Method Summary collapse

Methods included from Base

call, definitions, error_result, text_result

Class Method Details

.create(args) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'app/services/completion_kit/mcp_tools/runs.rb', line 63

def self.create(args)
  run = Run.new(args.slice("name", "prompt_id", "dataset_id", "judge_model"))
  if run.save
    run.replace_metrics!(args["metric_ids"])
    text_result(run.reload.as_json)
  else
    error_result(run.errors.full_messages.join(", "))
  end
end

.delete(args) ⇒ Object



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

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

.generate(args) ⇒ Object



88
89
90
91
92
93
94
95
# File 'app/services/completion_kit/mcp_tools/runs.rb', line 88

def self.generate(args)
  run = Run.find(args["id"])
  if run.start!
    text_result(run.reload.as_json)
  else
    text_result(run.failure_summary || run.errors.full_messages.to_sentence)
  end
end

.get(args) ⇒ Object



59
60
61
# File 'app/services/completion_kit/mcp_tools/runs.rb', line 59

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

.list(_args) ⇒ Object



55
56
57
# File 'app/services/completion_kit/mcp_tools/runs.rb', line 55

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

.update(args) ⇒ Object



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

def self.update(args)
  run = Run.find(args["id"])
  if run.update(args.except("id", "metric_ids").slice("name", "dataset_id", "judge_model"))
    run.replace_metrics!(args["metric_ids"]) if args.key?("metric_ids")
    text_result(run.reload.as_json)
  else
    error_result(run.errors.full_messages.join(", "))
  end
end