Graphiti MCP Server
by mateicanavra
The Graphiti MCP Server allows AI agents to interact with a knowledge graph for persistent memory, entity extraction, and relationship tracking using the Graphiti framework. It includes a command-line interface (CLI) tool for project management and deployment.
Last updated: N/A
Graphiti MCP Server
This repository contains the Graphiti Model Context Protocol (MCP) Server and its associated command-line interface (CLI) tool. It allows AI agents to interact with a knowledge graph for persistent memory, entity extraction, and relationship tracking using the Graphiti framework.
Features
- Exposes Graphiti functionality via MCP (SSE or Stdio transport).
- Provides tools for adding/searching episodes, nodes, and facts in a knowledge graph.
- Supports custom entity type definitions for tailored extraction.
- Includes a CLI (
graphiti) for project initialization, entity management, and Docker environment control. - Uses Docker Compose for easy deployment of the MCP server(s) and Neo4j database.
- Leverages
uvfor fast dependency management.
Prerequisites
- Python: Version 3.10 or higher (
python3 --version). Python 3.11+ recommended (as used in Dockerfile). - Docker & Docker Compose: Required to run the Neo4j database and MCP server containers. Install from Docker's official website.
uv: A fast Python package installer and resolver. If you don't have it, install it first (requirespiporcurl):# Using pip (recommended if you have Python/pip already) pip install uv # Or using curl # curl -LsSf https://astral.sh/uv/install.sh | sh # source $HOME/.cargo/env # Or equivalent for your shell if using curl method # Verify installation uv --version- Git: For cloning the repository.
Installation and Setup Guide
This guide covers how to install the graphiti CLI and set up the necessary environment. Choose the path that best suits your needs:
- For Regular Users (Recommended): Install the CLI globally using
pipxfor managing projects and running services. - For Developers: Set up a local development environment using
venvif you plan to modify the CLI or server code.
1. Standard Installation for Users (Using pipx)
This is the strongly recommended method if you primarily want to use the graphiti CLI to initialize projects, manage entities, and run the Docker services. pipx installs the CLI into an isolated environment, making it available system-wide without interfering with other Python projects.
Why pipx?
- Isolation: Prevents dependency conflicts.
- Clean Global Environment: Keeps your system Python tidy.
- Safety: Avoids issues with
sudo pipor modifying system Python.
Prerequisites:
- Python: 3.10+ (
python3 --version). - Docker & Docker Compose: Install from Docker's official website.
uv: Follow the instructions in the Prerequisites section above.pipx: If you don't have it:# Install pipx (requires Python and pip) python3 -m pip install --user pipx # Add pipx to your PATH python3 -m pipx ensurepath # Close and reopen your terminal, or source your shell profile (e.g., ~/.zshrc, ~/.bashrc)
Steps:
-
Clone This Repository: You need the source code to build the CLI and access configuration files (like
base-compose.yaml). Clone it to a stable location (e.g.,~/dev/rawr-mcp-graphiti).# Choose a suitable parent directory cd ~/dev git clone <repository-url> rawr-mcp-graphiti cd rawr-mcp-graphiti -
Configure Environment Variables (Optional but Recommended):
- Copy the example
.envfile within the cloned repository:# Make sure you are in the cloned repo directory (e.g., ~/dev/rawr-mcp-graphiti) cp .env.example .env - Edit
.env: Fill in required secrets and configurations (Neo4j credentials, OpenAI key, etc.). See the "Configure Environment" section under Developer Setup for details.
- Copy the example
-
Install CLI using
pipx: Navigate to the root of the cloned repository (rawr-mcp-graphiti) in your terminal and run:# Make sure you are in the cloned repo directory pipx install . --include-deps- This installs the
rawr-mcp-graphitipackage into an isolatedpipxenvironment. --include-depsensures necessary runtime dependencies are included.
- This installs the
-
First Run & Repo Path Configuration:
- The first time you run a
graphiticommand that needs to access the repository (likegraphiti check-setuporgraphiti compose), it might not find the repository automatically. - If it can't find it, the CLI will prompt you interactively to enter the absolute path to where you cloned the
rawr-mcp-graphitirepository. - Enter the correct absolute path (e.g.,
/Users/your_user/dev/rawr-mcp-graphiti). - The CLI will validate the path and save it to a configuration file (
~/.config/graphiti/repo_path.txt) for future use.
# Example: Run check-setup from ANY directory after installation graphiti check-setup # If needed, it will prompt for the repo path here. - The first time you run a
-
Verify Installation:
# Check where pipx installed it which graphiti # Should output a path like: /Users/<your_user>/.local/bin/graphiti # Verify the CLI runs and can find the repo (due to MCP_GRAPHITI_REPO_PATH) # Run this from ANY directory (e.g., your home directory `cd ~`) graphiti --help graphiti check-setup # This should now work from anywhere without prompting (if configured)- If
check-setupfails, ensure the path saved in~/.config/graphiti/repo_path.txtis correct, or remove the file and run the command again to be re-prompted.
- If
-
Updating: To update after pulling changes in the repository:
# Navigate back to the repository root cd /path/to/your/rawr-mcp-graphiti # Pull the latest changes git pull # Upgrade the pipx installation pipx upgrade rawr-mcp-graphiti # If needed, force a reinstall from the updated source: # pipx reinstall --force rawr-mcp-graphiti
Summary for Users: Clone the repo, copy/edit .env, install with pipx. Run a command like graphiti check-setup; if prompted, provide the absolute path to the cloned repo. The path will be saved automatically for future use.
2. Local Development Installation (Using venv)
Follow these steps only if you intend to modify or contribute to the graphiti CLI or the MCP server codebase itself. This setup uses a Python virtual environment (.venv) and an editable installation, allowing code changes to be reflected immediately when running graphiti within the activated environment.
Prerequisites:
- Same as for Standard Installation (Python, Docker,
uv).pipxis not required for this method.
Steps:
-
Clone the Repository:
git clone <repository-url> rawr-mcp-graphiti cd rawr-mcp-graphiti -
Configure Environment:
- Copy the example environment file:
cp .env.example .env - Edit
.env: Fill in required secrets and configurations:NEO4J_USER,NEO4J_PASSWORD: Credentials for Neo4j.OPENAI_API_KEY: OpenAI key.MODEL_NAME: (Optional) OpenAI model.- Adjust other settings (ports, memory) if needed.
MCP_GRAPHITI_REPO_PATH: While the CLI run from within the activevenvand repo root might find the root automatically, relying on the auto-prompt or the config file (~/.config/graphiti/repo_path.txt) generated on first use (even within the venv) is the recommended approach now. You can still set the environment variable as a manual override if needed.
- Copy the example environment file:
-
Set up Python Virtual Environment:
# Create the virtual environment python3 -m venv .venv # Activate it (example for macOS/Linux) source .venv/bin/activate # You should see (.venv) in your prompt -
Install Dependencies:
- Use
uvto install dependencies from the lock file into the activevenv.
# Make sure (.venv) is active uv pip sync uv.lock - Use
-
Install CLI in Editable Mode:
- Install the package itself in editable mode (
-e). This links thegraphiticommand within thevenvdirectly to your source code.
# Make sure (.venv) is active pip install -e . # ('uv pip install -e .' should also work) - Install the package itself in editable mode (
-
Verify Installation:
# Verify it's using the venv path which graphiti # Should output path inside your .venv/bin/ # Verify the CLI runs (ensure venv is active) graphiti --help graphiti check-setup # Run from repo root
Summary for Developers: Clone, copy/edit .env, set up .venv, activate it, uv pip sync, pip install -e .. Run commands from within the repo root with the venv active. The repo path will be auto-detected or prompted for and saved on first use.
Understanding Which graphiti You're Using
- Global (
pipx): If no(.venv)is in your prompt, you're likely using thepipxversion. It relies on the path stored in~/.config/graphiti/repo_path.txt(or prompts on first use). Updates requirepipx upgrade. - Local (
venv): If(.venv)is in your prompt (aftersource .venv/bin/activate), you're using the editable development version. Code changes are live. Ideally, run from the repo root. Deactivate withdeactivate.
Verifying Your Setup
Regardless of the installation method, use check-setup.
- If using
pipx: Rungraphiti check-setupfrom any directory. It relies on the configured path in~/.config/graphiti/repo_path.txt(or prompts). - If using
venv: Activate thevenv(source .venv/bin/activate) and rungraphiti check-setupfrom the repository root directory.
# Example for pipx user (run from anywhere):
graphiti check-setup
# Example for developer (activate venv first, run from repo root):
# source .venv/bin/activate
# graphiti check-setup
This command checks:
- Repository Root: Finds the root (via config file
~/.config/graphiti/repo_path.txt, env var override, or relative paths for venv). .envFile: Checks if the.envfile exists at the identified repository root and if essential variables are loaded.- Docker Status: Verifies that the
dockercommand is available in yourPATHand that the Docker daemon appears to be running and responsive.
If all checks pass, you're ready to proceed.
Running the Services (Docker)
The MCP server and its Neo4j database run as Docker containers managed by Docker Compose. These commands (compose, up, down, etc.) must be run from the root of the rawr-mcp-graphiti repository. Ensure your CLI (either pipx or venv) is set up correctly and can find the repository root.
-
Generate Docker Compose Configuration:
- The
graphitiCLI generates the finaldocker-compose.ymlfrombase-compose.yaml(in the repo) and project definitions inmcp-projects.yaml(also in the repo). - Navigate to the repository root and run:
# cd /path/to/your/rawr-mcp-graphiti graphiti compose - This command reads
mcp-projects.yaml. If you initialize new projects usinggraphiti init, this file will be updated automatically with absolute paths to your projects. Ensure these paths are correct for your system, as they are used for Docker volume mounts. - It also updates the
.cursor/mcp.jsonfile in each enabled project's root directory.
- The
-
Start Services:
- Build and start the containers (Neo4j, root MCP server, and any project-specific servers defined in
mcp-projects.yaml):graphiti up - To run in detached mode (in the background):
graphiti up -d - The first time you run this, Docker may build the
graphiti-mcp-serverimage. Subsequent starts are faster. - The root MCP server will typically be available at
http://localhost:8000(or the port specified byMCP_ROOT_HOST_PORTin.env). Project-specific servers will be available on ports assigned sequentially starting from 8001 (or as configured in their respectivemcp-config.yamlfiles). Check the output ofgraphiti composefor port assignments. - You can usually access the Neo4j Browser UI in your web browser at
http://localhost:7474to interact with the database directly (use the credentials from your.envfile).
- Build and start the containers (Neo4j, root MCP server, and any project-specific servers defined in
-
Check Status:
- View running containers:
docker ps - View logs:
graphiti logsordocker compose logs -f [service_name](e.g.,docker compose logs -f graphiti-mcp-root)
- View running containers:
-
Stop Services:
- Stop and remove the containers:
graphiti down
- Stop and remove the containers:
-
Other Docker Commands:
- Restart services:
graphiti restart [-d](Runsdownthenup) - Reload (restart) a specific service:
graphiti reload <service_name>(e.g.,graphiti reload graphiti-mcp-root)
- Restart services:
Using the graphiti CLI
The graphiti CLI helps manage projects and the Docker environment. Run graphiti --help to see all commands.
Key Command Locations:
- Run from Repository Root (
rawr-mcp-graphiti/):graphiti compose: Generatesdocker-compose.yml.graphiti up|down|restart|reload|logs: Manages Docker services.graphiti check-setup: Verifies setup (especially useful here for venv users).
- Run from Project Parent Directory:
graphiti init <project_name> [target_dir]: Initializes a new project structure in the specified directory.
- Run from Existing Project Root Directory:
graphiti entity <set_name>: Creates a new entity definition template within this project'sentitiesdirectory.graphiti rules <project_name>: Sets up/updates Cursor rule symlinks for this project.
Example Workflow:
- Install CLI (
pipxrecommended for users). cd /path/to/your/rawr-mcp-graphitigraphiti composegraphiti up -d(Start services)cd /path/to/where/you/keep/projectsgraphiti init my-new-ai-projectcd my-new-ai-projectgraphiti entity user-profiles(Create entity definitions inside./ai/graph/entities/)- Edit
user-profiles.yaml... - The
my-new-ai-projectis now registered inmcp-projects.yaml(in the repo root). If you re-rungraphiti composeandgraphiti up -d(from the repo root), a dedicated MCP server instance for this project might be started (depending on the base config).
Development Notes
- Generating
uv.lock: If theuv.lockfile is missing or out of date, you can regenerate it frompyproject.tomlusing:# Activate venv uv pip compile pyproject.toml --output-file uv.lock # Or potentially just: uv pip lock # Commit the updated uv.lock file to the repository. - Local
graphiti-coreDevelopment: If you are developinggraphiti-corelocally alongside this server:- Build the
graphiti-corewheel file (e.g.,python3 -m build) in thegraphiti-corerepository. This creates files in itsdist/directory. - Ensure the
dist/directory containing the.whlfile exists at the root of the main Graphiti repository (one level aboverawr-mcp-graphiti). The path might need adjustment depending on your exact structure post-extraction. - In
rawr-mcp-graphiti/pyproject.toml, ensure the linegraphiti-core = {path = "../dist/graphiti_core-...-py3-none-any.whl"}(adjust path/filename) is uncommented. Comment out the versioned linegraphiti-core>=.... - Re-run
uv pip sync uv.lockorpip install -e .in your venv. - The Docker build process might also need adjustment if it doesn't automatically pick up the local wheel installation from the venv. Consider adding a
COPY ../dist /distandRUN uv pip install /dist/*.whlin the Dockerfile's builder stage if needed.
- Build the
- Running Server without Docker: You can run the server directly for debugging:
# Ensure .env is loaded or variables are exported # Activate venv: source .venv/bin/activate # Example: python3 graphiti_mcp_server.py --transport sse --group-id my-test-group --log-level debug # Add other flags like --use-custom-entities, --entity-type-dir as needed
⚠️ DANGER ZONE: Clearing the Database ⚠️
The environment variable NEO4J_DESTROY_ENTIRE_GRAPH in your .env file is extremely dangerous.
- Setting
NEO4J_DESTROY_ENTIRE_GRAPH=truewill PERMANENTLY DELETE ALL DATA in your Neo4j database when the containers start. - This affects ALL knowledge graphs, not just a specific
group_id. - This action cannot be undone.
- Only set this to
trueif you are absolutely certain you want to wipe the entire database. - Immediately comment it out or set it back to
falseafter use to prevent accidental data loss on subsequent restarts.