From f65142989bdba392c7d9efc47445f2fcb504dd5e Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Fri, 7 Aug 2026 18:03:14 -0400 Subject: [PATCH] fix: Run MCP create_document inside a transaction (#13335) Co-authored-by: Claude Opus 5 (1M context) --- server/tools/documents.ts | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/server/tools/documents.ts b/server/tools/documents.ts index 4ebb3a934a..0b69913e4a 100644 --- a/server/tools/documents.ts +++ b/server/tools/documents.ts @@ -426,22 +426,27 @@ export function documentTools(server: McpServer, scopes: string[]) { authType: ctx.state.auth.type, ip: ctx.context.ip, }) - : await documentCreator(ctx, { - title: input.title, - text: input.text, - icon: input.icon, - color: input.color, - parentDocumentId, - publish: input.publish !== false, - collectionId: collection?.id, - template, - fullWidth: input.fullWidth, - sourceMetadata: input.sourceFileName - ? { - fileName: input.sourceFileName, - mimeType: "text/markdown", - } - : undefined, + : await sequelize.transaction(async (transaction) => { + ctx.state.transaction = transaction; + ctx.context.transaction = transaction; + + return documentCreator(ctx, { + title: input.title, + text: input.text, + icon: input.icon, + color: input.color, + parentDocumentId, + publish: input.publish !== false, + collectionId: collection?.id, + template, + fullWidth: input.fullWidth, + sourceMetadata: input.sourceFileName + ? { + fileName: input.sourceFileName, + mimeType: "text/markdown", + } + : undefined, + }); }); const breadcrumb = await getDocumentBreadcrumb(document, user);