From e867732463ecace755382ba8e74f8a515490de0d Mon Sep 17 00:00:00 2001 From: donbr Date: Sun, 23 Nov 2025 21:12:41 -0800 Subject: [PATCH] fix(mcp): handle Neo4j 5.x index creation race condition Wrap build_indices_and_constraints() in try/except to catch EquivalentSchemaRuleAlreadyExists error that occurs when Neo4j 5.x processes parallel CREATE INDEX IF NOT EXISTS statements. Fixes #353 --- mcp_server/src/graphiti_mcp_server.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mcp_server/src/graphiti_mcp_server.py b/mcp_server/src/graphiti_mcp_server.py index 833bc5d9..bb802b06 100644 --- a/mcp_server/src/graphiti_mcp_server.py +++ b/mcp_server/src/graphiti_mcp_server.py @@ -278,8 +278,18 @@ class GraphitiService: # Re-raise other errors raise - # Build indices - await self.client.build_indices_and_constraints() + # Build indices - wrap in try/except to handle Neo4j 5.x race condition + # with parallel IF NOT EXISTS index creation + try: + await self.client.build_indices_and_constraints() + except Exception as idx_error: + if 'EquivalentSchemaRuleAlreadyExists' in str(idx_error): + logger.warning( + 'Index creation race condition detected (Neo4j 5.x issue). ' + 'Indexes likely already exist. Continuing...' + ) + else: + raise logger.info('Successfully initialized Graphiti client')