@@ -513,17 +513,70 @@ The agent will incorporate the guidance from your reference documents when sugge
513513
514514Code-Graph-RAG can run as an MCP (Model Context Protocol) server, enabling seamless integration with Claude Code and other MCP clients.
515515
516+ ### MCP Dual Mode System (v0.0.60+)
517+
518+ The MCP server now supports two distinct modes with different capabilities and security profiles:
519+
520+ #### Query Mode (Production Recommended)
521+ ** Read-only access** for safe codebase exploration and analysis.
522+
523+ ** Available Tools:**
524+ - ` list_projects ` - List all indexed projects
525+ - ` query_code_graph ` - Natural language graph queries
526+ - ` get_code_snippet ` - Retrieve source code by qualified name
527+ - ` list_directory ` - Browse directory structure
528+
529+ ** Use Cases:**
530+ - Production environments where code modification is not allowed
531+ - Code review and exploration
532+ - Documentation generation
533+ - Architecture analysis
534+
535+ #### Edit Mode (Development)
536+ ** Full access** including file editing and database management.
537+
538+ ** Additional Tools (beyond Query mode):**
539+ - ` read_file ` / ` write_file ` - File operations
540+ - ` surgical_replace_code ` - Precise code editing
541+ - ` delete_project ` - Remove projects from graph
542+ - ` wipe_database ` - Complete database reset (dangerous!)
543+ - ` index_repository ` - Build/update knowledge graph
544+
545+ ** Use Cases:**
546+ - Local development environments
547+ - Code refactoring assistance
548+ - Automated code generation
549+ - Database maintenance
550+
516551### Quick Setup
517552
553+ #### Query Mode (Recommended for Production)
554+
555+ ``` bash
556+ claude mcp add --transport stdio code-graph-rag \
557+ --env TARGET_REPO_PATH=" $( pwd) " \
558+ --env MCP_MODE=query \
559+ --env CYPHER_PROVIDER=openai \
560+ --env CYPHER_MODEL=gpt-4 \
561+ --env CYPHER_API_KEY=your-api-key \
562+ -- uv run --directory /path/to/code-graph-rag code-graph-rag mcp-server
563+ ```
564+
565+ #### Edit Mode (For Development)
566+
518567``` bash
519568claude mcp add --transport stdio code-graph-rag \
520- --env TARGET_REPO_PATH=/absolute/path/to/your/project \
569+ --env TARGET_REPO_PATH=" $( pwd) " \
570+ --env MCP_MODE=edit \
571+ --env ALLOWED_PROJECT_ROOTS=" $( pwd) " \
521572 --env CYPHER_PROVIDER=openai \
522573 --env CYPHER_MODEL=gpt-4 \
523574 --env CYPHER_API_KEY=your-api-key \
524575 -- uv run --directory /path/to/code-graph-rag code-graph-rag mcp-server
525576```
526577
578+ ** Important:** Always set ` ALLOWED_PROJECT_ROOTS ` in Edit mode to restrict file operations to specific directories.
579+
527580### Available Tools
528581
529582<!-- SECTION:mcp_tools -->
@@ -543,13 +596,48 @@ claude mcp add --transport stdio code-graph-rag \
543596
544597### Example Usage
545598
599+ #### Query Mode
546600```
547- > Index this repository
548601> What functions call UserService.create_user?
602+ > Show me all classes that implement Repository
603+ > List all modules in the utils package
604+ > Get the source code for AuthService.login
605+ ```
606+
607+ #### Edit Mode
608+ ```
609+ > Index this repository
549610> Update the login function to add rate limiting
611+ > Refactor this class to use dependency injection
612+ > Delete the deprecated project from the graph
550613```
551614
552- For detailed setup, see [ Claude Code Setup Guide] ( docs/claude-code-setup.md ) .
615+ ### Security Configuration
616+
617+ For Edit mode, always restrict access with ` ALLOWED_PROJECT_ROOTS ` :
618+
619+ ``` bash
620+ # Single project
621+ --env ALLOWED_PROJECT_ROOTS=" /path/to/project"
622+
623+ # Multiple projects (comma-separated)
624+ --env ALLOWED_PROJECT_ROOTS=" /path/to/project1,/path/to/project2"
625+ ```
626+
627+ This ensures file operations cannot modify files outside the specified directories.
628+
629+ ### Mode Selection Guide
630+
631+ | Scenario | Recommended Mode | Reasoning |
632+ | ----------| -----------------| -----------|
633+ | Production code review | Query | Prevents accidental modifications |
634+ | Development work | Edit | Allows code generation and editing |
635+ | CI/CD pipelines | Query | Read-only analysis is sufficient |
636+ | Local experimentation | Edit | Full control for testing |
637+ | Multi-project analysis | Query | Safe exploration across projects |
638+ | Code refactoring | Edit | Requires write access |
639+
640+ For detailed setup and configuration examples, see [ Claude Code Setup Guide] ( docs/claude-code-setup.md ) and [ Security Best Practices] ( docs/security-best-practices.md ) .
553641
554642## 📊 Graph Schema
555643
@@ -560,20 +648,20 @@ The knowledge graph uses the following node types and relationships:
560648<!-- SECTION:node_schemas -->
561649| Label | Properties |
562650| -----| ----------|
563- | Project | ` {name: string} ` |
564- | Package | ` {qualified_name: string, name: string, path: string} ` |
565- | Folder | ` {path: string, name: string} ` |
566- | File | ` {path: string, name: string, extension: string} ` |
567- | Module | ` {qualified_name: string, name: string, path: string} ` |
568- | Class | ` {qualified_name: string, name: string, decorators: list[string]} ` |
569- | Function | ` {qualified_name: string, name: string, decorators: list[string]} ` |
570- | Method | ` {qualified_name: string, name: string, decorators: list[string]} ` |
571- | Interface | ` {qualified_name: string, name: string} ` |
572- | Enum | ` {qualified_name: string, name: string} ` |
573- | Type | ` {qualified_name: string, name: string} ` |
574- | Union | ` {qualified_name: string, name: string} ` |
575- | ModuleInterface | ` {qualified_name: string, name: string, path: string} ` |
576- | ModuleImplementation | ` {qualified_name: string, name: string, path: string, implements_module: string} ` |
651+ | Project | ` {name: string, absolute_path: string, project_name: string } ` |
652+ | Package | ` {qualified_name: string, name: string, path: string, absolute_path: string, project_name: string } ` |
653+ | Folder | ` {path: string, name: string, absolute_path: string, project_name: string } ` |
654+ | File | ` {path: string, name: string, extension: string, absolute_path: string, project_name: string } ` |
655+ | Module | ` {qualified_name: string, name: string, path: string, absolute_path: string, project_name: string } ` |
656+ | Class | ` {qualified_name: string, name: string, path: string, absolute_path: string, project_name: string, decorators: list[string]} ` |
657+ | Function | ` {qualified_name: string, name: string, path: string, absolute_path: string, project_name: string, decorators: list[string]} ` |
658+ | Method | ` {qualified_name: string, name: string, path: string, absolute_path: string, project_name: string, decorators: list[string]} ` |
659+ | Interface | ` {qualified_name: string, name: string, path: string, absolute_path: string, project_name: string } ` |
660+ | Enum | ` {qualified_name: string, name: string, path: string, absolute_path: string, project_name: string } ` |
661+ | Type | ` {qualified_name: string, name: string, path: string, absolute_path: string, project_name: string } ` |
662+ | Union | ` {qualified_name: string, name: string, path: string, absolute_path: string, project_name: string } ` |
663+ | ModuleInterface | ` {qualified_name: string, name: string, path: string, absolute_path: string, project_name: string } ` |
664+ | ModuleImplementation | ` {qualified_name: string, name: string, path: string, absolute_path: string, project_name: string, implements_module: string} ` |
577665| ExternalPackage | ` {name: string, version_spec: string} ` |
578666<!-- /SECTION:node_schemas -->
579667
@@ -653,6 +741,10 @@ Configuration is managed through environment variables in `.env` file:
653741- ` TARGET_REPO_PATH ` : Default repository path (default: ` . ` )
654742- ` LOCAL_MODEL_ENDPOINT ` : Fallback endpoint for Ollama (default: ` http://localhost:11434/v1 ` )
655743
744+ ### MCP Server Configuration
745+ - ` MCP_MODE ` : MCP server operation mode - ` query ` (read-only) or ` edit ` (full access). Default: ` edit ` . ** Recommended: Use ` query ` mode for production environments.**
746+ - ` ALLOWED_PROJECT_ROOTS ` : Comma-separated list of allowed project root paths for file operations in Edit mode. This is a critical security setting that restricts file read/write operations to specified directories. Example: ` /path/to/project1,/path/to/project2 `
747+
656748### Custom Ignore Patterns
657749
658750You can specify additional directories to exclude by creating a ` .cgrignore ` file in your repository root:
0 commit comments