Skip to content
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

Merged
merged 2 commits into from
Dec 23, 2024
Merged

Feat/cognee mcp #400

merged 2 commits into from
Dec 23, 2024

Conversation

borisarzentar
Copy link
Contributor

@borisarzentar borisarzentar commented Dec 23, 2024

Summary by CodeRabbit

  • New Features

    • Streamlined setup process with updated instructions for cloning the repository and configuring the server.
    • Introduced new tools: "cognify", "search", and "prune" for enhanced functionality.
  • Bug Fixes

    • Corrected directory path references in setup instructions.
  • Documentation

    • Updated README to reflect changes in setup and configuration steps.
  • Chores

    • Project renamed from "mcpcognee" to "cognee-mcp" across various files.

@borisarzentar borisarzentar self-assigned this Dec 23, 2024
Copy link
Contributor

coderabbitai bot commented Dec 23, 2024

Walkthrough

This 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

File Change Summary
README.md Updated repository cloning instructions, modified directory structure reference, simplified configuration steps
cognee_mcp/__init__.py Updated __all__ declaration from single to double quotes
cognee_mcp/server.py Renamed server from "mcpcognee" to "cognee-mcp", redefined tools (added "cognify", "search", "prune"), updated tool handling logic
mcpcognee/__main__.py File deleted, removing direct module execution entry point
pyproject.toml Renamed project from "mcpcognee" to "cognee-mcp", updated script entry point

Sequence Diagram

sequenceDiagram
    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
Loading

Possibly related PRs

Suggested labels

run-checks

Suggested reviewers

  • dexters1
  • Vasilije1990

Poem

🐰 A Rabbit's Ode to Renaming 🔧

From mcpcognee to cognee-mcp we leap,
Refactoring code with a technological sweep
Tools redefined, paths made clear
A server's journey, without a fear
Hop, hop, hurrah! The changes are here! 🚀

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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_require

The 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 format

The GitHub URL should use the https:// protocol instead of www.

-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 manager

Consider 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 paths

Using 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 setup

The current development setup has a few potential issues:

  1. The hardcoded relative path ../../cognee in tool.uv.sources might break in different environments
  2. 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

📥 Commits

Reviewing files that changed from the base of the PR and between b73a35f and 29de5a3.

⛔ 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

Comment on lines +13 to 16
3. Activate the venv with

```jsx
source .venv/bin/activate
Copy link
Contributor

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

Comment on lines 37 to 41

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.
Copy link
Contributor

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:

  1. Adding an example snippet showing the required packages in pyproject.toml
  2. Providing a code example of how to define the cognify tool in server.py
  3. Explaining the relationship between these configurations

Comment on lines +30 to +35
"env": {
"ENV": "local",
"TOKENIZERS_PARALLELISM": "false",
"LLM_API_KEY": "add_your_api_key_here",
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix JSON format and add API key validation

  1. Remove the trailing comma in the JSON object (line 34)
  2. 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.

Suggested change
"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"
}
}

Comment on lines 1 to 41
# 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.
Copy link
Contributor

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:

  1. Prerequisites section:
  • Python version requirement (UV requires Python 3.7+)
  • UV package manager installation instructions
  • Git for cloning the repository
  1. Testing section:
  • Basic import test exists in tests/import_test.py
  • Add instructions to run tests using pytest
  1. 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:

  1. Prerequisites section (Python version, required tools)
  2. Troubleshooting section for common issues
  3. 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

@Vasilije1990 Vasilije1990 merged commit e770eda into dev Dec 23, 2024
8 checks passed
@Vasilije1990 Vasilije1990 deleted the feat/cognee-mcp branch December 23, 2024 15:10
@coderabbitai coderabbitai bot mentioned this pull request Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants