🪢 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
feat(mcp): add listPrompts updatedAt range filters (#11832)
Matt Owen8756ea9ed0c1
diff --git a/web/src/__tests__/async/mcp-tools-read.servertest.ts b/web/src/__tests__/async/mcp-tools-read.servertest.tsindex d1d41d1179..7c007f0859 100644--- a/web/src/__tests__/async/mcp-tools-read.servertest.ts+++ b/web/src/__tests__/async/mcp-tools-read.servertest.ts@@ -16,6 +16,7 @@ jest.mock("@langfuse/shared/src/server", () => {});import { nanoid } from "nanoid";+import { prisma } from "@langfuse/shared/src/db";import {createMcpTestSetup,createPromptInDb,@@ -407,6 +408,130 @@ describe("MCP Read Tools", () => {}});+ it("should filter by fromUpdatedAt", async () => {+ const { context, projectId } = await createMcpTestSetup();+ const oldPrompt = `filter-from-updated-${nanoid()}`;+ const newPrompt = `filter-from-updated-${nanoid()}`;++ const oldDate = new Date("2026-01-01T00:00:00.000Z");+ const newDate = new Date("2026-02-01T00:00:00.000Z");++ await prisma.prompt.create({+ data: {+ name: oldPrompt,+ prompt: "old",+ labels: [],+ tags: [],+ type: "text",+ version: 1,+ config: {},+ createdBy: "test-user",+ createdAt: oldDate,+ updatedAt: oldDate,+ project: { connect: { id: projectId } },+ },+ });++ await prisma.prompt.create({+ data: {+ name: newPrompt,+ prompt: "new",+ labels: [],+ tags: [],+ type: "text",+ version: 1,+ config: {},+ createdBy: "test-user",+ createdAt: newDate,+ updatedAt: newDate,+ project: { connect: { id: projectId } },+ },+ });++ const result = (await handleListPrompts(+ {+ fromUpdatedAt: "2026-01-15T00:00:00.000Z",+ page: 1,+ limit: 100,+ },+ context,+ )) as { data: Array<{ name: string }> };++ const names = result.data.map((p) => p.name);+ expect(names).toContain(newPrompt);+ expect(names).not.toContain(oldPrompt);+ });++ it("should filter by toUpdatedAt", async () => {+ const { context, projectId } = await createMcpTestSetup();+ const oldPrompt = `filter-to-updated-${nanoid()}`;+ const newPrompt = `filter-to-updated-${nanoid()}`;++ const oldDate = new Date("2026-01-01T00:00:00.000Z");+ const newDate = new Date("2026-02-01T00:00:00.000Z");++ await prisma.prompt.create({+ data: {+ name: oldPrompt,+ prompt: "old",+ labels: [],+ tags: [],+ type: "text",+ version: 1,+ config: {},+ createdBy: "test-user",+ createdAt: oldDate,+ updatedAt: oldDate,+ project: { connect: { id: projectId } },+ },+ });++ await prisma.prompt.create({+ data: {+ name: newPrompt,+ prompt: "new",+ labels: [],+ tags: [],+ type: "text",+ version: 1,+ config: {},+ createdBy: "test-user",+ createdAt: newDate,+ updatedAt: newDate,+ project: { connect: { id: projectId } },+ },+ });++ const result = (await handleListPrompts(+ {+ toUpdatedAt: "2026-01-15T00:00:00.000Z",+ page: 1,+ limit: 100,+ },+ context,+ )) as { data: Array<{ name: string }> };++ const names = result.data.map((p) => p.name);+ expect(names).toContain(oldPrompt);+ expect(names).not.toContain(newPrompt);+ });++ it("should return error when fromUpdatedAt is after toUpdatedAt", async () => {+ const { context } = await createMcpTestSetup();++ await expect(+ handleListPrompts(+ {+ fromUpdatedAt: "2026-02-02T00:00:00.000Z",+ toUpdatedAt: "2026-02-01T00:00:00.000Z",+ page: 1,+ limit: 50,+ },+ context,+ ),+ ).rejects.toThrow(/fromUpdatedAt.*<=.*toUpdatedAt/i);+ });+it("should handle pagination with page and limit", async () => {const { context, projectId } = await createMcpTestSetup();diff --git a/web/src/features/mcp/README.md b/web/src/features/mcp/README.mdindex 2794c3a121..45ebbfa856 100644--- a/web/src/features/mcp/README.md+++ b/web/src/features/mcp/README.md@@ -48,7 +48,7 @@ The MCP server provides 6 tools for prompt management:- **`getPrompt`** - Fetch a specific prompt by name with optional label or version (fully resolved with dependencies)- **`getPromptUnresolved`** - Fetch a specific prompt WITHOUT resolving dependencies (useful for prompt composition analysis)-- **`listPrompts`** - List all prompts in the project with filtering and pagination+- **`listPrompts`** - List all prompts in the project with filtering (name/label/tag/updatedAt range) and pagination- **`createTextPrompt`** - Create a new text prompt version- **`createChatPrompt`** - Create a new chat prompt version (OpenAI-style messages)- **`updatePromptLabels`** - Add/move labels across prompt versionsdiff --git a/web/src/features/mcp/features/prompts/tools/listPrompts.ts b/web/src/features/mcp/features/prompts/tools/listPrompts.tsindex db0469d11c..9248b27613 100644--- a/web/src/features/mcp/features/prompts/tools/listPrompts.ts+++ b/web/src/features/mcp/features/prompts/tools/listPrompts.ts@@ -17,6 +17,20 @@ import { getPromptsMeta } from "@/src/features/prompts/server/actions/getPromptsimport { instrumentAsync } from "@langfuse/shared/src/server";import { SpanKind } from "@opentelemetry/api";+const ParamFromUpdatedAt = z.iso+ .datetime({ offset: true })+ .optional()+ .describe(+ "Filter prompts updated at or after this timestamp (ISO 8601 with timezone, e.g. 2026-02-02T00:00:00Z)",+ );++const ParamToUpdatedAt = z.iso+ .datetime({ offset: true })+ .optional()+ .describe(+ "Filter prompts updated at or before this timestamp (ISO 8601 with timezone, e.g. 2026-02-02T00:00:00Z)",+ );+/*** Base schema for listPrompts tool (no refinements needed)*/@@ -28,10 +42,32 @@ const ListPromptsBaseSchema = z.object({"Filter by label (e.g., 'production', 'staging')",),tag: ParamPromptTag.describe("Filter by tag (e.g., 'experimental', 'v1')"),+ fromUpdatedAt: ParamFromUpdatedAt,+ toUpdatedAt: ParamToUpdatedAt,page: ParamPage,limit: ParamLimit,});+/**+ * Full input schema with runtime validations+ */+const ListPromptsInputSchema = ListPromptsBaseSchema.superRefine(+ (data, ctx) => {+ if (data.fromUpdatedAt && data.toUpdatedAt) {+ const fromMs = Date.parse(data.fromUpdatedAt);+ const toMs = Date.parse(data.toUpdatedAt);++ if (Number.isFinite(fromMs) && Number.isFinite(toMs) && fromMs > toMs) {+ ctx.addIssue({+ code: "custom",+ path: ["fromUpdatedAt"],+ message: "fromUpdatedAt must be <= toUpdatedAt",+ });+ }+ }+ },+);+/*** listPrompts tool definition and handler*/@@ -44,16 +80,19 @@ export const [listPromptsTool, handleListPrompts] = defineTool({"- name: Filter by exact prompt name","- label: Filter by label on any version","- tag: Filter by tag",+ "- fromUpdatedAt: Filter prompts updated at or after this timestamp",+ "- toUpdatedAt: Filter prompts updated at or before this timestamp","","Pagination: page (default: 1), limit (default: 50, max: 100)",].join("\n"),baseSchema: ListPromptsBaseSchema,- inputSchema: ListPromptsBaseSchema, // No refinements, same as base+ inputSchema: ListPromptsInputSchema,handler: async (input, context) => {return await instrumentAsync({ name: "mcp.prompts.list", spanKind: SpanKind.INTERNAL },async (span) => {- const { name, label, tag, page, limit } = input;+ const { name, label, tag, fromUpdatedAt, toUpdatedAt, page, limit } =+ input;// Set span attributes for observabilityspan.setAttributes({@@ -73,6 +112,12 @@ export const [listPromptsTool, handleListPrompts] = defineTool({if (tag) {span.setAttribute("mcp.filter_tag", tag);}+ if (fromUpdatedAt) {+ span.setAttribute("mcp.filter_fromUpdatedAt", fromUpdatedAt);+ }+ if (toUpdatedAt) {+ span.setAttribute("mcp.filter_toUpdatedAt", toUpdatedAt);+ }// Fetch prompts metadata using existing serviceconst result = await getPromptsMeta({@@ -80,6 +125,8 @@ export const [listPromptsTool, handleListPrompts] = defineTool({name,label,tag,+ fromUpdatedAt,+ toUpdatedAt,page, // Default handled by Zod schemalimit, // Default handled by Zod schema});