Skip to content

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

fix(mcp): Don't classify handled timeouts as unexpected errors (#18949)

Ben Bachemef990bd84b25
diff --git a/packages/shared/src/features/query/server/queryExecutor.ts b/packages/shared/src/features/query/server/queryExecutor.ts
index be23afcc91..f2b5db6c5f 100644
--- a/packages/shared/src/features/query/server/queryExecutor.ts
+++ b/packages/shared/src/features/query/server/queryExecutor.ts
@@ -94,6 +94,7 @@ export async function executeQuery(
query: QueryType,
version: ViewVersion = "v1",
enableSingleLevelOptimization = false,
+ options?: Pick<ClickhouseQueryOpts, "clickhouseSettings">,
): Promise<Array<Record<string, unknown>>> {
const prepared = await prepareExecuteQuery({
projectId,
@@ -103,6 +104,10 @@ export async function executeQuery(
});
const chOpts = toClickhouseQueryOpts(prepared);
+ chOpts.clickhouseSettings = {
+ ...chOpts.clickhouseSettings,
+ ...options?.clickhouseSettings,
+ };
if (!prepared.usesTraceTable) {
return queryClickhouse<Record<string, unknown>>(chOpts);
diff --git a/packages/shared/src/server/repositories/events.ts b/packages/shared/src/server/repositories/events.ts
index 4f8022ba81..70f40c42b9 100644
--- a/packages/shared/src/server/repositories/events.ts
+++ b/packages/shared/src/server/repositories/events.ts
@@ -2237,11 +2237,13 @@ const queryEventsFilterOptionRows = async (
| BuiltEventsFilterOptionColumnQuery
| BuiltEventsFilterOptionsForColumnsQuery
| BuiltEventsExactFilterOptionsForColumnsQuery,
+ clickhouseSettings?: ClickHouseSettings,
) => {
return queryClickhouse<EventFilterOptionRow>({
query: queryWithParams.query,
params: queryWithParams.params,
tags: { projectId },
+ clickhouseSettings,
preferredClickhouseService: "EventsReadOnly",
});
};
@@ -2279,6 +2281,7 @@ const queryEventsFilterOptionColumn = async (params: {
offset?: number;
scope?: EventFilterOptionScope;
sampleRows?: number;
+ clickhouseSettings?: ClickHouseSettings;
}) => {
const queryWithParams = buildEventsFilterOptionColumnQuery({
projectId: params.projectId,
@@ -2294,7 +2297,11 @@ const queryEventsFilterOptionColumn = async (params: {
return [];
}
- return queryEventsFilterOptionRows(params.projectId, queryWithParams);
+ return queryEventsFilterOptionRows(
+ params.projectId,
+ queryWithParams,
+ params.clickhouseSettings,
+ );
};
export const getEventsFilterOptionsForColumns = async (params: {
@@ -2341,6 +2348,7 @@ export const getEventsFilterOptionValuesPage = async (params: {
column: EventFilterOptionColumn;
limit: number;
offset: number;
+ clickhouseSettings?: ClickHouseSettings;
}) =>
queryEventsFilterOptionColumn({
projectId: params.projectId,
@@ -2348,6 +2356,7 @@ export const getEventsFilterOptionValuesPage = async (params: {
column: params.column,
limit: params.limit,
offset: params.offset,
+ clickhouseSettings: params.clickhouseSettings,
});
/** EventsMetadataOptionRow is one metadata key or value with its event count. */
@@ -2431,6 +2440,7 @@ export const getEventsNumericStatsByFilterColumn = async (
NumericEventsTableColumnId,
"inputTokens" | "outputTokens" | "inputCost" | "outputCost"
>,
+ clickhouseSettings?: ClickHouseSettings,
) => {
const column = eventsTableCols.find((col) => col.id === columnId);
@@ -2468,6 +2478,7 @@ export const getEventsNumericStatsByFilterColumn = async (
query,
params,
tags: { projectId },
+ clickhouseSettings,
preferredClickhouseService: "EventsReadOnly",
});
const range = res[0];
diff --git a/packages/shared/src/server/repositories/scores.ts b/packages/shared/src/server/repositories/scores.ts
index 7f9bd80fab..e55deb81de 100644
--- a/packages/shared/src/server/repositories/scores.ts
+++ b/packages/shared/src/server/repositories/scores.ts
@@ -22,6 +22,7 @@ import type { ScoreFieldGroupV3 } from "../../features/scores/interfaces/api/v3/
import { filterAndValidateV3GetScoreList } from "../../features/scores/interfaces/api/v3/validation";
import {
commandClickhouse,
+ type ClickhouseQueryOpts,
queryClickhouse,
queryClickhouseStream,
queryClickhouseExecRaw,
@@ -3532,6 +3533,7 @@ export async function listScoresV3ForPublicApi(
cursor?: ScoresCursorV3Type;
fields: ScoreFieldGroupV3[];
} & ListFilterParams,
+ options?: Pick<ClickhouseQueryOpts, "clickhouseSettings">,
): Promise<{ data: APIScoreV3[]; cursor?: string }> {
const { query: filterClause, params: filterParams } =
buildDynamicFilters(params);
@@ -3558,6 +3560,7 @@ export async function listScoresV3ForPublicApi(
),
params: input.params,
tags: input.tags,
+ clickhouseSettings: options?.clickhouseSettings,
preferredClickhouseService: "ReadOnly",
});
diff --git a/web/src/__tests__/server/mcp-error-formatting.servertest.ts b/web/src/__tests__/server/mcp-error-formatting.servertest.ts
index 89b66e709b..079e8ff20c 100644
--- a/web/src/__tests__/server/mcp-error-formatting.servertest.ts
+++ b/web/src/__tests__/server/mcp-error-formatting.servertest.ts
@@ -176,22 +176,27 @@ describe("MCP Error Formatting", () => {
expect(mcpError.code).toBe(ErrorCode.InvalidRequest);
expect(mcpError.message).toContain("ClickHouse query timed out");
expect(mcpError.message).toContain("Narrow the query");
+ expect(mcpError.message).toContain("shortening the date range");
+ expect(mcpError.message).toContain("adding more specific filters");
expect(mcpError.message).not.toContain("internal timeout details");
});
- it("should format other ClickHouse resource errors without internal details", () => {
- const error = new ClickHouseResourceError(
- "MEMORY_LIMIT",
- new Error("Memory limit exceeded at 215 GiB"),
- );
- const mcpError = formatErrorForUser(error);
+ it.each(["MEMORY_LIMIT", "OVERCOMMIT"] as const)(
+ "should format ClickHouse %s errors without internal details",
+ (errorType) => {
+ const error = new ClickHouseResourceError(
+ errorType,
+ new Error("Memory limit exceeded at 215 GiB"),
+ );
+ const mcpError = formatErrorForUser(error);
- expect(mcpError.code).toBe(ErrorCode.InvalidRequest);
- expect(mcpError.message).toContain(
- ClickHouseResourceError.ERROR_ADVICE_MESSAGE,
- );
- expect(mcpError.message).not.toContain("215 GiB");
- });
+ expect(mcpError.code).toBe(ErrorCode.InvalidRequest);
+ expect(mcpError.message).toContain(
+ ClickHouseResourceError.ERROR_ADVICE_MESSAGE,
+ );
+ expect(mcpError.message).not.toContain("215 GiB");
+ },
+ );
it("should format UnauthorizedError with auth message", () => {
const error = new UnauthorizedError("Invalid API key");
diff --git a/web/src/__tests__/server/unit/mcp-clickhouse-settings.servertest.ts b/web/src/__tests__/server/unit/mcp-clickhouse-settings.servertest.ts
new file mode 100644
index 0000000000..657a437f04
--- /dev/null
+++ b/web/src/__tests__/server/unit/mcp-clickhouse-settings.servertest.ts
@@ -0,0 +1,124 @@
+import { beforeEach, describe, expect, it, vi } from "vitest";
+import { env } from "@langfuse/shared/src/env";
+import { executeQuery, QueryBuilder } from "@langfuse/shared/query/server";
+import {
+ listScoresV3ForPublicApi,
+ queryClickhouse,
+} from "@langfuse/shared/src/server";
+import {
+ getEventFilterNumericRange,
+ getEventFilterValuePage,
+} from "@/src/features/events/server/eventsService";
+import { MCP_CLICKHOUSE_SETTINGS } from "@/src/features/mcp/core/clickhouse-settings";
+
+vi.mock(
+ "../../../../../packages/shared/src/server/repositories/clickhouse",
+ async (importOriginal) => ({
+ ...(await importOriginal<Record<string, unknown>>()),
+ queryClickhouse: vi.fn(),
+ }),
+);
+
+describe("MCP ClickHouse execution limits", () => {
+ beforeEach(() => {
+ vi.restoreAllMocks();
+ vi.mocked(queryClickhouse).mockReset().mockResolvedValue([]);
+ });
+
+ it.each(["events_core", "traces"])(
+ "preserves metrics settings and applies the timeout for %s queries",
+ async (table) => {
+ vi.spyOn(QueryBuilder.prototype, "build").mockResolvedValue({
+ query: `SELECT count() FROM ${table}`,
+ parameters: {},
+ });
+
+ await executeQuery(
+ "project-id",
+ {
+ view: "observations",
+ dimensions: [],
+ metrics: [{ measure: "count", aggregation: "count" }],
+ filters: [],
+ timeDimension: null,
+ fromTimestamp: "2026-10-01T00:00:00Z",
+ toTimestamp: "2026-10-02T00:00:00Z",
+ orderBy: null,
+ },
+ "v2",
+ true,
+ { clickhouseSettings: MCP_CLICKHOUSE_SETTINGS },
+ );
+
+ expect(queryClickhouse).toHaveBeenCalledOnce();
+ expect(queryClickhouse).toHaveBeenCalledWith(
+ expect.objectContaining({
+ clickhouseSettings: expect.objectContaining({
+ max_execution_time: 25,
+ date_time_output_format: "iso",
+ max_bytes_before_external_group_by: String(
+ env.CLICKHOUSE_MAX_BYTES_BEFORE_EXTERNAL_GROUP_BY,
+ ),
+ }),
+ }),
+ );
+ },
+ );
+
+ it.each([true, false])(
+ "keeps score query limits opt-in: %s",
+ async (applyLimit) => {
+ await listScoresV3ForPublicApi(
+ {
+ projectId: "project-id",
+ limit: 1,
+ fields: ["core"],
+ },
+ applyLimit
+ ? { clickhouseSettings: MCP_CLICKHOUSE_SETTINGS }
+ : undefined,
+ );
+
+ expect(queryClickhouse).toHaveBeenCalledOnce();
+ expect(queryClickhouse).toHaveBeenCalledWith(
+ expect.objectContaining({
+ clickhouseSettings: applyLimit
+ ? { max_execution_time: 25 }
+ : undefined,
+ }),
+ );
+ },
+ );
+
+ it("passes the limit through categorical filter-value queries", async () => {
+ await getEventFilterValuePage({
+ projectId: "project-id",
+ column: "name",
+ limit: 20,
+ offset: 0,
+ clickhouseSettings: MCP_CLICKHOUSE_SETTINGS,
+ });
+
+ expect(queryClickhouse).toHaveBeenCalledOnce();
+ expect(queryClickhouse).toHaveBeenCalledWith(
+ expect.objectContaining({
+ clickhouseSettings: { max_execution_time: 25 },
+ }),
+ );
+ });
+
+ it("passes the limit through numeric filter-value queries", async () => {
+ await getEventFilterNumericRange({
+ projectId: "project-id",
+ column: "latency",
+ clickhouseSettings: MCP_CLICKHOUSE_SETTINGS,
+ });
+
+ expect(queryClickhouse).toHaveBeenCalledOnce();
+ expect(queryClickhouse).toHaveBeenCalledWith(
+ expect.objectContaining({
+ clickhouseSettings: { max_execution_time: 25 },
+ }),
+ );
+ });
+});
diff --git a/web/src/__tests__/server/unit/run-mcp-tool.servertest.ts b/web/src/__tests__/server/unit/run-mcp-tool.servertest.ts
index 251c5047b1..4099e196a1 100644
--- a/web/src/__tests__/server/unit/run-mcp-tool.servertest.ts
+++ b/web/src/__tests__/server/unit/run-mcp-tool.servertest.ts
@@ -1,5 +1,8 @@
import type { Span } from "@opentelemetry/api";
import { InvalidRequestError } from "@langfuse/shared";
+import { ClickHouseResourceError } from "@langfuse/shared/src/server";
+import { ErrorCode } from "@modelcontextprotocol/sdk/types.js";
+import { formatErrorForUser } from "@/src/features/mcp/core/error-formatting";
import { z } from "zod";
import type { ServerContext } from "@/src/features/mcp/types";
@@ -41,6 +44,35 @@ describe("runMcpTool outcome telemetry", () => {
vi.clearAllMocks();
});
+ it.each(["TIMEOUT", "MEMORY_LIMIT", "OVERCOMMIT"] as const)(
+ "classifies handled ClickHouse %s errors consistently with the response",
+ async (errorType) => {
+ const error = new ClickHouseResourceError(
+ errorType,
+ new Error("sensitive ClickHouse details"),
+ );
+
+ await expect(
+ runMcpTool({
+ spanName: "mcp.test",
+ context,
+ fn: async () => {
+ throw error;
+ },
+ }),
+ ).rejects.toBe(error);
+
+ expect(fakeSpan.setAttribute).toHaveBeenCalledWith(
+ "mcp.outcome",
+ "request_error",
+ );
+ const response = formatErrorForUser(error);
+ expect(response.code).toBe(ErrorCode.InvalidRequest);
+ expect(response.message).toMatch(/date range/);
+ expect(response.message).not.toContain("sensitive ClickHouse details");
+ },
+ );
+
it.each([
{
name: "successful execution",
diff --git a/web/src/features/events/server/eventsService.ts b/web/src/features/events/server/eventsService.ts
index 37ad1f7573..63b6870fff 100644
--- a/web/src/features/events/server/eventsService.ts
+++ b/web/src/features/events/server/eventsService.ts
@@ -26,6 +26,7 @@ import {
EVENTS_APPROX_TOTAL_COUNT_MARKER,
type EventBatchIOResult,
type EventFilterOptionColumn,
+ type ClickhouseQueryOpts,
} from "@langfuse/shared/src/server";
import { aggregateScores } from "@/src/features/scores/server";
type TimeFilter = z.infer<typeof timeFilter>;
@@ -632,6 +633,7 @@ export async function getEventFilterValuePage(
| "promptName";
limit: number;
offset: number;
+ clickhouseSettings?: ClickhouseQueryOpts["clickhouseSettings"];
},
) {
const scopedParams = ensureStartTimeFilterForEventFilterOptions(params);
@@ -645,6 +647,7 @@ export async function getEventFilterValuePage(
column,
limit: queryLimit,
offset,
+ clickhouseSettings: scopedParams.clickhouseSettings,
});
const values = rows.map((row) =>
@@ -668,13 +671,19 @@ export async function getEventFilterNumericRange(
NumericEventsTableColumnId,
"inputTokens" | "outputTokens" | "inputCost" | "outputCost"
>;
+ clickhouseSettings?: ClickhouseQueryOpts["clickhouseSettings"];
},
) {
const scopedParams = ensureStartTimeFilterForEventFilterOptions(params);
const { projectId, column } = scopedParams;
const { eventsFilter } = getEventFilterOptionsScope(scopedParams);
- return getEventsNumericStatsByFilterColumn(projectId, eventsFilter, column);
+ return getEventsNumericStatsByFilterColumn(
+ projectId,
+ eventsFilter,
+ column,
+ scopedParams.clickhouseSettings,
+ );
}
/**
diff --git a/web/src/features/mcp/core/clickhouse-settings.ts b/web/src/features/mcp/core/clickhouse-settings.ts
new file mode 100644
index 0000000000..116b0b32b5
--- /dev/null
+++ b/web/src/features/mcp/core/clickhouse-settings.ts
@@ -0,0 +1,3 @@
+// Leave headroom for sending an actionable error before the load balancer's 30s timeout.
+// Use only for tools that execute a single ClickHouse query per call.
+export const MCP_CLICKHOUSE_SETTINGS = { max_execution_time: 25 } as const;
diff --git a/web/src/features/mcp/core/error-formatting.ts b/web/src/features/mcp/core/error-formatting.ts
index 1e30039a43..5672b330ca 100644
--- a/web/src/features/mcp/core/error-formatting.ts
+++ b/web/src/features/mcp/core/error-formatting.ts
@@ -81,7 +81,7 @@ export function formatErrorForUser(error: unknown): McpError {
return new McpError(
ErrorCode.InvalidRequest,
error.errorType === "TIMEOUT"
- ? "The ClickHouse query timed out. Narrow the query and try again."
+ ? "The ClickHouse query timed out. Narrow the query by shortening the date range or adding more specific filters before trying again."
: ClickHouseResourceError.ERROR_ADVICE_MESSAGE,
);
}
diff --git a/web/src/features/mcp/core/run-mcp-tool.ts b/web/src/features/mcp/core/run-mcp-tool.ts
index 056b145e6d..0a045bf27d 100644
--- a/web/src/features/mcp/core/run-mcp-tool.ts
+++ b/web/src/features/mcp/core/run-mcp-tool.ts
@@ -1,5 +1,9 @@
import { BaseError } from "@langfuse/shared";
-import { addUserToSpan, instrumentAsync } from "@langfuse/shared/src/server";
+import {
+ addUserToSpan,
+ ClickHouseResourceError,
+ instrumentAsync,
+} from "@langfuse/shared/src/server";
import { SpanKind, type Span } from "@opentelemetry/api";
import { ZodError } from "zod";
@@ -48,11 +52,12 @@ export const runMcpTool = async <TResult>({
span.setAttribute("mcp.outcome", "success");
return result;
} catch (error) {
- // Keep telemetry aligned with formatErrorForUser, which reports Zod
- // validation failures as InvalidParams. Response validators should
- // wrap schema-drift failures in a server-side BaseError.
+ // Keep telemetry aligned with formatErrorForUser: resource limits
+ // return actionable query guidance, not an unexpected server failure.
+ // Response validators should wrap schema drift in a server-side BaseError.
const isRequestError =
error instanceof ZodError ||
+ error instanceof ClickHouseResourceError ||
isUserInputError(error) ||
(error instanceof BaseError && error.httpCode < 500);
diff --git a/web/src/features/mcp/server/metrics/tools/queryMetrics.ts b/web/src/features/mcp/server/metrics/tools/queryMetrics.ts
index 1d3a3f117d..f7f7234d09 100644
--- a/web/src/features/mcp/server/metrics/tools/queryMetrics.ts
+++ b/web/src/features/mcp/server/metrics/tools/queryMetrics.ts
@@ -14,6 +14,7 @@ import {
import { defineTool } from "../../../core/define-tool";
import { McpAdvancedFilterBaseSchema } from "../../../core/filter-schema";
import { runMcpTool } from "../../../core/run-mcp-tool";
+import { MCP_CLICKHOUSE_SETTINGS } from "../../../core/clickhouse-settings";
import { clampToDataAccessDays } from "@/src/features/entitlements/server";
import { z } from "zod";
@@ -198,6 +199,7 @@ export const [queryMetricsTool, handleQueryMetrics] = defineTool({
queryParams,
"v2",
true,
+ { clickhouseSettings: MCP_CLICKHOUSE_SETTINGS },
);
return { data: result };
diff --git a/web/src/features/mcp/server/observations/tools/getObservation.ts b/web/src/features/mcp/server/observations/tools/getObservation.ts
index cae34b88d0..1ffa8476fb 100644
--- a/web/src/features/mcp/server/observations/tools/getObservation.ts
+++ b/web/src/features/mcp/server/observations/tools/getObservation.ts
@@ -6,6 +6,7 @@ import {
} from "@langfuse/shared/src/server";
import { defineTool } from "../../../core/define-tool";
import { runMcpTool } from "../../../core/run-mcp-tool";
+import { MCP_CLICKHOUSE_SETTINGS } from "../../../core/clickhouse-settings";
import { clampToDataAccessDays } from "@/src/features/entitlements/server";
import {
ExpandMetadataKeysSchema,
@@ -17,7 +18,6 @@ import {
} from "../schema";
const OBSERVATION_MAX_RANGE_MS = 90 * 24 * 60 * 60 * 1000; // 90 days
-const MCP_OBSERVATIONS_MAX_EXECUTION_TIME_SECONDS = 25;
const GetObservationBaseSchema = z.object({
observationId: z.string().min(1),
@@ -112,9 +112,7 @@ export const [getObservationTool, handleGetObservation] = defineTool({
),
},
{
- clickhouseSettings: {
- max_execution_time: MCP_OBSERVATIONS_MAX_EXECUTION_TIME_SECONDS,
- },
+ clickhouseSettings: MCP_CLICKHOUSE_SETTINGS,
},
);
diff --git a/web/src/features/mcp/server/observations/tools/getObservationFilterValues.ts b/web/src/features/mcp/server/observations/tools/getObservationFilterValues.ts
index a6eb261b40..59bd29f6bf 100644
--- a/web/src/features/mcp/server/observations/tools/getObservationFilterValues.ts
+++ b/web/src/features/mcp/server/observations/tools/getObservationFilterValues.ts
@@ -11,6 +11,7 @@ import {
} from "@/src/features/events/server";
import { defineTool } from "../../../core/define-tool";
import { runMcpTool } from "../../../core/run-mcp-tool";
+import { MCP_CLICKHOUSE_SETTINGS } from "../../../core/clickhouse-settings";
import {
ObservationLimitSchema,
type ObservationMcpFilterColumn,
@@ -200,6 +201,7 @@ export const [
if (isNumericEventsTableColumnId(eventsColumn)) {
const range = await getEventFilterNumericRange({
+ clickhouseSettings: MCP_CLICKHOUSE_SETTINGS,
column: eventsColumn,
projectId: context.projectId,
startTimeFilter,
@@ -219,6 +221,7 @@ export const [
const offset = decodeObservationFilterValueCursor(input.cursor);
const page = await getEventFilterValuePage({
+ clickhouseSettings: MCP_CLICKHOUSE_SETTINGS,
column: eventsColumn,
projectId: context.projectId,
startTimeFilter,
diff --git a/web/src/features/mcp/server/observations/tools/listObservations.ts b/web/src/features/mcp/server/observations/tools/listObservations.ts
index 34958b774c..434c6957c8 100644
--- a/web/src/features/mcp/server/observations/tools/listObservations.ts
+++ b/web/src/features/mcp/server/observations/tools/listObservations.ts
@@ -30,6 +30,7 @@ import {
} from "@/src/features/public-api/server";
import { defineTool } from "../../../core/define-tool";
import { runMcpTool } from "../../../core/run-mcp-tool";
+import { MCP_CLICKHOUSE_SETTINGS } from "../../../core/clickhouse-settings";
import { clampToDataAccessDays } from "@/src/features/entitlements/server";
import {
ExpandMetadataKeysSchema,
@@ -52,7 +53,6 @@ const ObservationCursorSchema =
const OBSERVATION_MAX_RANGE_MS = 14 * 24 * 60 * 60 * 1000; // 14 days
const EXPENSIVE_OBSERVATION_MAX_IO_LIMIT = 50;
-const MCP_OBSERVATIONS_MAX_EXECUTION_TIME_SECONDS = 25;
const OBSERVATION_MCP_FILTER_COLUMN_TYPES = new Map(
eventsTableCols
@@ -424,9 +424,7 @@ export const [listObservationsTool, handleListObservations] = defineTool({
),
},
{
- clickhouseSettings: {
- max_execution_time: MCP_OBSERVATIONS_MAX_EXECUTION_TIME_SECONDS,
- },
+ clickhouseSettings: MCP_CLICKHOUSE_SETTINGS,
},
);
diff --git a/web/src/features/mcp/server/scores/tools/getScore.ts b/web/src/features/mcp/server/scores/tools/getScore.ts
index f4f64b4947..e8a01dec04 100644
--- a/web/src/features/mcp/server/scores/tools/getScore.ts
+++ b/web/src/features/mcp/server/scores/tools/getScore.ts
@@ -2,6 +2,7 @@ import { LangfuseNotFoundError, SCORE_FIELD_GROUPS_V3 } from "@langfuse/shared";
import { z } from "zod";
import { defineTool } from "../../../core/define-tool";
import { runMcpTool } from "../../../core/run-mcp-tool";
+import { MCP_CLICKHOUSE_SETTINGS } from "../../../core/clickhouse-settings";
import { listScoresV3ForPublicApi } from "@/src/features/public-api/server";
import { buildScoreSubjectUrl } from "@langfuse/shared/src/server";
@@ -24,12 +25,15 @@ export const [getScoreTool, handleGetScore] = defineTool({
attributes: { "mcp.score_id": input.scoreId },
fn: async () => {
// v3 has no by-id route; a v3 list with an id filter is the lookup path.
- const result = await listScoresV3ForPublicApi({
- projectId: context.projectId,
- limit: 1,
- fields: [...SCORE_FIELD_GROUPS_V3],
- id: [input.scoreId],
- });
+ const result = await listScoresV3ForPublicApi(
+ {
+ projectId: context.projectId,
+ limit: 1,
+ fields: [...SCORE_FIELD_GROUPS_V3],
+ id: [input.scoreId],
+ },
+ { clickhouseSettings: MCP_CLICKHOUSE_SETTINGS },
+ );
const score = result.data[0];
if (!score) {
diff --git a/web/src/features/mcp/server/scores/tools/listScores.ts b/web/src/features/mcp/server/scores/tools/listScores.ts
index 393aed8109..9f6d4a09f9 100644
--- a/web/src/features/mcp/server/scores/tools/listScores.ts
+++ b/web/src/features/mcp/server/scores/tools/listScores.ts
@@ -7,6 +7,7 @@ import {
import { z } from "zod";
import { defineTool } from "../../../core/define-tool";
import { runMcpTool } from "../../../core/run-mcp-tool";
+import { MCP_CLICKHOUSE_SETTINGS } from "../../../core/clickhouse-settings";
import { clampToDataAccessDays } from "@/src/features/entitlements/server";
import {
listScoresV3ForPublicApi,
@@ -177,32 +178,35 @@ export const [listScoresTool, handleListScores] = defineTool({
plan: context.plan,
fromTimestamp: input.fromTimestamp,
});
- const result = await listScoresV3ForPublicApi({
- projectId: context.projectId,
- limit: input.limit,
- cursor: input.cursor ? parseCursor(input.cursor) : undefined,
- // Always fetch every field group: subject feeds the url mapping below.
- fields: [...SCORE_FIELD_GROUPS_V3],
- id: input.scoreIds,
- name: input.name,
- source: input.source,
- dataType: input.dataType,
- environment: input.environment,
- configId: input.configId,
- queueId: input.queueId,
- authorUserId: input.authorUserId,
- value: input.value,
- valueMin: input.valueMin,
- valueMax: input.valueMax,
- traceId: input.traceId,
- sessionId: input.sessionId,
- observationId: input.observationId,
- experimentId: input.experimentId,
- fromTimestamp: dataAccessWindow.effectiveFromTimestamp,
- toTimestamp: input.toTimestamp
- ? new Date(input.toTimestamp)
- : undefined,
- });
+ const result = await listScoresV3ForPublicApi(
+ {
+ projectId: context.projectId,
+ limit: input.limit,
+ cursor: input.cursor ? parseCursor(input.cursor) : undefined,
+ // Always fetch every field group: subject feeds the url mapping below.
+ fields: [...SCORE_FIELD_GROUPS_V3],
+ id: input.scoreIds,
+ name: input.name,
+ source: input.source,
+ dataType: input.dataType,
+ environment: input.environment,
+ configId: input.configId,
+ queueId: input.queueId,
+ authorUserId: input.authorUserId,
+ value: input.value,
+ valueMin: input.valueMin,
+ valueMax: input.valueMax,
+ traceId: input.traceId,
+ sessionId: input.sessionId,
+ observationId: input.observationId,
+ experimentId: input.experimentId,
+ fromTimestamp: dataAccessWindow.effectiveFromTimestamp,
+ toTimestamp: input.toTimestamp
+ ? new Date(input.toTimestamp)
+ : undefined,
+ },
+ { clickhouseSettings: MCP_CLICKHOUSE_SETTINGS },
+ );
const data = result.data.map((score) => {
const url = buildScoreSubjectUrl(context.projectId, score.subject);