Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(surveys): expose question id in MCP survey schema so edits keep responses attached (#66224)

Steven Shults88897a7c1f1d
diff --git a/posthog/temporal/tests/product_analytics/__snapshots__/test_upgrade_queries_workflow.ambr b/posthog/temporal/tests/product_analytics/__snapshots__/test_upgrade_queries_workflow.ambr
index 0839c952c78f..a1c0325ab25a 100644
--- a/posthog/temporal/tests/product_analytics/__snapshots__/test_upgrade_queries_workflow.ambr
+++ b/posthog/temporal/tests/product_analytics/__snapshots__/test_upgrade_queries_workflow.ambr
@@ -11,6 +11,14 @@
OR query @? '$.** ? (
@.kind == "InsightVizNode" &&
(!exists(@.version) || @.version == null || @.version < 4)
+ )'
+ OR query @? '$.** ? (
+ @.kind == "RetentionQuery" &&
+ (!exists(@.version) || @.version == null || @.version < 2)
+ )'
+ OR query @? '$.** ? (
+ @.kind == "StickinessQuery" &&
+ (!exists(@.version) || @.version == null || @.version < 2)
)'
OR query @? '$.** ? (
@.kind == "TrendsQuery" &&
diff --git a/products/surveys/backend/api/survey.py b/products/surveys/backend/api/survey.py
index 924194a4e015..2f1713f7481f 100644
--- a/products/surveys/backend/api/survey.py
+++ b/products/surveys/backend/api/survey.py
@@ -395,6 +395,14 @@ class SurveyQuestionValidationRuleSerializer(serializers.Serializer):
class SurveyBaseQuestionSchemaSerializer(serializers.Serializer):
+ id = serializers.CharField(
+ required=False,
+ help_text=(
+ "Stable question identifier (UUID). When editing an existing question, send back its current id so "
+ "its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the "
+ "server generates one."
+ ),
+ )
type = serializers.ChoiceField(
choices=["open", "link", "rating", "single_choice", "multiple_choice"],
required=True,
diff --git a/products/surveys/frontend/generated/api.schemas.ts b/products/surveys/frontend/generated/api.schemas.ts
index 509a0fd82863..d64d69e4b6f2 100644
--- a/products/surveys/frontend/generated/api.schemas.ts
+++ b/products/surveys/frontend/generated/api.schemas.ts
@@ -831,6 +831,8 @@ export const DescriptionContentTypeEnumApi = {
} as const
export interface SurveyOpenQuestionSchemaApi {
+ /** Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one. */
+ id?: string
type: SurveyOpenQuestionSchemaTypeEnumApi
/** Question text shown to respondents. */
question: string
@@ -858,6 +860,8 @@ export const SurveyLinkQuestionSchemaTypeEnumApi = {
} as const
export interface SurveyLinkQuestionSchemaApi {
+ /** Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one. */
+ id?: string
type: SurveyLinkQuestionSchemaTypeEnumApi
/** Question text shown to respondents. */
question: string
@@ -985,6 +989,8 @@ export type SurveyBranchingSchemaApi =
| SurveyResponseBasedBranchingApi
export interface SurveyRatingQuestionSchemaApi {
+ /** Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one. */
+ id?: string
type: SurveyRatingQuestionSchemaTypeEnumApi
/** Question text shown to respondents. */
question: string
@@ -1027,6 +1033,8 @@ export const SurveySingleChoiceQuestionSchemaTypeEnumApi = {
} as const
export interface SurveySingleChoiceQuestionSchemaApi {
+ /** Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one. */
+ id?: string
type: SurveySingleChoiceQuestionSchemaTypeEnumApi
/** Question text shown to respondents. */
question: string
@@ -1065,6 +1073,8 @@ export const SurveyMultipleChoiceQuestionSchemaTypeEnumApi = {
} as const
export interface SurveyMultipleChoiceQuestionSchemaApi {
+ /** Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one. */
+ id?: string
type: SurveyMultipleChoiceQuestionSchemaTypeEnumApi
/** Question text shown to respondents. */
question: string
diff --git a/products/surveys/frontend/generated/api.zod.ts b/products/surveys/frontend/generated/api.zod.ts
index 3c8c31d441fd..bb2ebec3d83d 100644
--- a/products/surveys/frontend/generated/api.zod.ts
+++ b/products/surveys/frontend/generated/api.zod.ts
@@ -393,6 +393,12 @@ export const SurveysCreateBody = /* @__PURE__ */ zod.object({
.array(
zod.union([
zod.object({
+ id: zod
+ .string()
+ .optional()
+ .describe(
+ 'Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one.'
+ ),
type: zod.enum(['open']).describe('\* `open` - open'),
question: zod.string().describe('Question text shown to respondents.'),
description: zod.string().optional().describe('Optional helper text.'),
@@ -405,6 +411,12 @@ export const SurveysCreateBody = /* @__PURE__ */ zod.object({
buttonText: zod.string().optional().describe('Custom button label.'),
}),
zod.object({
+ id: zod
+ .string()
+ .optional()
+ .describe(
+ 'Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one.'
+ ),
type: zod.enum(['link']).describe('\* `link` - link'),
question: zod.string().describe('Question text shown to respondents.'),
description: zod.string().optional().describe('Optional helper text.'),
@@ -418,6 +430,12 @@ export const SurveysCreateBody = /* @__PURE__ */ zod.object({
link: zod.string().describe('HTTPS or mailto URL for link questions.'),
}),
zod.object({
+ id: zod
+ .string()
+ .optional()
+ .describe(
+ 'Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one.'
+ ),
type: zod.enum(['rating']).describe('\* `rating` - rating'),
question: zod.string().describe('Question text shown to respondents.'),
description: zod.string().optional().describe('Optional helper text.'),
@@ -502,6 +520,12 @@ export const SurveysCreateBody = /* @__PURE__ */ zod.object({
.optional(),
}),
zod.object({
+ id: zod
+ .string()
+ .optional()
+ .describe(
+ 'Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one.'
+ ),
type: zod.enum(['single_choice']).describe('\* `single_choice` - single_choice'),
question: zod.string().describe('Question text shown to respondents.'),
description: zod.string().optional().describe('Optional helper text.'),
@@ -585,6 +609,12 @@ export const SurveysCreateBody = /* @__PURE__ */ zod.object({
.optional(),
}),
zod.object({
+ id: zod
+ .string()
+ .optional()
+ .describe(
+ 'Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one.'
+ ),
type: zod.enum(['multiple_choice']).describe('\* `multiple_choice` - multiple_choice'),
question: zod.string().describe('Question text shown to respondents.'),
description: zod.string().optional().describe('Optional helper text.'),
@@ -1293,6 +1323,12 @@ export const SurveysPartialUpdateBody = /* @__PURE__ */ zod.object({
.array(
zod.union([
zod.object({
+ id: zod
+ .string()
+ .optional()
+ .describe(
+ 'Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one.'
+ ),
type: zod.enum(['open']).describe('\* `open` - open'),
question: zod.string().describe('Question text shown to respondents.'),
description: zod.string().optional().describe('Optional helper text.'),
@@ -1305,6 +1341,12 @@ export const SurveysPartialUpdateBody = /* @__PURE__ */ zod.object({
buttonText: zod.string().optional().describe('Custom button label.'),
}),
zod.object({
+ id: zod
+ .string()
+ .optional()
+ .describe(
+ 'Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one.'
+ ),
type: zod.enum(['link']).describe('\* `link` - link'),
question: zod.string().describe('Question text shown to respondents.'),
description: zod.string().optional().describe('Optional helper text.'),
@@ -1318,6 +1360,12 @@ export const SurveysPartialUpdateBody = /* @__PURE__ */ zod.object({
link: zod.string().describe('HTTPS or mailto URL for link questions.'),
}),
zod.object({
+ id: zod
+ .string()
+ .optional()
+ .describe(
+ 'Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one.'
+ ),
type: zod.enum(['rating']).describe('\* `rating` - rating'),
question: zod.string().describe('Question text shown to respondents.'),
description: zod.string().optional().describe('Optional helper text.'),
@@ -1402,6 +1450,12 @@ export const SurveysPartialUpdateBody = /* @__PURE__ */ zod.object({
.optional(),
}),
zod.object({
+ id: zod
+ .string()
+ .optional()
+ .describe(
+ 'Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one.'
+ ),
type: zod.enum(['single_choice']).describe('\* `single_choice` - single_choice'),
question: zod.string().describe('Question text shown to respondents.'),
description: zod.string().optional().describe('Optional helper text.'),
@@ -1485,6 +1539,12 @@ export const SurveysPartialUpdateBody = /* @__PURE__ */ zod.object({
.optional(),
}),
zod.object({
+ id: zod
+ .string()
+ .optional()
+ .describe(
+ 'Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one.'
+ ),
type: zod.enum(['multiple_choice']).describe('\* `multiple_choice` - multiple_choice'),
question: zod.string().describe('Question text shown to respondents.'),
description: zod.string().optional().describe('Optional helper text.'),
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index ef7d78a08b81..e86723ec5b78 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -40718,6 +40718,8 @@ export namespace Schemas {
} as const;
export interface SurveyOpenQuestionSchema {
+ /** Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one. */
+ id?: string;
type: SurveyOpenQuestionSchemaTypeEnum;
/** Question text shown to respondents. */
question: string;
@@ -40745,6 +40747,8 @@ export namespace Schemas {
} as const;
export interface SurveyLinkQuestionSchema {
+ /** Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one. */
+ id?: string;
type: SurveyLinkQuestionSchemaTypeEnum;
/** Question text shown to respondents. */
question: string;
@@ -40868,6 +40872,8 @@ export namespace Schemas {
export type SurveyBranchingSchema = SurveyNextQuestionBranching | SurveyEndBranching | SurveySpecificQuestionBranching | SurveyResponseBasedBranching;
export interface SurveyRatingQuestionSchema {
+ /** Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one. */
+ id?: string;
type: SurveyRatingQuestionSchemaTypeEnum;
/** Question text shown to respondents. */
question: string;
@@ -40910,6 +40916,8 @@ export namespace Schemas {
} as const;
export interface SurveySingleChoiceQuestionSchema {
+ /** Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one. */
+ id?: string;
type: SurveySingleChoiceQuestionSchemaTypeEnum;
/** Question text shown to respondents. */
question: string;
@@ -40948,6 +40956,8 @@ export namespace Schemas {
} as const;
export interface SurveyMultipleChoiceQuestionSchema {
+ /** Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one. */
+ id?: string;
type: SurveyMultipleChoiceQuestionSchemaTypeEnum;
/** Question text shown to respondents. */
question: string;
diff --git a/services/mcp/src/generated/surveys/api.ts b/services/mcp/src/generated/surveys/api.ts
index 65dffc00d822..7298a00db6b2 100644
--- a/services/mcp/src/generated/surveys/api.ts
+++ b/services/mcp/src/generated/surveys/api.ts
@@ -413,6 +413,12 @@ export const SurveysCreateBody = /* @__PURE__ */ zod.object({
.array(
zod.union([
zod.object({
+ id: zod
+ .string()
+ .optional()
+ .describe(
+ 'Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one.'
+ ),
type: zod.enum(['open']).describe('* `open` - open'),
question: zod.string().describe('Question text shown to respondents.'),
description: zod.string().optional().describe('Optional helper text.'),
@@ -425,6 +431,12 @@ export const SurveysCreateBody = /* @__PURE__ */ zod.object({
buttonText: zod.string().optional().describe('Custom button label.'),
}),
zod.object({
+ id: zod
+ .string()
+ .optional()
+ .describe(
+ 'Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one.'
+ ),
type: zod.enum(['link']).describe('* `link` - link'),
question: zod.string().describe('Question text shown to respondents.'),
description: zod.string().optional().describe('Optional helper text.'),
@@ -438,6 +450,12 @@ export const SurveysCreateBody = /* @__PURE__ */ zod.object({
link: zod.string().describe('HTTPS or mailto URL for link questions.'),
}),
zod.object({
+ id: zod
+ .string()
+ .optional()
+ .describe(
+ 'Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one.'
+ ),
type: zod.enum(['rating']).describe('* `rating` - rating'),
question: zod.string().describe('Question text shown to respondents.'),
description: zod.string().optional().describe('Optional helper text.'),
@@ -522,6 +540,12 @@ export const SurveysCreateBody = /* @__PURE__ */ zod.object({
.optional(),
}),
zod.object({
+ id: zod
+ .string()
+ .optional()
+ .describe(
+ 'Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one.'
+ ),
type: zod.enum(['single_choice']).describe('* `single_choice` - single_choice'),
question: zod.string().describe('Question text shown to respondents.'),
description: zod.string().optional().describe('Optional helper text.'),
@@ -605,6 +629,12 @@ export const SurveysCreateBody = /* @__PURE__ */ zod.object({
.optional(),
}),
zod.object({
+ id: zod
+ .string()
+ .optional()
+ .describe(
+ 'Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one.'
+ ),
type: zod.enum(['multiple_choice']).describe('* `multiple_choice` - multiple_choice'),
question: zod.string().describe('Question text shown to respondents.'),
description: zod.string().optional().describe('Optional helper text.'),
@@ -1220,6 +1250,12 @@ export const SurveysPartialUpdateBody = /* @__PURE__ */ zod.object({
.array(
zod.union([
zod.object({
+ id: zod
+ .string()
+ .optional()
+ .describe(
+ 'Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one.'
+ ),
type: zod.enum(['open']).describe('* `open` - open'),
question: zod.string().describe('Question text shown to respondents.'),
description: zod.string().optional().describe('Optional helper text.'),
@@ -1232,6 +1268,12 @@ export const SurveysPartialUpdateBody = /* @__PURE__ */ zod.object({
buttonText: zod.string().optional().describe('Custom button label.'),
}),
zod.object({
+ id: zod
+ .string()
+ .optional()
+ .describe(
+ 'Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one.'
+ ),
type: zod.enum(['link']).describe('* `link` - link'),
question: zod.string().describe('Question text shown to respondents.'),
description: zod.string().optional().describe('Optional helper text.'),
@@ -1245,6 +1287,12 @@ export const SurveysPartialUpdateBody = /* @__PURE__ */ zod.object({
link: zod.string().describe('HTTPS or mailto URL for link questions.'),
}),
zod.object({
+ id: zod
+ .string()
+ .optional()
+ .describe(
+ 'Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one.'
+ ),
type: zod.enum(['rating']).describe('* `rating` - rating'),
question: zod.string().describe('Question text shown to respondents.'),
description: zod.string().optional().describe('Optional helper text.'),
@@ -1329,6 +1377,12 @@ export const SurveysPartialUpdateBody = /* @__PURE__ */ zod.object({
.optional(),
}),
zod.object({
+ id: zod
+ .string()
+ .optional()
+ .describe(
+ 'Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one.'
+ ),
type: zod.enum(['single_choice']).describe('* `single_choice` - single_choice'),
question: zod.string().describe('Question text shown to respondents.'),
description: zod.string().optional().describe('Optional helper text.'),
@@ -1412,6 +1466,12 @@ export const SurveysPartialUpdateBody = /* @__PURE__ */ zod.object({
.optional(),
}),
zod.object({
+ id: zod
+ .string()
+ .optional()
+ .describe(
+ 'Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one.'
+ ),
type: zod.enum(['multiple_choice']).describe('* `multiple_choice` - multiple_choice'),
question: zod.string().describe('Question text shown to respondents.'),
description: zod.string().optional().describe('Optional helper text.'),
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/survey-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/survey-create.json
index 84673681d98d..3743b8e6a31d 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/survey-create.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/survey-create.json
@@ -275,6 +275,10 @@
"enum": ["html", "text"],
"type": "string"
},
+ "id": {
+ "description": "Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one.",
+ "type": "string"
+ },
"optional": {
"description": "Whether respondents may skip this question.",
"type": "boolean"
@@ -307,6 +311,10 @@
"enum": ["html", "text"],
"type": "string"
},
+ "id": {
+ "description": "Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one.",
+ "type": "string"
+ },
"link": {
"description": "HTTPS or mailto URL for link questions.",
"type": "string"
@@ -427,6 +435,10 @@
"enum": ["number", "emoji"],
"type": "string"
},
+ "id": {
+ "description": "Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one.",
+ "type": "string"
+ },
"lowerBoundLabel": {
"description": "Label for the lowest rating (e.g., 'Very Poor')",
"type": "string"
@@ -564,6 +576,10 @@
"description": "Whether the final option should be an open-text choice (for example, 'Other').",
"type": "boolean"
},
+ "id": {
+ "description": "Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one.",
+ "type": "string"
+ },
"optional": {
"description": "Whether respondents may skip this question.",
"type": "boolean"
@@ -613,6 +629,10 @@
"description": "Whether the final option should be an open-text choice (for example, 'Other').",
"type": "boolean"
},
+ "id": {
+ "description": "Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one.",
+ "type": "string"
+ },
"optional": {
"description": "Whether respondents may skip this question.",
"type": "boolean"
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/survey-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/survey-update.json
index 8dea1fa8ec0e..deeb4aa4ecda 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/survey-update.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/survey-update.json
@@ -295,6 +295,10 @@
"enum": ["html", "text"],
"type": "string"
},
+ "id": {
+ "description": "Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one.",
+ "type": "string"
+ },
"optional": {
"description": "Whether respondents may skip this question.",
"type": "boolean"
@@ -327,6 +331,10 @@
"enum": ["html", "text"],
"type": "string"
},
+ "id": {
+ "description": "Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one.",
+ "type": "string"
+ },
"link": {
"description": "HTTPS or mailto URL for link questions.",
"type": "string"
@@ -447,6 +455,10 @@
"enum": ["number", "emoji"],
"type": "string"
},
+ "id": {
+ "description": "Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one.",
+ "type": "string"
+ },
"lowerBoundLabel": {
"description": "Label for the lowest rating (e.g., 'Very Poor')",
"type": "string"
@@ -584,6 +596,10 @@
"description": "Whether the final option should be an open-text choice (for example, 'Other').",
"type": "boolean"
},
+ "id": {
+ "description": "Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one.",
+ "type": "string"
+ },
"optional": {
"description": "Whether respondents may skip this question.",
"type": "boolean"
@@ -633,6 +649,10 @@
"description": "Whether the final option should be an open-text choice (for example, 'Other').",
"type": "boolean"
},
+ "id": {
+ "description": "Stable question identifier (UUID). When editing an existing question, send back its current id so its responses (keyed by $survey_response_<id>) stay attached; omit it for new questions and the server generates one.",
+ "type": "string"
+ },
"optional": {
"description": "Whether respondents may skip this question.",
"type": "boolean"
diff --git a/services/mcp/tests/unit/schema.survey-question-id.test.ts b/services/mcp/tests/unit/schema.survey-question-id.test.ts
new file mode 100644
index 000000000000..584ea428946e
--- /dev/null
+++ b/services/mcp/tests/unit/schema.survey-question-id.test.ts
@@ -0,0 +1,23 @@
+import { describe, expect, it } from 'vitest'
+
+import { SurveysCreateBody, SurveysPartialUpdateBody } from '@/generated/surveys/api'
+
+// Regression guard: survey responses are keyed $survey_response_<question_id>, so the MCP
+// survey tools must let callers send back an existing question id on edit. If the `id` field
+// is dropped from the question schema, zod silently strips it and every edit regenerates the
+// UUID, orphaning historical responses (support ticket 61130).
+describe('Survey question id preservation', () => {
+ it.each([
+ ['survey-create', SurveysCreateBody.shape.questions],
+ ['survey-update', SurveysPartialUpdateBody.shape.questions],
+ ])('preserves an explicit question id through %s validation', (_label, questionsSchema) => {
+ const existingId = '0190a1b2-c3d4-7e8f-9012-3456789abcde'
+
+ const result = questionsSchema.safeParse([
+ { type: 'open', question: 'How was your experience?', id: existingId },
+ ])
+
+ expect(result.success).toBe(true)
+ expect(result.data?.[0]).toMatchObject({ id: existingId })
+ })
+})