cognee-mcp
The Cognee MCP server is a multi-functional tool for managing knowledge graphs with four main capabilities:
Cognify: Converts text into a structured knowledge graph
Codify: Transforms a codebase into a knowledge graph
Search: Allows searching within the knowledge graph with customizable search types
Prune: Simplifies and optimizes the knowledge graph as needed
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@cognee-mcpingest my project documentation from the docs folder"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
cognee‑mcp - Run cognee’s memory engine as a Model Context Protocol server
Build memory for Agents and query from any client that speaks MCP – in your terminal or IDE.
✨ Features
Multiple transports – choose Streamable HTTP --transport http (recommended for web deployments), SSE --transport sse (real‑time streaming), or stdio (classic pipe, default)
Cloud Mode – connect to Cognee Cloud via
--serve-urlorCOGNEE_SERVICE_URLenv var (see Connection Modes)API Mode – connect to an already running Cognee FastAPI server (see Connection Modes)
Minimal Memory API – exposes only
remember,recall, andforgetfor agent memory workflowsIntegrated logging – all actions written to a rotating file (see get_log_file_location()) and mirrored to console in dev
Session-aware memory – store fast session cache entries or permanent graph memory through one
remembertoolFocused recall – query memory through one
recalltool with optional session and search controlsSimple deletion – remove a dataset or all owned memory through one
forgettool
Please refer to our documentation here for further information.
Related MCP server: MCP AI Memory
🚀 Quick Start
Clone cognee repo
git clone https://github.com/topoteretes/cognee.gitNavigate to cognee-mcp subdirectory
cd cognee/cognee-mcpInstall uv if you don't have one
pip install uvInstall all the dependencies you need for cognee mcp server with uv
uv sync --dev --all-extras --reinstallActivate the virtual environment in cognee mcp directory
source .venv/bin/activateSet up your OpenAI API key in .env for a quick setup with the default cognee configurations
LLM_API_KEY="YOUR_OPENAI_API_KEY"(Optional — running from source only) Build the MCP App workspace UI bundle. Requires Node.js. Docker users skip this; the image build runs it automatically.
cd apps-src && npm install && npm run build && cd ..This produces
src/app_bundles/visualize-graph.html, which is gitignored. If you skip this step,visualize_graph_uiand the workspace tools will raise a clear error pointing back to this command.Run cognee mcp server with stdio (default)
python src/server.pyor stream responses over SSE
python src/server.py --transport sseor run with Streamable HTTP transport (recommended for web deployments)
python src/server.py --transport http --host 127.0.0.1 --port 8000 --path /mcp
You can do more advanced configurations by creating .env file using our template. To use different LLM providers / database configurations, and for more info check out our documentation.
🐳 Docker Usage
If you'd rather run cognee-mcp in a container, you have two options:
Build locally
Make sure you are in /cognee root directory and have a fresh
.envcontaining only yourLLM_API_KEY(and your chosen settings).Remove any old image and rebuild:
docker rmi cognee/cognee-mcp:main || true docker build --no-cache -f cognee-mcp/Dockerfile -t cognee/cognee-mcp:main .Run it:
# For HTTP transport (recommended for web deployments) docker run -e TRANSPORT_MODE=http --env-file ./.env -p 8000:8000 --rm -it cognee/cognee-mcp:main # For SSE transport docker run -e TRANSPORT_MODE=sse --env-file ./.env -p 8000:8000 --rm -it cognee/cognee-mcp:main # For stdio transport (default) docker run -e TRANSPORT_MODE=stdio --env-file ./.env --rm -it cognee/cognee-mcp:mainInstalling optional dependencies at runtime:
You can install optional dependencies when running the container by setting the
EXTRASenvironment variable:# Install a single optional dependency group at runtime docker run \ -e TRANSPORT_MODE=http \ -e EXTRAS=aws \ --env-file ./.env \ -p 8000:8000 \ --rm -it cognee/cognee-mcp:main # Install multiple optional dependency groups at runtime (comma-separated) docker run \ -e TRANSPORT_MODE=sse \ -e EXTRAS=aws,postgres,neo4j \ --env-file ./.env \ -p 8000:8000 \ --rm -it cognee/cognee-mcp:mainAvailable optional dependency groups:
aws- S3 storage supportpostgres/postgres-binary- PostgreSQL database supportneo4j- Neo4j graph database supportneptune- AWS Neptune supportchromadb- ChromaDB vector store supportscraping- Web scraping capabilitiesdistributed- Modal distributed executionlangchain- LangChain integrationllama-index- LlamaIndex integrationanthropic- Anthropic modelsgroq- Groq modelsmistral- Mistral modelsollama/huggingface- Local model supportdocs- Document processingcodegraph- Code analysismonitoring- Sentry & Langfuse monitoringredis- Redis supportAnd more (see pyproject.toml for full list)
Pull from Docker Hub (no build required):
# With HTTP transport (recommended for web deployments) docker run -e TRANSPORT_MODE=http --env-file ./.env -p 8000:8000 --rm -it cognee/cognee-mcp:main # With SSE transport docker run -e TRANSPORT_MODE=sse --env-file ./.env -p 8000:8000 --rm -it cognee/cognee-mcp:main # With stdio transport (default) docker run -e TRANSPORT_MODE=stdio --env-file ./.env --rm -it cognee/cognee-mcp:mainWith runtime installation of optional dependencies:
# Install optional dependencies from Docker Hub image docker run \ -e TRANSPORT_MODE=http \ -e EXTRAS=aws,postgres \ --env-file ./.env \ -p 8000:8000 \ --rm -it cognee/cognee-mcp:main
Important: Docker vs Direct Usage
Docker uses environment variables, not command line arguments:
✅ Docker:
-e TRANSPORT_MODE=http❌ Docker:
--transport http(won't work)
Direct Python usage uses command line arguments:
✅ Direct:
python src/server.py --transport http❌ Direct:
-e TRANSPORT_MODE=http(won't work)
Docker API Mode
To connect the MCP Docker container to a Cognee API server running on your host machine:
Simple Usage (Automatic localhost handling):
# Start your Cognee API server on the host
python -m cognee.api.client
# Run MCP container in API mode - localhost is automatically converted!
docker run \
-e TRANSPORT_MODE=sse \
-e API_URL=http://localhost:8000 \
-e API_TOKEN=your_auth_token \
-p 8001:8000 \
--rm -it cognee/cognee-mcp:mainNote: The container will automatically convert localhost to host.docker.internal on Mac/Windows/Docker Desktop. You'll see a message in the logs showing the conversion.
Explicit host.docker.internal (Mac/Windows):
# Or explicitly use host.docker.internal
docker run \
-e TRANSPORT_MODE=sse \
-e API_URL=http://host.docker.internal:8000 \
-e API_TOKEN=your_auth_token \
-p 8001:8000 \
--rm -it cognee/cognee-mcp:mainOn Linux (use host network or container IP):
# Option 1: Use host network (simplest)
docker run \
--network host \
-e TRANSPORT_MODE=sse \
-e API_URL=http://localhost:8000 \
-e API_TOKEN=your_auth_token \
--rm -it cognee/cognee-mcp:main
# Option 2: Use host IP address
# First, get your host IP: ip addr show docker0
docker run \
-e TRANSPORT_MODE=sse \
-e API_URL=http://172.17.0.1:8000 \
-e API_TOKEN=your_auth_token \
-p 8001:8000 \
--rm -it cognee/cognee-mcp:mainEnvironment variables for API mode:
API_URL: URL of the running Cognee API serverAPI_TOKEN: Authentication token (optional, required if API has authentication enabled)
Note: When running in API mode:
Database migrations are automatically skipped (API server handles its own DB)
Some features are limited (see API Mode Limitations)
🔗 MCP Client Configuration
After starting your Cognee MCP server with Docker, you need to configure your MCP client to connect to it.
SSE Transport Configuration (Recommended)
Start the server with SSE transport:
docker run -e TRANSPORT_MODE=sse --env-file ./.env -p 8000:8000 --rm -it cognee/cognee-mcp:mainConfigure your MCP client:
Claude CLI (Easiest)
claude mcp add cognee-sse -t sse http://localhost:8000/sseVerify the connection:
claude mcp listYou should see your server connected:
Checking MCP server health...
cognee-sse: http://localhost:8000/sse (SSE) - ✓ ConnectedManual Configuration
Claude (~/.claude.json)
{
"mcpServers": {
"cognee": {
"type": "sse",
"url": "http://localhost:8000/sse"
}
}
}Cursor (~/.cursor/mcp.json)
{
"mcpServers": {
"cognee-sse": {
"url": "http://localhost:8000/sse"
}
}
}HTTP Transport Configuration (Alternative)
Start the server with HTTP transport:
docker run -e TRANSPORT_MODE=http --env-file ./.env -p 8000:8000 --rm -it cognee/cognee-mcp:mainConfigure your MCP client:
Claude CLI (Easiest)
claude mcp add cognee-http -t http http://localhost:8000/mcpVerify the connection:
claude mcp listYou should see your server connected:
Checking MCP server health...
cognee-http: http://localhost:8000/mcp (HTTP) - ✓ ConnectedManual Configuration
Claude (~/.claude.json)
{
"mcpServers": {
"cognee": {
"type": "http",
"url": "http://localhost:8000/mcp"
}
}
}Cursor (~/.cursor/mcp.json)
{
"mcpServers": {
"cognee-http": {
"url": "http://localhost:8000/mcp"
}
}
}Dual Configuration Example
You can configure both transports simultaneously for testing:
{
"mcpServers": {
"cognee-sse": {
"type": "sse",
"url": "http://localhost:8000/sse"
},
"cognee-http": {
"type": "http",
"url": "http://localhost:8000/mcp"
}
}
}Note: Only enable the server you're actually running to avoid connection errors.
🌐 Connection Modes
The MCP server supports three connection modes:
Direct Mode (Default)
The MCP server directly imports and uses the cognee library with local databases (SQLite, LanceDB, Ladybug). This is the default mode with full feature support.
Cloud Mode
Connect to Cognee Cloud or a remote Cognee instance. The server calls cognee.serve() at startup, and all SDK operations transparently route to the cloud. No local databases needed.
Via CLI flags:
python src/server.py --serve-url https://your-instance.cognee.ai --serve-api-key ck_...Via environment variables (zero-config):
export COGNEE_SERVICE_URL="https://your-instance.cognee.ai"
export COGNEE_API_KEY="ck_..."
python src/server.pyCloud Mode with Docker:
docker run \
-e TRANSPORT_MODE=sse \
-e COGNEE_SERVICE_URL=https://your-instance.cognee.ai \
-e COGNEE_API_KEY=ck_... \
-p 8000:8000 \
--rm -it cognee/cognee-mcp:mainCloud Mode arguments / environment variables:
--serve-url/COGNEE_SERVICE_URL: Cognee Cloud or remote instance URL--serve-api-key/COGNEE_API_KEY: API key for the instance
Database migrations are automatically skipped in Cloud mode.
API Mode
The MCP server connects to an already running Cognee FastAPI server via HTTP requests. This is useful when:
You have a centralized Cognee API server running
You want to separate the MCP server from the knowledge graph backend
You need multiple MCP servers to share the same knowledge graph
Starting the MCP server in API mode:
# Start your Cognee FastAPI server first (default port 8000)
cd /path/to/cognee
python -m cognee.api.client
# Then start the MCP server in API mode
cd cognee-mcp
python src/server.py --api-url http://localhost:8000 --api-token YOUR_AUTH_TOKENAPI Mode with different transports:
# With SSE transport
python src/server.py --transport sse --api-url http://localhost:8000 --api-token YOUR_TOKEN
# With HTTP transport
python src/server.py --transport http --api-url http://localhost:8000 --api-token YOUR_TOKENAPI Mode with Docker:
# On Mac/Windows (use host.docker.internal to access host)
docker run \
-e TRANSPORT_MODE=sse \
-e API_URL=http://host.docker.internal:8000 \
-e API_TOKEN=YOUR_TOKEN \
-p 8001:8000 \
--rm -it cognee/cognee-mcp:main
# On Linux (use host network)
docker run \
--network host \
-e TRANSPORT_MODE=sse \
-e API_URL=http://localhost:8000 \
-e API_TOKEN=YOUR_TOKEN \
--rm -it cognee/cognee-mcp:mainCommand-line arguments for API mode:
--api-url: Base URL of the running Cognee FastAPI server (e.g.,http://localhost:8000)--api-token: Authentication token for the API (optional, required if API has authentication enabled)
Docker environment variables for API mode:
API_URL: Base URL of the running Cognee FastAPI serverAPI_TOKEN: Authentication token (optional, required if API has authentication enabled)
API Mode behavior:
The MCP server intentionally exposes only the memory API: remember, recall, and forget.
In API mode these tools call the Cognee API server endpoints directly. Operational helpers such as
cognify, search, list_data, delete, prune, improve, and document retrieval helpers are
kept internal and are not exposed as MCP tools.
💻 Basic Usage
The MCP server exposes its functionality through tools. Call them from any MCP client (Cursor, Claude Desktop, Cline, Roo and more).
Available Tools
The MCP server exposes three tools:
remember: Store data in memory. With
session_id: fast session cache. Withoutsession_id: permanent graph memoryrecall: Search memory with auto-routing. Searches session cache first when
session_idis provided, then falls through to the permanent graphforget: Delete memory by dataset name, or delete all owned memory with
everything=True
Workspace UI Tools (MCP Apps — Cursor, Claude Desktop, etc.):
visualize_graph_ui: Open the workspace and render the current knowledge graph
upload_file_ui: Open the workspace for file upload
open_cognee_workspace: Generic "open the cognee UI" entry point
cognify_file: Ingest an uploaded file (used by the workspace; accepts base64 content)
list_datasets_json / list_dataset_data_json / create_dataset_json / get_client_info_json: Structured-JSON helpers powering the workspace dropdown
The workspace lets you create/switch/delete datasets, upload files, add text, search, and view the graph from one inline panel.
The bundle that powers the workspace lives at cognee-mcp/src/app_bundles/visualize-graph.html. It is built from cognee-mcp/apps-src/ via npm run build and is gitignored. The Docker image builds it as part of the image; PyPI wheels carry it (the maintainer runs npm run build before uv build); from-source users build it manually (see Quick Start step 7). If the bundle is missing at runtime, the workspace tools raise a FileNotFoundError pointing back to the build command.
Agent Scoping (per-client default datasets)
By default, each MCP client gets its own auto-named dataset (e.g. Cursor → cursor_vscode_memory, Claude Code → claude_code_memory) so different agents don't share memory unintentionally. The dataset is created on demand the first time a client calls a workspace tool.
LLM-direct calls to cognify, remember, improve, cognify_status, and cognify_file route to the agent-scoped dataset when dataset_name is omitted. Pass dataset_name explicitly to override (e.g. dataset_name="main_dataset" still works).
To disable agent scoping and have all clients share main_dataset as the default, set in .env:
COGNEE_MCP_AGENT_SCOPED=falseWhen disabled, the workspace UI header shows (agent scoping off) and no per-client datasets are autocreated.
Per-dataset isolation (ENABLE_BACKEND_ACCESS_CONTROL)
Agent scoping decides which dataset name a tool defaults to. Whether two datasets are actually isolated at the storage layer is governed by cognee's ENABLE_BACKEND_ACCESS_CONTROL flag:
false(default) — all datasets share one Kuzu graph DB and one LanceDB. The dataset filter is honored for top-level data points, butGRAPH_COMPLETIONtraversal can pull connected nodes from any dataset, andvisualize_graph_uireflects the full shared graph. Fastest path; fine for single-user local dev.true— each(user, dataset)pair gets its own per-dataset Kuzu + LanceDB under.cognee_system/databases/<dataset_uuid>/.visualize_graph_uiand search become strictly per-dataset because the workspace passesdataset_nameand the server routes the visualization through cognee'svisualize_multi_user_graphto set the right DB context.
Switching modes wipes nothing automatically — but data does not migrate. Data ingested in one mode lives at a different on-disk path than the other and won't be visible after the flip. Clean-slate when changing the flag:
# Stop server, then:
DATA_ROOT="/absolute/path/to/data-root"
rm -rf "$DATA_ROOT/.cognee_system" "$DATA_ROOT/.data_storage"
# Edit .env to flip ENABLE_BACKEND_ACCESS_CONTROL, restart, re-cognify.(Set DATA_ROOT to whatever you used for DATA_ROOT_DIRECTORY / SYSTEM_ROOT_DIRECTORY, or your cognee install dir if you didn't set those.)
Examples:
# Store permanent memory
remember(data="Cognee MCP now exposes a focused memory API.", dataset_name="main_dataset")
# Store session memory
remember(data="Temporary working note", session_id="agent-session-1")
# Recall from memory
recall(query="What changed in the MCP server?", session_id="agent-session-1")
# Delete one dataset
forget(dataset="main_dataset")Development and Debugging
Debugging
To use debugger, run:
bash mcp dev src/server.py
Open inspector with timeout passed:
http://localhost:5173?timeout=120000
To apply new changes while developing cognee you need to do:
Update dependencies in cognee folder if needed
uv sync --dev --all-extras --reinstallmcp dev src/server.py
Development
In order to use local cognee:
Uncomment the following line in the cognee-mcp
pyproject.tomlfile and set the cognee root path.#"cognee[postgres,codegraph,gemini,huggingface,docs,neo4j] @ file:/Users/<username>/Desktop/cognee"Remember to replace
file:/Users/<username>/Desktop/cogneewith your actual cognee root path.Install dependencies with uv in the mcp folder
uv sync --reinstall
Code of Conduct
We are committed to making open source an enjoyable and respectful experience for our community. See CODE_OF_CONDUCT for more information.
💫 Contributors
Star History
Maintenance
Appeared in Searches
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/topoteretes/cognee'
If you have feedback or need assistance with the MCP directory API, please join our Discord server