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
This commit is contained in:
donbr 2025-11-23 21:12:41 -08:00
parent 582e093582
commit e867732463

View file

@ -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')