Skip to content

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

feat(mcp): Improve prompt label handling on creation (don't allow creating prompt with production label directly) (#14879)

Lysander Kiesel613caeb4ebdb
diff --git a/web/src/__tests__/server/mcp-tools-write.servertest.ts b/web/src/__tests__/server/mcp-tools-write.servertest.ts
index f715d4abe4..67ec7967a2 100644
--- a/web/src/__tests__/server/mcp-tools-write.servertest.ts
+++ b/web/src/__tests__/server/mcp-tools-write.servertest.ts
@@ -503,15 +503,15 @@ describe("MCP Write Tools", () => {
expect(result.message).toContain("Successfully created");
});
- it("should create text prompt with labels", async () => {
+ it("should create text prompt with non-production labels", async () => {
const { context } = await createMcpTestSetup();
const promptName = `text-prompt-${nanoid()}`;
const result = (await handleCreateTextPrompt(
{
name: promptName,
- prompt: "Production prompt",
- labels: ["production", "stable"],
+ prompt: "Staged prompt",
+ labels: ["staged", "stable"],
},
context,
)) as {
@@ -520,9 +520,25 @@ describe("MCP Write Tools", () => {
};
expect(result.labels).toEqual(
- expect.arrayContaining(["production", "stable"]),
+ expect.arrayContaining(["staged", "stable"]),
);
- expect(result.message).toContain("production");
+ expect(result.message).toContain("staged");
+ });
+
+ it("should reject text prompt creation with the production label", async () => {
+ const { context } = await createMcpTestSetup();
+ const promptName = `text-prompt-${nanoid()}`;
+
+ await expect(
+ handleCreateTextPrompt(
+ {
+ name: promptName,
+ prompt: "Production prompt",
+ labels: ["production"],
+ },
+ context,
+ ),
+ ).rejects.toThrow(/production.*cannot be assigned/i);
});
it("should create text prompt with config", async () => {
@@ -683,14 +699,14 @@ describe("MCP Write Tools", () => {
{
name: promptName,
prompt: "Test",
- labels: ["latest", "production"],
+ labels: ["latest", "stable"],
},
context,
)) as { labels: string[] };
- // Should have 'latest' (auto) and 'production' (user-provided)
+ // Should have 'latest' (auto) and 'stable' (user-provided)
expect(result.labels).toContain("latest");
- expect(result.labels).toContain("production");
+ expect(result.labels).toContain("stable");
});
it("should set createdBy to API", async () => {
@@ -741,7 +757,7 @@ describe("MCP Write Tools", () => {
expect(result.message).toContain("Successfully created");
});
- it("should create chat prompt with labels", async () => {
+ it("should create chat prompt with non-production labels", async () => {
const { context } = await createMcpTestSetup();
const promptName = `chat-prompt-${nanoid()}`;
@@ -749,14 +765,30 @@ describe("MCP Write Tools", () => {
{
name: promptName,
prompt: [{ role: "system", content: "System instruction" }],
- labels: ["production"],
+ labels: ["staged"],
},
context,
)) as {
labels: string[];
};
- expect(result.labels).toContain("production");
+ expect(result.labels).toContain("staged");
+ });
+
+ it("should reject chat prompt creation with the production label", async () => {
+ const { context } = await createMcpTestSetup();
+ const promptName = `chat-prompt-${nanoid()}`;
+
+ await expect(
+ handleCreateChatPrompt(
+ {
+ name: promptName,
+ prompt: [{ role: "system", content: "System instruction" }],
+ labels: ["production"],
+ },
+ context,
+ ),
+ ).rejects.toThrow(/production.*cannot be assigned/i);
});
it("should create chat prompt with multiple message roles", async () => {
@@ -1068,12 +1100,12 @@ describe("MCP Write Tools", () => {
{
name: promptName,
prompt: "Test",
- labels: ["production"],
+ labels: ["stable"],
},
context,
)) as { version: number; labels: string[] };
- expect(created.labels).toContain("production");
+ expect(created.labels).toContain("stable");
expect(created.labels).toContain("latest");
// The updatePromptLabels action ADDS labels, not replaces them
@@ -1091,7 +1123,7 @@ describe("MCP Write Tools", () => {
// Should have all labels: original + new
expect(result.labels).toContain("latest");
- expect(result.labels).toContain("production");
+ expect(result.labels).toContain("stable");
expect(result.labels).toContain("staging");
});
diff --git a/web/src/features/mcp/features/prompts/tools/createChatPrompt.ts b/web/src/features/mcp/features/prompts/tools/createChatPrompt.ts
index 6f30306011..45773f6254 100644
--- a/web/src/features/mcp/features/prompts/tools/createChatPrompt.ts
+++ b/web/src/features/mcp/features/prompts/tools/createChatPrompt.ts
@@ -9,7 +9,6 @@ import { defineTool } from "../../../core/define-tool";
import {
CreatePromptSchema,
PromptType,
- PromptLabelSchema,
PromptNameSchema,
COMMIT_MESSAGE_MAX_LENGTH,
PROMPT_NAME_MAX_LENGTH,
@@ -17,6 +16,7 @@ import {
import { createPromptForApi } from "@/src/features/prompts/server/prompt-api-service";
import { buildPromptUrl } from "@/src/utils/product-url";
import { runMcpTool } from "../../../core/run-mcp-tool";
+import { ParamCreatePromptLabels } from "../validation";
/**
* Schema for a single chat message (role + content)
@@ -44,7 +44,9 @@ const CreateChatPromptBaseSchema = z.object({
labels: z
.array(z.string())
.optional()
- .describe("Labels to assign (e.g., ['production', 'staging'])"),
+ .describe(
+ "Optional labels to assign, excluding 'production'. New prompt versions receive the 'latest' label automatically.",
+ ),
config: z
.record(z.string(), z.any())
.optional()
@@ -70,7 +72,7 @@ const CreateChatPromptInputSchema = z.object({
prompt: z
.array(ChatMessageSchema)
.min(1, "Chat prompts must have at least one message"),
- labels: z.array(PromptLabelSchema).optional(),
+ labels: ParamCreatePromptLabels,
config: z.record(z.string(), z.any()).optional(),
tags: z.array(z.string()).optional(),
commitMessage: z.string().max(COMMIT_MESSAGE_MAX_LENGTH).optional(),
@@ -87,7 +89,9 @@ export const [createChatPromptTool, handleCreateChatPrompt] = defineTool({
"Important:",
"- Prompts are immutable - cannot modify existing versions",
"- To update content, create a new version",
- "- To promote to production, use updatePromptLabels",
+ "- New prompt versions receive the 'latest' label automatically",
+ "- Cannot assign the 'production' label during creation",
+ "- To promote to production, use updatePromptLabels only when the user explicitly requests it",
"- Labels are unique across versions",
"",
"Message roles: system (instructions), user (input, can contain {{variables}}), assistant (examples)",
diff --git a/web/src/features/mcp/features/prompts/tools/createTextPrompt.ts b/web/src/features/mcp/features/prompts/tools/createTextPrompt.ts
index 7580c80b84..f9db15ed5a 100644
--- a/web/src/features/mcp/features/prompts/tools/createTextPrompt.ts
+++ b/web/src/features/mcp/features/prompts/tools/createTextPrompt.ts
@@ -9,7 +9,6 @@ import { defineTool } from "../../../core/define-tool";
import {
CreatePromptSchema,
PromptType,
- PromptLabelSchema,
PromptNameSchema,
COMMIT_MESSAGE_MAX_LENGTH,
PROMPT_NAME_MAX_LENGTH,
@@ -17,6 +16,7 @@ import {
import { createPromptForApi } from "@/src/features/prompts/server/prompt-api-service";
import { buildPromptUrl } from "@/src/utils/product-url";
import { runMcpTool } from "../../../core/run-mcp-tool";
+import { ParamCreatePromptLabels } from "../validation";
/**
* Base schema for JSON Schema generation (MCP client display)
@@ -34,7 +34,9 @@ const CreateTextPromptBaseSchema = z.object({
labels: z
.array(z.string())
.optional()
- .describe("Labels to assign (e.g., ['production', 'staging'])"),
+ .describe(
+ "Optional labels to assign, excluding 'production'. New prompt versions receive the 'latest' label automatically.",
+ ),
config: z
.record(z.string(), z.any())
.optional()
@@ -58,7 +60,7 @@ const CreateTextPromptBaseSchema = z.object({
const CreateTextPromptInputSchema = z.object({
name: PromptNameSchema,
prompt: z.string(),
- labels: z.array(PromptLabelSchema).optional(),
+ labels: ParamCreatePromptLabels,
config: z.record(z.string(), z.any()).optional(),
tags: z.array(z.string()).optional(),
commitMessage: z.string().max(COMMIT_MESSAGE_MAX_LENGTH).optional(),
@@ -75,7 +77,9 @@ export const [createTextPromptTool, handleCreateTextPrompt] = defineTool({
"Important:",
"- Prompts are immutable - cannot modify existing versions",
"- To update content, create a new version",
- "- To promote to production, use updatePromptLabels",
+ "- New prompt versions receive the 'latest' label automatically",
+ "- Cannot assign the 'production' label during creation",
+ "- To promote to production, use updatePromptLabels only when the user explicitly requests it",
"- Labels are unique across versions",
"- Use {{variable_name}} syntax for dynamic content",
"",
diff --git a/web/src/features/mcp/features/prompts/tools/updatePromptLabels.ts b/web/src/features/mcp/features/prompts/tools/updatePromptLabels.ts
index 5776c10a76..70b7032d04 100644
--- a/web/src/features/mcp/features/prompts/tools/updatePromptLabels.ts
+++ b/web/src/features/mcp/features/prompts/tools/updatePromptLabels.ts
@@ -64,6 +64,7 @@ export const [updatePromptLabelsTool, handleUpdatePromptLabels] = defineTool({
"- Specified labels are added to the version (preserving others not mentioned)",
"- Labels are unique across versions - setting a label on one version automatically removes it from others",
"- 'latest' label is auto-managed and cannot be set manually",
+ "- Only add the 'production' label when the user explicitly asks to promote this prompt version to production",
"- Cannot modify prompt content, type, or tags - use createTextPrompt or createChatPrompt for new versions",
"",
"Accepts: name, version (required), newLabels (array, can be empty to remove all labels)",
diff --git a/web/src/features/mcp/features/prompts/validation.ts b/web/src/features/mcp/features/prompts/validation.ts
index edc16b1676..6679281fd8 100644
--- a/web/src/features/mcp/features/prompts/validation.ts
+++ b/web/src/features/mcp/features/prompts/validation.ts
@@ -13,6 +13,8 @@ import {
PROMPT_LABEL_REGEX_ERROR,
COMMIT_MESSAGE_MAX_LENGTH,
LATEST_PROMPT_LABEL,
+ PRODUCTION_LABEL,
+ PromptLabelSchema,
} from "@langfuse/shared";
/**
@@ -69,6 +71,20 @@ export const ParamCommitMessage = z
.optional()
.describe("Optional commit message describing the changes");
+/**
+ * Labels allowed while creating a new prompt version.
+ */
+export const ParamCreatePromptLabels = z
+ .array(PromptLabelSchema)
+ .refine((labels) => !labels.includes(PRODUCTION_LABEL), {
+ message:
+ "The 'production' label cannot be assigned when creating prompts through MCP. Create the prompt first, then use updatePromptLabels only when the user explicitly requests promotion to production.",
+ })
+ .optional()
+ .describe(
+ "Optional labels to assign. The 'production' label cannot be assigned during creation and the 'latest' label is auto-managed.",
+ );
+
/**
* New labels array for updating prompt labels
*/