[BUG] clear_graph MCP tool fails silently due to async session context manager bug in clear_data function
Bug Description
The clear_graph MCP tool fails silently and does not actually clear any data from the Neo4j database. The issue is caused by a bug in the clear_data function in graphiti_core/utils/maintenance/graph_data_operations.py which attempts to use async with driver.session() on a synchronous Neo4j driver session.
Steps to Reproduce
- Set up Graphiti MCP server with Neo4j database
- Add some episodes using
add_memorytool (verify they are stored in Neo4j) - Call the
clear_graphMCP tool - Check Neo4j database - data is still present (not cleared)
- Check server logs - no clear operation appears in Neo4j logs
Expected Behavior
clear_graphshould delete all nodes and relationships from the Neo4j database- The operation should complete successfully and log the clearing operation
- Neo4j logs should show the
MATCH (n) DETACH DELETE nquery execution
Actual Behavior
clear_graphreturns success message but no data is actually cleared- Neo4j never receives the delete query
- The operation fails silently due to a
TypeErrorexception
Root Cause
The bug is in graphiti_core/utils/maintenance/graph_data_operations.py line 66:
async def clear_data(driver: GraphDriver, group_ids: list[str] | None = None):
async with driver.session() as session: # ❌ BUG: Sync driver doesn't support async context manager
Problem: Graphiti uses GraphDatabase.driver() (synchronous driver) but clear_data tries to use async with driver.session() which requires AsyncGraphDatabase.driver().
Error thrown: TypeError: 'Session' object does not support the asynchronous context manager protocol
Environment
- Graphiti version: 0.18.9
- Neo4j driver version: 5.28.2
- Python version: 3.13
- Neo4j version: Latest (Docker container)
Verification
You can verify this by checking the Neo4j driver session capabilities:
from neo4j import GraphDatabase
driver = GraphDatabase.driver('bolt://localhost:7687', auth=('neo4j', 'password'))
session = driver.session()
print(f'Session has __aenter__: {hasattr(session, "__aenter__")}') # False
print(f'Session has __aexit__: {hasattr(session, "__aexit__")}') # False
Proposed Solution
Option 1 (Minimal fix): Change clear_data to use synchronous context manager:
async def clear_data(driver: GraphDriver, group_ids: list[str] | None = None):
with driver.session() as session: # ✅ Use sync context manager
# ... rest of the function
Option 2 (Comprehensive fix): Use async driver throughout Graphiti:
from neo4j import AsyncGraphDatabase
# Use AsyncGraphDatabase.driver() and async sessions consistently
Impact
- Severity: Medium - Feature completely non-functional but fails silently
- Affected components: MCP server
clear_graphtool, any code usingclear_datafunction - Workaround: Manual database clearing via Neo4j browser/cypher-shell
Additional Context
This bug has likely gone unnoticed because:
clear_graphis not frequently used- The failure is silent (exception caught but not properly logged)
- Users may not immediately verify that data was actually cleared
Related Code
graphiti_core/utils/maintenance/graph_data_operations.py(line 66)mcp_server/graphiti_mcp_server.py(clear_graph tool implementation)
@akannk001 Is this still an issue? Please confirm within 14 days or this issue will be closed.
@akannk001 Is this still an issue? Please confirm within 14 days or this issue will be closed.
@akannk001 Is this still an issue? Please confirm within 14 days or this issue will be closed.
i faced a similar situation with clear_graph i am using the graphiti mcp server for falkordb. The index is destroyed but the nodes are still there.