Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

1.2 KB
Raw Blame
import { z } from "zod";
import { defineTool } from "../../../core/define-tool";
import { buildEvaluatorUrl } from "@langfuse/shared/src/server";
import { runMcpTool } from "../../../core/run-mcp-tool";
import { createMcpEvaluatorService } from "../evaluator-service";

const GetEvaluatorInput = z.object({ evaluatorId: z.string() });

export const [getEvaluatorTool, handleGetEvaluator] = defineTool({
  name: "getEvaluator",
  description:
    "Fetch a single evaluator by id, including its LLM prompt, code, or decision-model questions and state mapping, plus how many evaluation rules reference it.",
  action: "evaluator:read",
  baseSchema: GetEvaluatorInput,
  inputSchema: GetEvaluatorInput,
  handler: async (input, context) =>
    runMcpTool({
      spanName: "mcp.evaluators.get",
      context,
      attributes: { "mcp.evaluator_id": input.evaluatorId },
      fn: async () => {
        const evaluator = await createMcpEvaluatorService(context).get(
          context.projectId,
          input.evaluatorId,
        );

        return {
          ...evaluator,
          url: buildEvaluatorUrl({
            projectId: context.projectId,
            evaluatorId: evaluator.id,
          }),
        };
      },
    }),
  readOnlyHint: true,
});