Skip to content

Commit d0a3cd9

Browse files
authored
Integrate MCP for FalkorDB (#910)
* Integrate MCP for FalkorDB * fix lint errors
1 parent 7c38ce7 commit d0a3cd9

File tree

10 files changed

+723
-459
lines changed

10 files changed

+723
-459
lines changed

graphiti_core/driver/falkordb_driver.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
limitations under the License.
1515
"""
1616

17+
import datetime
1718
import asyncio
1819
import logging
1920
from typing import TYPE_CHECKING, Any
@@ -230,7 +231,29 @@ def clone(self, database: str) -> 'GraphDriver':
230231
"""
231232
cloned = FalkorDriver(falkor_db=self.client, database=database)
232233

233-
return cloned
234+
return cloned
235+
236+
async def health_check(self) -> None:
237+
"""Check FalkorDB connectivity by running a simple query."""
238+
try:
239+
await self.execute_query("MATCH (n) RETURN 1 LIMIT 1")
240+
return None
241+
except Exception as e:
242+
print(f"FalkorDB health check failed: {e}")
243+
raise
244+
245+
@staticmethod
246+
def convert_datetimes_to_strings(obj):
247+
if isinstance(obj, dict):
248+
return {k: FalkorDriver.convert_datetimes_to_strings(v) for k, v in obj.items()}
249+
elif isinstance(obj, list):
250+
return [FalkorDriver.convert_datetimes_to_strings(item) for item in obj]
251+
elif isinstance(obj, tuple):
252+
return tuple(FalkorDriver.convert_datetimes_to_strings(item) for item in obj)
253+
elif isinstance(obj, datetime):
254+
return obj.isoformat()
255+
else:
256+
return obj
234257

235258
def sanitize(self, query: str) -> str:
236259
"""

graphiti_core/driver/neo4j_driver.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,12 @@ def delete_all_indexes(self) -> Coroutine:
7272
return self.client.execute_query(
7373
'CALL db.indexes() YIELD name DROP INDEX name',
7474
)
75+
76+
async def health_check(self) -> None:
77+
"""Check Neo4j connectivity by running the driver's verify_connectivity method."""
78+
try:
79+
await self.client.verify_connectivity()
80+
return None
81+
except Exception as e:
82+
print(f"Neo4j health check failed: {e}")
83+
raise

mcp_server/.env.example

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
# Graphiti MCP Server Environment Configuration
22

3-
# Neo4j Database Configuration
3+
# Database Configuration
4+
# Choose between 'neo4j' or 'falkordb'
5+
DATABASE_TYPE=falkordb
6+
47
# These settings are used to connect to your Neo4j database
58
NEO4J_URI=bolt://localhost:7687
69
NEO4J_USER=neo4j
710
NEO4J_PASSWORD=demodemo
811

12+
# These settings are used to connect to your FalkorDB database
13+
FALKORDB_PORT=6379
14+
FALKORDB_HOST=localhost
15+
FALKORDB_USER=
16+
FALKORDB_PASSWORD=
17+
918
# OpenAI API Configuration
1019
# Required for LLM operations
1120
OPENAI_API_KEY=your_openai_api_key_here

mcp_server/Dockerfile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,13 @@ RUN groupadd -r app && useradd -r -d /app -g app app
3030
COPY pyproject.toml uv.lock ./
3131

3232
# Install dependencies first (better layer caching)
33+
ARG INSTALL_FALKORDB=false
3334
RUN --mount=type=cache,target=/root/.cache/uv \
34-
uv sync --frozen --no-dev
35+
if [ "$INSTALL_FALKORDB" = "true" ]; then \
36+
uv sync --frozen --no-dev --extra falkordb; \
37+
else \
38+
uv sync --frozen --no-dev; \
39+
fi
3540

3641
# Copy application code
3742
COPY graphiti_mcp_server.py ./
@@ -43,7 +48,7 @@ RUN chown -Rv app:app /app
4348
USER app
4449

4550
# Expose port
46-
EXPOSE 8000
51+
EXPOSE $PORT
4752

4853
# Command to run the application
4954
CMD ["uv", "run", "graphiti_mcp_server.py"]

mcp_server/README.md

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,21 @@ uv sync
8282

8383
## Configuration
8484

85-
The server uses the following environment variables:
85+
The server supports both Neo4j and FalkorDB as database backends. Use the `DATABASE_TYPE` environment variable to choose between them.
86+
87+
#### Neo4j Configuration (default)
8688

8789
- `NEO4J_URI`: URI for the Neo4j database (default: `bolt://localhost:7687`)
8890
- `NEO4J_USER`: Neo4j username (default: `neo4j`)
8991
- `NEO4J_PASSWORD`: Neo4j password (default: `demodemo`)
92+
93+
#### FalkorDB Configuration
94+
- `DATABASE_TYPE`: Set to `falkordb`
95+
- `FALKORDB_HOST`: FalkorDB host (default: `localhost`)
96+
- `FALKORDB_PORT`: FalkorDB port (default: `6379`)
97+
- `FALKORDB_USERNAME`: FalkorDB username (optional)
98+
- `FALKORDB_PASSWORD`: FalkorDB password (optional)
99+
90100
- `OPENAI_API_KEY`: OpenAI API key (required for LLM operations)
91101
- `OPENAI_BASE_URL`: Optional base URL for OpenAI API
92102
- `MODEL_NAME`: OpenAI model name to use for LLM operations.
@@ -115,7 +125,7 @@ uv run graphiti_mcp_server.py
115125
With options:
116126

117127
```bash
118-
uv run graphiti_mcp_server.py --model gpt-4.1-mini --transport sse
128+
uv run graphiti_mcp_server.py --model gpt-4.1-mini --transport sse --database-type falkordb --port 8001
119129
```
120130

121131
Available arguments:
@@ -124,6 +134,7 @@ Available arguments:
124134
- `--small-model`: Overrides the `SMALL_MODEL_NAME` environment variable.
125135
- `--temperature`: Overrides the `LLM_TEMPERATURE` environment variable.
126136
- `--transport`: Choose the transport method (sse or stdio, default: sse)
137+
- `--database-type`: Choose database backend (neo4j or falkordb, default: neo4j)
127138
- `--group-id`: Set a namespace for the graph (optional). If not provided, defaults to "default".
128139
- `--destroy-graph`: If set, destroys all Graphiti graphs on startup.
129140
- `--use-custom-entities`: Enable entity extraction using the predefined ENTITY_TYPES
@@ -175,11 +186,30 @@ The Docker Compose setup includes a Neo4j container with the following default c
175186
- URI: `bolt://neo4j:7687` (from within the Docker network)
176187
- Memory settings optimized for development use
177188
189+
To run only Neo4j with its MCP server:
190+
```bash
191+
docker compose up
192+
```
193+
- Neo4j MCP server on port 8000
194+
195+
#### FalkorDB Configuration
196+
197+
The Docker Compose setup includes a FalkorDB container with the following default configuration:
198+
- Host: `falkordb`
199+
- Port: `6379`
200+
- No authentication by default
201+
202+
To run only FalkorDB with its MCP server:
203+
```bash
204+
docker compose --profile falkordb up
205+
```
206+
- FalkorDB MCP server on port 8001
207+
178208
#### Running with Docker Compose
179209
180210
A Graphiti MCP container is available at: `zepai/knowledge-graph-mcp`. The latest build of this container is used by the Compose setup below.
181211
182-
Start the services using Docker Compose:
212+
Start the services using Docker Compose For Neo4j:
183213
184214
```bash
185215
docker compose up
@@ -191,13 +221,25 @@ Or if you're using an older version of Docker Compose:
191221
docker-compose up
192222
```
193223

194-
This will start both the Neo4j database and the Graphiti MCP server. The Docker setup:
224+
For FalkorDB:
225+
226+
```bash
227+
docker compose --profile falkordb up
228+
```
229+
230+
Or if you're using an older version of Docker Compose:
231+
232+
```bash
233+
docker-compose --profile falkordb up
234+
```
235+
236+
This will start the database(s) and the Graphiti MCP server(s). The Docker setup:
195237
196238
- Uses `uv` for package management and running the server
197239
- Installs dependencies from the `pyproject.toml` file
198-
- Connects to the Neo4j container using the environment variables
199-
- Exposes the server on port 8000 for HTTP-based SSE transport
200-
- Includes a healthcheck for Neo4j to ensure it's fully operational before starting the MCP server
240+
- Connects to the database container using the environment variables
241+
- Exposes the server on port 8000 (Neo4j) or 8001 (FalkorDB) for HTTP-based SSE transport
242+
- Includes healthchecks to ensure databases are fully operational before starting the MCP server
201243
202244
## Integrating with MCP Clients
203245
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"mcpServers": {
3+
"graphiti": {
4+
"transport": "sse",
5+
"url": "http://localhost:8001/sse"
6+
}
7+
}
8+
}

