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
  },
  "runs_judge" => {
    description: "Judge responses for a run using configured metrics",
    inputSchema: {type: "object", properties: {id: {type: "integer"}}, required: ["id"]},
    handler: :judge
  }
}.freeze

Class Method Summary collapse

Methods included from Base

call, definitions, error_result, text_result

Class Method Details

.create(args) ⇒ Object



68
69
70
71
72
73
74
75
76
# File 'app/services/completion_kit/mcp_tools/runs.rb', line 68

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



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

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

.generate(args) ⇒ Object



93
94
95
96
97
# File 'app/services/completion_kit/mcp_tools/runs.rb', line 93

def self.generate(args)
  run = Run.find(args["id"])
  GenerateJob.perform_later(run.id)
  text_result(run.reload.as_json)
end

.get(args) ⇒ Object



64
65
66
# File 'app/services/completion_kit/mcp_tools/runs.rb', line 64

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

.judge(args) ⇒ Object



99
100
101
102
103
# File 'app/services/completion_kit/mcp_tools/runs.rb', line 99

def self.judge(args)
  run = Run.find(args["id"])
  JudgeJob.perform_later(run.id)
  text_result(run.reload.as_json)
end

.list(_args) ⇒ Object



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

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

.update(args) ⇒ Object



78
79
80
81
82
83
84
85
86
# File 'app/services/completion_kit/mcp_tools/runs.rb', line 78

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