From df117ebad53a38ad2eeaf8ef8cff196907be9b3c Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Thu, 21 May 2026 17:41:37 -0400 Subject: [PATCH] fix: Updating collection description via MCP does not take (#12410) --- server/models/Collection.ts | 15 ++++++++++++++- server/routes/api/collections/collections.ts | 14 -------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/server/models/Collection.ts b/server/models/Collection.ts index 4af1dc579f..b06715929b 100644 --- a/server/models/Collection.ts +++ b/server/models/Collection.ts @@ -55,6 +55,7 @@ import { UrlHelper } from "@shared/utils/UrlHelper"; import { sortNavigationNodes } from "@shared/utils/collections"; import slugify from "@shared/utils/slugify"; import { CollectionValidation } from "@shared/validations"; +import { parser } from "@server/editor"; import { ValidationError } from "@server/errors"; import type { APIContext } from "@server/types"; import { CacheHelper } from "@server/utils/CacheHelper"; @@ -346,9 +347,21 @@ class Collection extends ParanoidModel< @BeforeSave static async onBeforeSave(model: Collection) { - if (!model.content) { + const descriptionChanged = model.changed("description"); + const contentChanged = model.changed("content"); + + if (descriptionChanged && !contentChanged) { + model.content = model.description + ? (parser.parse(model.description)?.toJSON() ?? null) + : null; + } else if (contentChanged && !descriptionChanged) { + model.description = model.content + ? await DocumentHelper.toMarkdown(model, { includeTitle: false }) + : null; + } else if (!model.content) { model.content = await DocumentHelper.toJSON(model); } + if (model.changed("documentStructure")) { await CacheHelper.clearData( RedisPrefixHelper.getCollectionDocumentsKey(model.id) diff --git a/server/routes/api/collections/collections.ts b/server/routes/api/collections/collections.ts index 04a283afe4..c04070bea7 100644 --- a/server/routes/api/collections/collections.ts +++ b/server/routes/api/collections/collections.ts @@ -10,7 +10,6 @@ import { } from "@shared/types"; import collectionExporter from "@server/commands/collectionExporter"; import teamUpdater from "@server/commands/teamUpdater"; -import { parser } from "@server/editor"; import auth from "@server/middlewares/authentication"; import { rateLimiter } from "@server/middlewares/rateLimiter"; import { transaction } from "@server/middlewares/transaction"; @@ -26,7 +25,6 @@ import { FileOperation, Document, } from "@server/models"; -import { DocumentHelper } from "@server/models/helpers/DocumentHelper"; import { authorize } from "@server/policies"; import { presentCollection, @@ -87,12 +85,6 @@ router.post( templateManagement, }); - if (data) { - collection.description = await DocumentHelper.toMarkdown(collection, { - includeTitle: false, - }); - } - await collection.saveWithCtx(ctx); // we must reload the collection to get memberships for policy presenter @@ -628,16 +620,10 @@ router.post( if (description !== undefined) { collection.description = description; - collection.content = description - ? parser.parse(description)?.toJSON() - : null; } if (data !== undefined) { collection.content = data; - collection.description = await DocumentHelper.toMarkdown(collection, { - includeTitle: false, - }); } if (icon !== undefined) {