graphiti/check_source_data.py
Lars Varming 341efd8c3d Fix: Critical database parameter bug + index creation error handling
CRITICAL FIX - Database Parameter (graphiti_core):
- Fixed graphiti_core/driver/neo4j_driver.py execute_query method
- database_ parameter was incorrectly added to params dict instead of kwargs
- Now correctly passed as keyword argument to Neo4j driver
- Impact: All queries now execute in configured database (not default 'neo4j')
- Root cause: Violated Neo4j Python driver API contract

Technical Details:
Previous code (BROKEN):
  params.setdefault('database_', self._database)  # Wrong - in params dict
  result = await self.client.execute_query(cypher_query_, parameters_=params, **kwargs)

Fixed code (CORRECT):
  kwargs.setdefault('database_', self._database)  # Correct - in kwargs
  result = await self.client.execute_query(cypher_query_, parameters_=params, **kwargs)

FIX - Index Creation Error Handling (MCP server):
- Added graceful handling for Neo4j IF NOT EXISTS bug
- Prevents MCP server crash when indices already exist
- Logs warning instead of failing initialization
- Handles EquivalentSchemaRuleAlreadyExists error gracefully

Files Modified:
- graphiti_core/driver/neo4j_driver.py (3 lines changed)
- mcp_server/src/graphiti_mcp_server.py (12 lines added error handling)
- mcp_server/pyproject.toml (version bump to 1.0.5)

Testing:
- Python syntax validation: PASSED
- Ruff formatting: PASSED
- Ruff linting: PASSED

Closes issues with:
- Data being stored in wrong Neo4j database
- MCP server crashing on startup with EquivalentSchemaRuleAlreadyExists
- NEO4J_DATABASE environment variable being ignored

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-10 11:37:16 +01:00

74 lines
2.2 KiB
Python

#!/usr/bin/env python3
"""Check what's in the source database."""
from neo4j import GraphDatabase
import os
NEO4J_URI = "bolt://192.168.1.25:7687"
NEO4J_USER = "neo4j"
NEO4J_PASSWORD = '!"MiTa1205'
SOURCE_DATABASE = "neo4j"
SOURCE_GROUP_ID = "lvarming73"
driver = GraphDatabase.driver(NEO4J_URI, auth=(NEO4J_USER, NEO4J_PASSWORD))
print("=" * 70)
print("Checking Source Database")
print("=" * 70)
with driver.session(database=SOURCE_DATABASE) as session:
# Check total nodes
result = session.run("""
MATCH (n {group_id: $group_id})
RETURN count(n) as total
""", group_id=SOURCE_GROUP_ID)
total = result.single()['total']
print(f"\n✓ Total nodes with group_id '{SOURCE_GROUP_ID}': {total}")
# Check date range
result = session.run("""
MATCH (n:Episodic {group_id: $group_id})
WHERE n.created_at IS NOT NULL
RETURN
min(n.created_at) as earliest,
max(n.created_at) as latest,
count(n) as total
""", group_id=SOURCE_GROUP_ID)
dates = result.single()
if dates and dates['total'] > 0:
print(f"\n✓ Episodic date range:")
print(f" Earliest: {dates['earliest']}")
print(f" Latest: {dates['latest']}")
print(f" Total episodes: {dates['total']}")
else:
print("\n⚠️ No episodic nodes with dates found")
# Sample episodic nodes by date
result = session.run("""
MATCH (n:Episodic {group_id: $group_id})
RETURN n.name as name, n.created_at as created_at
ORDER BY n.created_at
LIMIT 10
""", group_id=SOURCE_GROUP_ID)
print(f"\n✓ Oldest episodic nodes:")
for record in result:
print(f" - {record['name']}: {record['created_at']}")
# Check for other group_ids in neo4j database
result = session.run("""
MATCH (n)
WHERE n.group_id IS NOT NULL
RETURN DISTINCT n.group_id as group_id, count(n) as count
ORDER BY count DESC
""")
print(f"\n✓ All group_ids in '{SOURCE_DATABASE}' database:")
for record in result:
print(f" {record['group_id']}: {record['count']} nodes")
driver.close()
print("\n" + "=" * 70)