From 1f05071d72fb0138c8d090b007a47492f9afd3ee Mon Sep 17 00:00:00 2001 From: Sonarly Claude Code Date: Sun, 19 Apr 2026 20:48:14 +0000 Subject: [PATCH] fix(server): guard against undefined args in stripLoadingMessage and resolveAndExecute https://sonarly.com/issue/28820?type=bug The MCP tool execution chain crashes with a TypeError when `execute_tool` is called without an inner `arguments` field, because `stripLoadingMessage` destructures an undefined parameter. A secondary i18n issue causes log spam from uncompiled Lingui message catalogs. Fix: Applied above. Two minimal defensive defaults preventing undefined from reaching destructure operations. --- .../core-modules/tool-provider/tools/execute-tool.tool.ts | 2 +- .../core-modules/tool/utils/wrap-tool-for-execution.util.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/twenty-server/src/engine/core-modules/tool-provider/tools/execute-tool.tool.ts b/packages/twenty-server/src/engine/core-modules/tool-provider/tools/execute-tool.tool.ts index 552af38ae55..f5335c8a6cf 100644 --- a/packages/twenty-server/src/engine/core-modules/tool-provider/tools/execute-tool.tool.ts +++ b/packages/twenty-server/src/engine/core-modules/tool-provider/tools/execute-tool.tool.ts @@ -54,7 +54,7 @@ export const createExecuteToolTool = ( parameters: ExecuteToolInput, options: ToolExecutionOptions, ): Promise => { - const { toolName, arguments: args } = parameters; + const { toolName, arguments: args = {} } = parameters; if (excludeTools?.has(toolName)) { return { diff --git a/packages/twenty-server/src/engine/core-modules/tool/utils/wrap-tool-for-execution.util.ts b/packages/twenty-server/src/engine/core-modules/tool/utils/wrap-tool-for-execution.util.ts index c2518a555d1..9a10367079d 100644 --- a/packages/twenty-server/src/engine/core-modules/tool/utils/wrap-tool-for-execution.util.ts +++ b/packages/twenty-server/src/engine/core-modules/tool/utils/wrap-tool-for-execution.util.ts @@ -42,6 +42,10 @@ export const wrapJsonSchemaForExecution = ( export const stripLoadingMessage = >( parameters: T, ): Omit => { + if (!parameters) { + return {} as Omit; + } + const { loadingMessage: _, ...rest } = parameters; return rest;