-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/cognee mcp #400
Feat/cognee mcp #400
Conversation
WalkthroughThis pull request involves a comprehensive renaming and restructuring of the MCP (Microservice Control Plane) Cognee project. The changes span multiple files, transitioning from "mcpcognee" to "cognee-mcp", updating server functionality, and modifying project configuration. The modifications include renaming project directories, updating tool definitions in the server, simplifying configuration processes, and adjusting entry points for the application. Changes
Sequence DiagramsequenceDiagram
participant Client
participant Server
participant KnowledgeGraph
Client->>Server: Call Tool
alt Cognify Tool
Server->>KnowledgeGraph: Build Knowledge Graph
KnowledgeGraph-->>Server: Graph Built
Server-->>Client: Ingestion Successful
else Search Tool
Server->>KnowledgeGraph: Search Query
KnowledgeGraph-->>Server: Search Results
Server-->>Client: Return Results
else Prune Tool
Server->>KnowledgeGraph: Reset Graph
KnowledgeGraph-->>Server: Graph Pruned
Server-->>Client: Graph Reset
end
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Tip CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
🔭 Outside diff range comments (1)
cognee-mcp/pyproject.toml (1)
Line range hint
8-89
: Improve dependency management with extras_requireThe current approach of marking optional dependencies with comments should be replaced with proper Python packaging extras_require configuration. This would allow users to install only the dependencies they need.
Consider restructuring the dependencies like this:
[project] dependencies = [ "mcp>=1.1.1", "openai==1.52.0", # ... core dependencies ... ] + +[project.optional-dependencies] +database = [ + "falkordb==1.0.9", + "neo4j>=5.20.0,<6.0.0", + "pgvector>=0.3.5,<0.4.0", + "psycopg2>=2.9.10,<3.0.0", +] +vector-stores = [ + "qdrant-client>=1.9.0,<2.0.0", + "weaviate-client==4.6.7", + "pymilvus>=2.5.0,<3.0.0", +] +document-processing = [ + "unstructured[csv,doc,docx,epub,md,odt,org,ppt,pptx,rst,rtf,tsv,xlsx]>=0.16.10,<1.0.0", +]This allows users to install optional dependencies with:
pip install cognee-mcp[database,vector-stores]
🧹 Nitpick comments (7)
cognee-mcp/cognee_mcp/server.py (3)
18-23
: Streamlined node representation.
This new node formatting is more succinct. However, be mindful of situations in which you might need the additional keys (e.g., debugging or exploring the knowledge graph deeply). If those use cases arise, consider adding optional debug flags.
78-87
: New “prune” tool
The “prune” tool is a welcome addition to reset the knowledge graph. However, note that “query” is present in the input schema but not apparently used. If it’s for potential future usage or a placeholder, consider adding a comment clarifying this. Otherwise, remove it to avoid confusion.- "properties": { - "query": {"type": "string"}, - }, + "properties": {}
100-126
: “cognify” tool logic
• Good job wrapping stdout/stderr for a noiseless experience.
• Properly handling missing arguments with a ValueError is correct.
• Consider logging ingestion progress or capturing partial results if you need debugging.cognee-mcp/README.md (3)
3-3
: Fix the GitHub repository URL formatThe GitHub URL should use the
https://
protocol instead ofwww
.-1. Clone the [cognee](www.github.com/topoteretes/cognee) repo +1. Clone the [cognee](https://github.com/topoteretes/cognee) repo
9-10
: Add context about the uv package managerConsider adding a brief explanation about
uv
and why it's preferred over pip, especially for new contributors.
26-26
: Consider using relative paths instead of absolute pathsUsing absolute paths makes the configuration less portable across different environments. Consider using relative paths or environment variables for the directory path.
cognee-mcp/pyproject.toml (1)
Line range hint
103-111
: Consider environment-agnostic development setupThe current development setup has a few potential issues:
- The hardcoded relative path
../../cognee
intool.uv.sources
might break in different environments- Development dependencies could be moved to
project.optional-dependencies
Consider using environment variables or a more flexible path resolution:
[tool.uv.sources] -cognee = { path = "../../cognee" } +cognee = { path = "${COGNEE_PATH:-../../cognee}" } -[dependency-groups] -dev = [ - "cognee", -] +[project.optional-dependencies] +dev = [ + "cognee", + "pytest>=7.4.0,<8.0.0", + "pytest-asyncio>=0.21.1,<0.22.0", + "coverage>=7.3.2,<8.0.0", + "mypy>=1.7.1,<2.0.0", + "deptry>=0.20.0,<0.21.0", + "debugpy==1.8.2", + "pylint>=3.0.3,<4.0.0", + "ruff>=0.2.2,<0.3.0", +]
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
cognee-mcp/uv.lock
is excluded by!**/*.lock
📒 Files selected for processing (5)
cognee-mcp/README.md
(1 hunks)cognee-mcp/cognee_mcp/__init__.py
(1 hunks)cognee-mcp/cognee_mcp/server.py
(4 hunks)cognee-mcp/mcpcognee/__main__.py
(0 hunks)cognee-mcp/pyproject.toml
(2 hunks)
💤 Files with no reviewable changes (1)
- cognee-mcp/mcpcognee/main.py
✅ Files skipped from review due to trivial changes (1)
- cognee-mcp/cognee_mcp/init.py
🔇 Additional comments (10)
cognee-mcp/cognee_mcp/server.py (8)
3-3
: Ensure that asyncio is necessary and properly leveraged.
The new import for asyncio is fine as long as you're using it in this file (which you do, in the main function). Consider removing if unused to keep imports clean.
55-76
: New “cognify” and “search” tool schemas
The addition of the “cognify” and “search” tools with simplified schemas is well-structured. Ensure their usage across the codebase is consistent (e.g., references in docs or clients). Also confirm that “graph_model_file” and “graph_model_name” remain optional only if the default class suffices in all scenarios.
93-94
: Refined method signature
Updating the signature for “handle_call_tool” to accept possible None arguments is good for safety. Ensure you have robust error handling for missing arguments.
127-146
: “search” tool improvements
• The searching logic is straightforward.
• The function “retrieved_edges_to_string” is leveraged effectively.
• Consider normalizing or sanitizing user input to safeguard from unexpected data in “search_query.”
147-155
: Prune tool usage
• The existing calls to prune both data and system metadata ensure a clean slate.
• Double-check concurrency or other clients that might need this “reset” to be notified.
169-173
: Initialization options
These lines reflect the updated server name and version. Ensure that any public referencing or external logs also reflect this new identity to avoid confusion.
176-180
: Async entry point
Switching to an explicit asyncio entry point is a best practice for modern Python. This helps with clarity for asynchronous operations.
14-14
: Server renaming alignment.
Renaming the server from "mcpcognee" to "cognee-mcp" aligns with the rebranding. Confirm that all references in the broader codebase are updated accordingly.
✅ Verification successful
Let me search for any references to both the old and new server names in the codebase.
Based on the search results, I can see that the new server name "cognee-mcp" appears in several files, while there are no occurrences of the old name "mcpcognee". Let me verify if there are any other potential variations of the server name.
Server name alignment verified.
The codebase consistently uses "cognee-mcp" as the server name across all relevant files, and there are no remaining instances of the old name "mcpcognee". The server name is properly aligned in:
- Server initialization:
server = Server("cognee-mcp")
- Server configuration:
server_name = "cognee-mcp"
- Package and directory structure:
cognee-mcp/
🏁 Scripts executed
The following scripts were executed for the analysis:
Error: No shell scripts found
Script:
#!/bin/bash
# Search for both old and new server names
echo "Searching for 'mcpcognee':"
rg "mcpcognee" -l
echo -e "\nSearching for 'cognee-mcp':"
rg "cognee-mcp" -l
# Also search in configuration files that might contain server names
echo -e "\nSearching in config/yaml/json files:"
fd -e yaml -e yml -e json -e conf -e cfg -e ini -x cat {}
Length of output: 79683
Script:
#!/bin/bash
# Search for potential variations of the server name
echo "Searching for variations:"
rg -i "mcp.*cognee|cognee.*mcp" -l
# Check Python files specifically for any server name references
echo -e "\nChecking Python files for server configurations:"
fd -e py -x cat {} | grep -i "server\(.*\)="
Length of output: 564
cognee-mcp/pyproject.toml (2)
94-94
: Verify the new module path exists
The entry point has been updated to use the new module name. Let's verify the new module structure.
✅ Verification successful
Entry point module and function verified
The verification shows that both the module cognee_mcp
and the main()
function exist in the correct location. Specifically:
- The module exists at
cognee-mcp/cognee_mcp/__init__.py
- The main function is defined in this module and serves as the entry point
- The main function correctly delegates to the server's main function
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Check if the new module exists
fd "cognee_mcp" --type f --extension py
# Check for the main function in the module
ast-grep --pattern 'def main():'
Length of output: 74
Script:
#!/bin/bash
# Let's try searching for Python files in the repository
fd --type f --extension py
# Also check for any Python files with 'main' function
rg "def main" --type py -A 2
Length of output: 23891
2-2
: Verify project name change impact across the codebase
The project rename from "mcpcognee" to "cognee-mcp" looks good, but we should verify all references have been updated.
✅ Verification successful
Project rename verification completed successfully
No references to the old name "mcpcognee" were found in the codebase, indicating that the project rename to "cognee-mcp" has been properly implemented across all files. The absence of any matches in Python files, documentation, configuration files, and import statements confirms a thorough rename.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for any remaining references to the old name
rg -i "mcpcognee" --type-not toml
# Check import statements that might need updating
ast-grep --pattern 'import mcpcognee'
ast-grep --pattern 'from mcpcognee import'
Length of output: 118
Script:
#!/bin/bash
# Let's try a more comprehensive search for any remaining references
# Search for old name in various forms and file types
rg -i "mcpcognee"
# Search for potential package references in Python files
fd -e py -x cat {} | rg -i "mcpcognee"
# Check setup files and documentation
fd -e md -e rst -e cfg -e ini -x cat {} | rg -i "mcpcognee"
# Look for any import-like patterns that might have been missed
rg -i "from.*mcpcognee|import.*mcpcognee"
Length of output: 164
3. Activate the venv with | ||
|
||
```jsx | ||
source .venv/bin/activate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add virtual environment creation step
The instructions assume the virtual environment exists but don't explain how to create it. Consider adding the creation step before activation.
+2a. Create a virtual environment with
+
+```jsx
+python -m venv .venv
+```
+
3. Activate the venv with
|
||
Then, edit the pyproject.toml in your new folder so that it includes packages from the cognee requirements. Use the pyproject.toml in your cognee library for this, but match the syntax of the automatically generated pyproject.toml so that it is compatible with uv. | ||
|
||
Define cognify tool in server.py | ||
Restart your Claude desktop. | ||
Restart your Claude desktop. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Enhance the final instructions with specific examples
The instructions about modifying pyproject.toml
and defining the cognify tool are too vague. Consider:
- Adding an example snippet showing the required packages in
pyproject.toml
- Providing a code example of how to define the cognify tool in
server.py
- Explaining the relationship between these configurations
"env": { | ||
"ENV": "local", | ||
"TOKENIZERS_PARALLELISM": "false", | ||
"LLM_API_KEY": "add_your_api_key_here", | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix JSON format and add API key validation
- Remove the trailing comma in the JSON object (line 34)
- Consider adding a note about validating the LLM_API_KEY before use
"env": {
"ENV": "local",
"TOKENIZERS_PARALLELISM": "false",
- "LLM_API_KEY": "add_your_api_key_here",
+ "LLM_API_KEY": "add_your_api_key_here"
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
"env": { | |
"ENV": "local", | |
"TOKENIZERS_PARALLELISM": "false", | |
"LLM_API_KEY": "add_your_api_key_here", | |
} | |
} | |
"env": { | |
"ENV": "local", | |
"TOKENIZERS_PARALLELISM": "false", | |
"LLM_API_KEY": "add_your_api_key_here" | |
} | |
} |
# cognee MCP server | ||
|
||
A MCP server project | ||
1. Clone the [cognee](www.github.com/topoteretes/cognee) repo | ||
|
||
Create a boilerplate server: | ||
|
||
```jsx | ||
uvx create-mcp-server | ||
``` | ||
|
||
1. The command will ask you to name your server, e.g. mcp_cognee | ||
|
||
|
||
2. Answer “Y” to connect with Claude | ||
Then run | ||
2. Install dependencies | ||
|
||
```jsx | ||
cd mcp_cognee | ||
cd cognee-mcp | ||
uv sync --dev --all-extras | ||
``` | ||
|
||
Activate the venv with | ||
3. Activate the venv with | ||
|
||
```jsx | ||
source .venv/bin/activate | ||
``` | ||
|
||
This should already add the new server to your Claude config, but if not, add these lines manually: | ||
|
||
``` | ||
"mcpcognee": { | ||
"command": "uv", | ||
"args": [ | ||
"--directory", | ||
"/Users/your_username/mcp/mcp_cognee", | ||
"run", | ||
"mcpcognee" | ||
], | ||
"env": { | ||
"ENV": "local", | ||
"TOKENIZERS_PARALLELISM": "false", | ||
"LLM_API_KEY": "add_your_api_key_here", | ||
"GRAPH_DATABASE_PROVIDER": "neo4j", | ||
"GRAPH_DATABASE_URL": "bolt://localhost:7687", | ||
"GRAPH_DATABASE_USERNAME": "add_username_here", | ||
"GRAPH_DATABASE_PASSWORD": "add_pwd_here", | ||
"VECTOR_DB_PROVIDER": "lancedb", | ||
"DB_PROVIDER": "sqlite", | ||
"DB_NAME": "postgres" | ||
} | ||
} | ||
4. Add the new server to your Claude config: | ||
|
||
```json | ||
"cognee": { | ||
"command": "uv", | ||
"args": [ | ||
"--directory", | ||
"/{Absolute path to cognee directory}/cognee-mcp", | ||
"run", | ||
"cognee" | ||
], | ||
"env": { | ||
"ENV": "local", | ||
"TOKENIZERS_PARALLELISM": "false", | ||
"LLM_API_KEY": "add_your_api_key_here", | ||
} | ||
} | ||
``` | ||
|
||
Then, edit the pyproject.toml in your new folder so that it includes packages from the cognee requirements. Use the pyproject.toml in your cognee library for this, but match the syntax of the automatically generated pyproject.toml so that it is compatible with uv. | ||
|
||
Define cognify tool in server.py | ||
Restart your Claude desktop. | ||
Restart your Claude desktop. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Let me analyze the output and generate the final response based on the verification results.
Add prerequisites and testing sections to improve setup instructions
The setup instructions should be enhanced with:
- Prerequisites section:
- Python version requirement (UV requires Python 3.7+)
- UV package manager installation instructions
- Git for cloning the repository
- Testing section:
- Basic import test exists in tests/import_test.py
- Add instructions to run tests using pytest
- Troubleshooting section:
- Common UV sync issues
- Python environment problems
- Configuration file errors
• Add these sections before step 1 in the README.md
The current documentation lacks important setup prerequisites and validation steps that could help users avoid common issues. The test files found in the codebase indicate testing capabilities that should be documented for verifying successful setup.
🔗 Analysis chain
Verify completeness of setup instructions
Please verify that all necessary setup steps are included. Consider adding:
- Prerequisites section (Python version, required tools)
- Troubleshooting section for common issues
- Testing instructions to verify successful setup
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Check if all referenced files exist
fd -t f "pyproject.toml|server.py" -x echo "Found: {}"
# Look for any testing instructions in the codebase
rg -i "test|pytest" -g "!*.pyc"
Length of output: 104270
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Chores