Skip to content

Conversation

@vitali87
Copy link
Owner

@vitali87 vitali87 commented Jan 8, 2026

Summary

  • Add list_projects, delete_project, and wipe_database MCP tools
  • Modify index_repository to use project-scoped deletion instead of wiping entire database
  • Add LIMIT 50 optimization to Cypher queries to prevent token explosion
  • Fix repo path resolution to handle relative paths correctly

Based on PR #178 by @PatD42. Code adapted to project coding standards.

Closes #178

Test plan

  • All existing MCP tests pass (18/18)
  • Pre-commit hooks pass
  • Manual test with Memgraph to verify project isolation

PatD42 and others added 4 commits January 8, 2026 14:06
Add project-scoped database operations that allow managing multiple projects
in the knowledge graph without interference:

- list_projects(): List all indexed projects in the database
- delete_project(): Delete a specific project while preserving others
- wipe_database(): Clear entire database (requires confirmation)
- index_repository(): Now uses project-scoped deletion instead of full wipe

This enables indexing multiple repositories without losing data from other
projects when re-indexing a single repository.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Update system prompts for Cypher generation to:
- Add LIMIT 50 to all listing queries to prevent overwhelming responses
- Use count() aggregation for "how many" queries instead of returning all items
- Add explicit examples for counting patterns

This addresses the issue where asking "how many classes are there?" would
return all 478 classes with full details (~23.6k tokens) instead of just
the count.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Simplify delete_project() to use a single DETACH DELETE query instead of
count + delete (two separate queries). This addresses atomicity concerns
raised in code review.

Changes:
- graph_service.py: Remove count query, single atomic delete
- mcp/tools.py: Remove deleted_nodes from responses
- tests: Update to verify delete_project called instead of clean_database

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Fix empty project name when using relative paths like `.` or `./`.
`Path('.').name` returns empty string, causing broken qualified names.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @vitali87, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the multi-project capabilities of the MCP tools, allowing users to manage multiple codebases within the knowledge graph more effectively. It provides granular control over project data, enabling selective deletion and re-indexing, while also improving query performance and accuracy through optimized Cypher queries and robust path handling.

Highlights

  • Multi-Project Support: Introduced new MCP tools: list_projects to view indexed projects, delete_project to remove a specific project, and wipe_database for a complete database reset. The index_repository tool now performs project-scoped deletion, re-indexing only the current project without affecting others.
  • Cypher Query Optimization: Implemented LIMIT 50 on several example Cypher queries to prevent token explosion and manage response sizes, improving query efficiency and user experience.
  • Repository Path Resolution: Fixed an issue where repository paths were not correctly resolved, ensuring that relative paths are handled properly when determining project names.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces multi-project support, a significant and well-implemented feature. The changes are clean, consistent, and include updated documentation and tests. The approach of using project-scoped deletion is robust. Additionally, the optimization of Cypher queries with LIMIT 50 and improved prompts is a great enhancement. I have one minor suggestion for improving code formatting consistency.

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Overview

Greptile Summary

Added multi-project support to MCP tools enabling project isolation in the knowledge graph. Three new tools (list_projects, delete_project, wipe_database) provide project management capabilities, and index_repository now uses project-scoped deletion instead of wiping the entire database.

Key Changes

  • Added project-scoped deletion query (CYPHER_DELETE_PROJECT) to remove only nodes belonging to a specific project
  • Modified index_repository to call delete_project(project_name) instead of clean_database(), preserving other projects
  • Fixed repo path resolution to use repo_path.resolve().name for consistent project naming with relative paths
  • Added LIMIT 50 to Cypher example queries to prevent token explosion from large result sets
  • Updated prompts with query optimization guidance for aggregation queries

Critical Issue Found

The CYPHER_DELETE_PROJECT query has a logic bug that prevents complete project deletion. It only matches nodes with qualified_name property, missing File nodes (use path), Folder nodes (use path), and ExternalPackage nodes (use name). This will leave orphaned nodes in the database after deletion.

Style Issues

Multiple violations of the TypedDict constructor requirement - the code uses dict literals instead of explicit TypedDict constructors in the new tool handlers.

Confidence Score: 2/5

  • This PR has a critical logic bug that will cause incomplete project deletion, leaving orphaned data in the database
  • Score reflects the critical deletion bug in CYPHER_DELETE_PROJECT that only removes nodes with qualified_name, missing File/Folder/ExternalPackage nodes. While the feature architecture is sound and tests pass, the core deletion functionality is broken. Multiple style violations (TypedDict constructors) are present but non-critical.
  • Pay close attention to codebase_rag/cypher_queries.py - the CYPHER_DELETE_PROJECT query must be fixed before merging

Important Files Changed

File Analysis

