Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(mcp): asAgentToolError sets code without Object.assign (semgrep insecure-object-assign)

garrytan15df90e20a6f
diff --git a/src/mcp/dispatch.ts b/src/mcp/dispatch.ts
index 03e63d8fc3..20678d9711 100644
--- a/src/mcp/dispatch.ts
+++ b/src/mcp/dispatch.ts
@@ -823,7 +823,9 @@ export function asAgentToolError(e: unknown, op: string, ctx: Pick<OperationCont
if (isAIInvocationPolicyError(e)) return e;
const auth: AuthInfo = ctx.auth ?? { token: '', clientId: '', scopes: ['read'] };
const text = errorResult(e, { remote: true, transport: 'http', sourceId: ctx.sourceId, auth, allowedOps }, { op, mutating: false, idempotent: true }).content[0]!.text;
- return Object.assign(new Error(text), { code: (JSON.parse(text) as { code?: string }).code });
+ const err: Error & { code?: string } = new Error(text);
+ err.code = (JSON.parse(text) as { code?: string }).code;
+ return err;
}
const stderrLogger: OperationContext['logger'] = {