@@ -237,6 +237,8 @@ func shouldRegister(name string, allowlist map[string]bool) bool {
237237}
238238
239239func registerTools (srv * server.MCPServer , s * store.Store , cfg MCPConfig , allowlist map [string ]bool , activity * SessionActivity ) {
240+ writeQueue := newWriteQueue (defaultMCPWriteQueueSize )
241+
240242 // ─── mem_search (profile: agent, core — always in context) ─────────
241243 if shouldRegister ("mem_search" , allowlist ) {
242244 srv .AddTool (
@@ -324,7 +326,7 @@ Examples:
324326 mcp .Description ("Optional topic identifier for upserts (e.g. architecture/auth-model). Reuses and updates the latest observation in same project+scope." ),
325327 ),
326328 ),
327- handleSave (s , cfg , activity ),
329+ queuedWriteHandler ( writeQueue , handleSave (s , cfg , activity ) ),
328330 )
329331 }
330332
@@ -359,7 +361,7 @@ Examples:
359361 mcp .Description ("New topic key (normalized internally)" ),
360362 ),
361363 ),
362- handleUpdate (s ),
364+ queuedWriteHandler ( writeQueue , handleUpdate (s ) ),
363365 )
364366 }
365367
@@ -407,7 +409,7 @@ Examples:
407409 mcp .Description ("If true, permanently deletes the observation" ),
408410 ),
409411 ),
410- handleDelete (s ),
412+ queuedWriteHandler ( writeQueue , handleDelete (s ) ),
411413 )
412414 }
413415
@@ -429,7 +431,7 @@ Examples:
429431 mcp .Description ("Session ID to associate with (default: manual-save-{project})" ),
430432 ),
431433 ),
432- handleSavePrompt (s , cfg ),
434+ queuedWriteHandler ( writeQueue , handleSavePrompt (s , cfg ) ),
433435 )
434436 }
435437
@@ -570,7 +572,7 @@ GUIDELINES:
570572 ),
571573 // project field intentionally omitted — auto-detect only (REQ-308 write-tool contract)
572574 ),
573- handleSessionSummary (s , cfg , activity ),
575+ queuedWriteHandler ( writeQueue , handleSessionSummary (s , cfg , activity ) ),
574576 )
575577 }
576578
@@ -593,7 +595,7 @@ GUIDELINES:
593595 mcp .Description ("Working directory" ),
594596 ),
595597 ),
596- handleSessionStart (s , cfg , activity ),
598+ queuedWriteHandler ( writeQueue , handleSessionStart (s , cfg , activity ) ),
597599 )
598600 }
599601
@@ -616,7 +618,7 @@ GUIDELINES:
616618 mcp .Description ("Summary of what was accomplished" ),
617619 ),
618620 ),
619- handleSessionEnd (s , cfg , activity ),
621+ queuedWriteHandler ( writeQueue , handleSessionEnd (s , cfg , activity ) ),
620622 )
621623 }
622624
@@ -646,7 +648,7 @@ Duplicates are automatically detected and skipped — safe to call multiple time
646648 mcp .Description ("Source identifier (e.g. 'subagent-stop', 'session-end')" ),
647649 ),
648650 ),
649- handleCapturePassive (s , cfg , activity ),
651+ queuedWriteHandler ( writeQueue , handleCapturePassive (s , cfg , activity ) ),
650652 )
651653 }
652654
@@ -670,7 +672,7 @@ Duplicates are automatically detected and skipped — safe to call multiple time
670672 mcp .Description ("The canonical project name to merge INTO (e.g. 'engram')" ),
671673 ),
672674 ),
673- handleMergeProjects (s ),
675+ queuedWriteHandler ( writeQueue , handleMergeProjects (s ) ),
674676 )
675677 }
676678
@@ -739,7 +741,7 @@ Re-judging an already-judged ID overwrites the verdict (deliberate revision).`),
739741 mcp .Description ("Session ID for provenance (default: auto)" ),
740742 ),
741743 ),
742- handleJudge (s , activity ),
744+ queuedWriteHandler ( writeQueue , handleJudge (s , activity ) ),
743745 )
744746 }
745747}
0 commit comments