🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(mcp): omit Unicode regex from score config tool JSON schemas (#14818)
Lysander Kieseld85e7a0121b0
diff --git a/packages/shared/src/domain/score-configs.ts b/packages/shared/src/domain/score-configs.tsindex 59b62e69f5..0aa21733d9 100644--- a/packages/shared/src/domain/score-configs.ts+++ b/packages/shared/src/domain/score-configs.ts@@ -7,11 +7,14 @@ export const ScoreConfigCategory = z.object({value: z.number(),});+export const SCORE_CONFIG_NAME_MIN_LENGTH = 1;+export const SCORE_CONFIG_NAME_MAX_LENGTH = 35;+/** Input-only schema for score config names. Use at API/tRPC boundaries, not for DB reads. */export const ScoreConfigNameSchema = z.string()- .min(1)- .max(35)+ .min(SCORE_CONFIG_NAME_MIN_LENGTH)+ .max(SCORE_CONFIG_NAME_MAX_LENGTH).regex(/^[\p{L}\p{N}_ .()-]+$/u, "Name contains invalid characters");// Numeric config fieldsdiff --git a/web/src/__tests__/server/mcp-public-api-tools.servertest.ts b/web/src/__tests__/server/mcp-public-api-tools.servertest.tsindex d762b165a7..5b070fcb72 100644--- a/web/src/__tests__/server/mcp-public-api-tools.servertest.ts+++ b/web/src/__tests__/server/mcp-public-api-tools.servertest.ts@@ -885,3 +885,57 @@ describe("MCP public API tools", () => {});});});++describe("MCP tool schema interoperability", () => {+ /** Recursively collect all JSON Schema `pattern` values with their location. */+ const collectPatterns = (+ schema: unknown,+ path: string[] = [],+ ): { path: string; pattern: string }[] => {+ if (typeof schema !== "object" || schema === null) return [];++ if (Array.isArray(schema)) {+ return schema.flatMap((item, index) =>+ collectPatterns(item, [...path, String(index)]),+ );+ }++ const obj = schema as Record<string, unknown>;+ const ownPattern =+ typeof obj.pattern === "string"+ ? [{ path: path.join("."), pattern: obj.pattern }]+ : [];++ return [+ ...ownPattern,+ ...Object.entries(obj).flatMap(([key, value]) =>+ collectPatterns(value, [...path, key]),+ ),+ ];+ };++ const getAllToolPatterns = () =>+ toolRegistry.getFeatures().flatMap((feature) =>+ feature.tools.flatMap((tool) =>+ collectPatterns(tool.definition.inputSchema).map((entry) => ({+ tool: tool.definition.name,+ ...entry,+ })),+ ),+ );++ it("advertises no pattern that requires the ECMAScript `u` flag", () => {+ // JSON Schema `pattern` is an ECMA-262 regex compiled WITHOUT the `u` flag.+ // Unicode-only escapes (`\p{...}`, `\P{...}`, `\u{...}`) don't merely fail+ // OpenAI/Vertex validation — without `u` they silently degrade instead of+ // throwing: e.g. `^[\p{L}\p{N}_ .()-]+$` collapses to a literal class+ // `[pLN{}...]` that REJECTS valid ASCII like "quality". Because those+ // providers validate the whole tool catalog atomically, a single such+ // pattern disables every Langfuse MCP tool.+ const offending = getAllToolPatterns().filter(({ pattern }) =>+ /\\[pP]\{|\\u\{/.test(pattern),+ );++ expect(offending).toEqual([]);+ });+});diff --git a/web/src/__tests__/server/mcp-tools-read.servertest.ts b/web/src/__tests__/server/mcp-tools-read.servertest.tsindex 7f632b7a58..1284c109d3 100644--- a/web/src/__tests__/server/mcp-tools-read.servertest.ts+++ b/web/src/__tests__/server/mcp-tools-read.servertest.ts@@ -2434,6 +2434,20 @@ describe("MCP Read Tools", () => {),).rejects.toThrow(/minValue/i);});++ it("should reject invalid name characters at runtime despite the relaxed advertised schema", async () => {+ const { context } = await createMcpTestSetup();++ await expect(+ handleCreateScoreConfig(+ {+ name: "css-injection}*{background:red}/*",+ dataType: "TEXT",+ },+ context,+ ),+ ).rejects.toThrow(/invalid characters/i);+ });});describe("updateScoreConfig tool", () => {@@ -2520,6 +2534,20 @@ describe("MCP Read Tools", () => {).rejects.toThrow(/minValue/i);});+ it("should reject invalid name characters at runtime despite the relaxed advertised schema", async () => {+ const { context } = await createMcpTestSetup();++ await expect(+ handleUpdateScoreConfig(+ {+ configId: randomUUID(),+ name: "css-injection}*{background:red}/*",+ },+ context,+ ),+ ).rejects.toThrow(/invalid characters/i);+ });+it("should not archive score configs through update", async () => {const { context, projectId } = await createMcpTestSetup();const config = await prisma.scoreConfig.create({diff --git a/web/src/__tests__/server/unit/mcp-define-tool.servertest.ts b/web/src/__tests__/server/unit/mcp-define-tool.servertest.tsindex fc91d96a60..7dacbdcae8 100644--- a/web/src/__tests__/server/unit/mcp-define-tool.servertest.ts+++ b/web/src/__tests__/server/unit/mcp-define-tool.servertest.ts@@ -105,4 +105,24 @@ describe("defineTool", () => {}),).toThrow("Union and intersection schemas are not supported");});++ it("preserves ASCII-safe patterns", () => {+ const schema = z.object({+ label: z.string().regex(/^[a-z0-9_\-.]+$/),+ });++ const [tool] = defineTool({+ name: "asciiPatternTool",+ description: "",+ baseSchema: schema,+ inputSchema: schema,+ handler: async (input) => input,+ });++ expect(tool.inputSchema.properties).toEqual(+ expect.objectContaining({+ label: expect.objectContaining({ pattern: "^[a-z0-9_\\-.]+$" }),+ }),+ );+ });});diff --git a/web/src/features/mcp/features/scores/schema.ts b/web/src/features/mcp/features/scores/schema.tsindex 59a086a447..3978bbd64c 100644--- a/web/src/features/mcp/features/scores/schema.ts+++ b/web/src/features/mcp/features/scores/schema.ts@@ -1,9 +1,19 @@-import { ScoreConfigNameSchema } from "@langfuse/shared";+import {+ SCORE_CONFIG_NAME_MAX_LENGTH,+ SCORE_CONFIG_NAME_MIN_LENGTH,+} from "@langfuse/shared";import { z } from "zod";-const McpScoreConfigNameSchema = ScoreConfigNameSchema.describe(- "Allowed characters: letters, numbers, spaces, underscores, periods, parentheses, and hyphens.",-);+// Deliberately not reusing ScoreConfigNameSchema: its Unicode-aware regex is+// not representable in MCP JSON Schema, character rules are+// still enforced at runtime via the strict input schemas.+const McpScoreConfigNameSchema = z+ .string()+ .min(SCORE_CONFIG_NAME_MIN_LENGTH)+ .max(SCORE_CONFIG_NAME_MAX_LENGTH)+ .describe(+ "Allowed characters: letters, numbers, spaces, underscores, periods, parentheses, and hyphens.",+ );const McpScoreConfigNumericMinValueSchema = z.number()