mcp_server/docker-compose.yml

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
services:
22
neo4j:
3+
profiles: [""]
34
image: neo4j:5.26.0
45
ports:
56
- "7474:7474" # HTTP
@@ -19,7 +20,8 @@ services:
1920
retries: 5
2021
start_period: 30s
2122

22-
graphiti-mcp:
23+
graphiti-mcp-neo4j:
24+
profiles: [""]
2325
image: zepai/knowledge-graph-mcp:latest
2426
build:
2527
context: .
@@ -31,6 +33,8 @@ services:
3133
neo4j:
3234
condition: service_healthy
3335
environment:
36+
- PORT=8000
37+
- DATABASE_TYPE=neo4j
3438
- NEO4J_URI=${NEO4J_URI:-bolt://neo4j:7687}
3539
- NEO4J_USER=${NEO4J_USER:-neo4j}
3640
- NEO4J_PASSWORD=${NEO4J_PASSWORD:-demodemo}
@@ -42,6 +46,50 @@ services:
4246
- "8000:8000" # Expose the MCP server via HTTP for SSE transport
4347
command: ["uv", "run", "graphiti_mcp_server.py", "--transport", "sse"]
4448

49+
falkordb:
50+
profiles: ["falkordb"]
51+
image: falkordb/falkordb:latest
52+
ports:
53+
- "6379:6379"
54+
command: ["falkordb-server", "--loadmodule", "/FalkorDB/bin/src/falkordb.so"]
55+
volumes:
56+
- falkordb_data:/data
57+
healthcheck:
58+
test: ["CMD", "redis-cli", "ping"]
59+
interval: 10s
60+
timeout: 5s
61+
retries: 5
62+
start_period: 30s
63+
64+
graphiti-mcp-falkordb:
65+
profiles: ["falkordb"]
66+
build:
67+
args:
68+
INSTALL_FALKORDB: "true"
69+
context: .
70+
dockerfile: Dockerfile
71+
env_file:
72+
- path: .env
73+
required: false
74+
depends_on:
75+
falkordb:
76+
condition: service_healthy
77+
environment:
78+
- PORT=8001
79+
- DATABASE_TYPE=falkordb
80+
- FALKORDB_HOST=falkordb
81+
- FALKORDB_PORT=6379
82+
- FALKORDB_USER=${FALKORDB_USER:-}
83+
- FALKORDB_PASSWORD=${FALKORDB_PASSWORD:-}
84+
- OPENAI_API_KEY=${OPENAI_API_KEY}
85+
- MODEL_NAME=${MODEL_NAME}
86+
- PATH=/root/.local/bin:${PATH}
87+
- SEMAPHORE_LIMIT=${SEMAPHORE_LIMIT:-10}
88+
ports:
89+
- "8001:8001" # Expose the MCP server via HTTP for SSE transport
90+
command: ["uv", "run", "graphiti_mcp_server.py", "--transport", "sse"]
91+
4592
volumes:
4693
neo4j_data:
4794
neo4j_logs:
95+
falkordb_data:

0 commit comments

Comments
 (0)