Filename Score Overview
codebase_rag/cypher_queries.py 2/5 Added project management queries and LIMIT 50 optimization. Critical issue: CYPHER_DELETE_PROJECT only deletes nodes with qualified_name, missing File/Folder nodes.
codebase_rag/mcp/tools.py 3/5 Added list_projects, delete_project, wipe_database tools. Changed index_repository to use project-scoped deletion. Multiple TypedDict constructor violations (style).
codebase_rag/services/graph_service.py 4/5 Added list_projects and delete_project methods to MemgraphIngestor. Clean implementation following existing patterns.
codebase_rag/types_defs.py 3/5 Added ListProjectsResult and DeleteProjectResult TypedDicts. Fields should not all be optional - success path requires certain fields.
codebase_rag/graph_updater.py 5/5 Changed project_name to use repo_path.resolve().name instead of repo_path.name. Good fix for relative path handling.
codebase_rag/tests/test_mcp_query_and_index.py 5/5 Updated tests to verify delete_project is called instead of clean_database. Tests properly validate project isolation behavior.

Sequence Diagram

sequenceDiagram
    participant User
    participant MCP as MCPToolsRegistry
    participant Ingestor as MemgraphIngestor
    participant Updater as GraphUpdater
    participant DB as Memgraph Database

    Note over User,DB: New Feature: list_projects
    User->>MCP: list_projects()
    MCP->>Ingestor: list_projects()
    Ingestor->>DB: CYPHER_LIST_PROJECTS
    DB-->>Ingestor: project names
    Ingestor-->>MCP: list[str]
    MCP-->>User: ListProjectsResult

    Note over User,DB: New Feature: delete_project
    User->>MCP: delete_project(project_name)
    MCP->>Ingestor: list_projects()
    Ingestor->>DB: CYPHER_LIST_PROJECTS
    DB-->>Ingestor: projects
    Ingestor-->>MCP: projects
    MCP->>MCP: validate project exists
    MCP->>Ingestor: delete_project(project_name)
    Ingestor->>DB: CYPHER_DELETE_PROJECT
    DB-->>Ingestor: deletion complete
    Ingestor-->>MCP: success
    MCP-->>User: DeleteProjectResult

    Note over User,DB: New Feature: wipe_database
    User->>MCP: wipe_database(confirm=true)
    MCP->>MCP: check confirm flag
    MCP->>Ingestor: clean_database()
    Ingestor->>DB: CYPHER_DELETE_ALL
    DB-->>Ingestor: all data deleted
    Ingestor-->>MCP: success
    MCP-->>User: success message

    Note over User,DB: Modified: index_repository (project-scoped)
    User->>MCP: index_repository()
    MCP->>MCP: project_name = Path.resolve().name
    MCP->>Ingestor: delete_project(project_name)
    Ingestor->>DB: CYPHER_DELETE_PROJECT
    DB-->>Ingestor: project data deleted
    Ingestor-->>MCP: success
    MCP->>Updater: GraphUpdater(repo_path, ...)
    MCP->>Updater: run()
    Updater->>Ingestor: ensure_node_batch(...)
    Updater->>Ingestor: ensure_relationship_batch(...)
    Ingestor->>DB: batch insert nodes/rels
    DB-->>Ingestor: success
    Ingestor-->>Updater: success
    Updater-->>MCP: indexing complete
    MCP-->>User: success with project_name
Loading

@vitali87
Copy link
Owner Author

vitali87 commented Jan 8, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request successfully introduces multi-project support to the MCP tools, a significant and valuable enhancement. The new tools for listing, deleting, and wiping projects are well-implemented, and the core logic change in index_repository to use project-scoped deletion is correct in principle. The addition of comprehensive integration tests is particularly commendable as it provides strong confidence in the new multi-project functionality. Other improvements like the LIMIT 50 query optimization and the fix for relative path resolution are also great additions.

I've found one critical issue with the project deletion query that could lead to data corruption in a multi-project setup, and one medium-severity suggestion for a minor refactoring to improve code clarity. Both comments are valid and have been included in the review.

@vitali87
Copy link
Owner Author

vitali87 commented Jan 8, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces significant and well-implemented multi-project support for the MCP tools. The addition of list_projects, delete_project, and wipe_database tools, along with the modification of index_repository to be project-scoped, is a great enhancement. The changes are robust, with comprehensive integration and unit tests that ensure project isolation. The optimizations to Cypher queries using LIMIT and the fix for relative path resolution are also valuable improvements. Overall, this is a high-quality contribution.

@vitali87
Copy link
Owner Author

vitali87 commented Jan 8, 2026

@greptile

@vitali87
Copy link
Owner Author

vitali87 commented Jan 8, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces significant multi-project support to the MCP tools, including new functionalities for listing, deleting, and wiping projects. The indexing logic has been updated to be project-scoped, which is a crucial improvement. I appreciate the performance optimization of adding LIMIT to Cypher queries and the fix for resolving relative repository paths. The new integration tests provide good coverage for the new features. I have a couple of minor suggestions to improve code quality and performance.

KEY_FROM_VAL = "from_val"
KEY_TO_VAL = "to_val"
KEY_VERSION_SPEC = "version_spec"
KEY_PREFIX = "prefix"
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The constant KEY_PREFIX is introduced but doesn't seem to be used anywhere in the codebase. To maintain code cleanliness and avoid dead code, it's best to remove it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants