Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(mcp): keep dispatchResolvedCall under the function-size limit
garrytanf4ac3b305ac1
diff --git a/src/mcp/dispatch.ts b/src/mcp/dispatch.tsindex 23dd931305..5683f9b344 100644--- a/src/mcp/dispatch.ts+++ b/src/mcp/dispatch.ts@@ -887,6 +887,13 @@ export async function dispatchToolCall(}/** The response-meta hook's keys, or its failure message; never rejects (a hook failure degrades to no keys). */+// The hot-memory hook reads ctx.sourceId only, so a call that names its own sources gets no ambient-source payload.+function namesOwnSources(params: Record<string, unknown>, sourceId: string | undefined): boolean {+ const ids = params.source_ids;+ if (Array.isArray(ids) ? ids.length > 0 : typeof ids === 'string' && ids.trim() !== '') return true;+ return typeof params.source_id === 'string' && params.source_id !== '' && params.source_id !== sourceId;+}+async function runMetaHook(hook: NonNullable<DispatchOpts['metaHook']>, name: string, ctx: OperationContext): Promise<{ meta?: Record<string, unknown>; failure?: string }> {try { return { meta: await hook(name, ctx) }; }catch (metaErr) { return { failure: metaErr instanceof Error ? metaErr.message : String(metaErr) }; }@@ -1078,11 +1085,7 @@ async function dispatchResolvedCall(// #5575 CEO-18: a floored connection only reaches read ops that enforce its floor.enforceReadTrustFloor(ctx.auth, op);// GBRA-156: a read op does not change what the hook reads, so it runs beside the handler (a degraded engine's reconnect stays the handler's).- // The hot-memory hook reads ctx.sourceId only, so a call that names its own sources gets no ambient-source payload.- const namedIds = safeParams.source_ids;- const namesSources = (Array.isArray(namedIds) ? namedIds.length > 0 : typeof namedIds === 'string' && namedIds.trim() !== '')- || (typeof safeParams.source_id === 'string' && safeParams.source_id !== '' && safeParams.source_id !== ctx.sourceId);- const metaHook = namesSources ? undefined : opts.metaHook;+ const metaHook = namesOwnSources(safeParams, ctx.sourceId) ? undefined : opts.metaHook;const earlyMeta = metaHook && op.mutating === false && !isEngineDegraded(engine) ? runMetaHook(metaHook, name, ctx) : undefined;const sharedStdio = ctx.transport === 'stdio' && !ctx.auth &&(op.requiredScopes?.length || ['list_skills', 'get_skill', 'get_skill_asset', 'list_brain_skillpack'].includes(name));