diff --git a/src/asap/server.c b/src/asap/server.c index d681f9b..fa39b0c 100644 --- a/src/asap/server.c +++ b/src/asap/server.c @@ -282,11 +282,14 @@ static int handle_mcp_tool_call(const asap_envelope_t *in, asap_envelope_t *out, return -32603; } result_buf[0] = '\0'; + /* Same mutex discipline as task.request: tools touch shared session/memory. */ + agent_lock(); if (ctx->tool_call_hook) { int hr = ctx->tool_call_hook(ctx, tool_name, args_json, result_buf, RESULT_CAP); exec_rc = hr == 0 ? 0 : 2; } else exec_rc = dispatch_tool_by_name(ctx, tool_name, args_json, result_buf, RESULT_CAP); + agent_unlock(); free(args_json); if (exec_rc == 1) { free(result_buf);