diff --git a/README.md b/README.md index b56dc30..00396af 100644 --- a/README.md +++ b/README.md @@ -741,21 +741,11 @@ Different tools use optimized temperature settings: **All file paths must be absolute paths.** -### Setup -1. **Use absolute paths** in all tool calls: - ``` - ✅ "Use gemini to analyze /Users/you/project/src/main.py" - ❌ "Use gemini to analyze ./src/main.py" (will be rejected) - ``` - -2. **Set MCP_PROJECT_ROOT** to your project directory for security: - ```json - "env": { - "GEMINI_API_KEY": "your-key", - "MCP_PROJECT_ROOT": "/Users/you/project" - } - ``` - The server only allows access to files within this directory. +When using any Gemini tool, always provide absolute paths: +``` +✅ "Use gemini to analyze /Users/you/project/src/main.py" +❌ "Use gemini to analyze ./src/main.py" (will be rejected) +``` ## Installation diff --git a/run_gemini.bat b/run_gemini.bat index 3a7bbd3..ea48f93 100644 --- a/run_gemini.bat +++ b/run_gemini.bat @@ -4,6 +4,9 @@ REM Windows batch script to run Gemini MCP server REM Get the directory where this script is located set SCRIPT_DIR=%~dp0 +REM Change to script directory to ensure proper working directory +cd /d "%SCRIPT_DIR%" + REM Check if virtual environment exists if exist "%SCRIPT_DIR%venv\Scripts\activate.bat" ( REM Activate the virtual environment diff --git a/run_gemini.sh b/run_gemini.sh index d8ea5ab..7c6d0df 100755 --- a/run_gemini.sh +++ b/run_gemini.sh @@ -15,5 +15,8 @@ else PYTHON_EXEC="python3" fi +# Change to script directory to ensure proper working directory +cd "$SCRIPT_DIR" + # Run the server exec "$PYTHON_EXEC" "$SCRIPT_DIR/server.py" \ No newline at end of file diff --git a/utils/file_utils.py b/utils/file_utils.py index f562a5f..9b9b411 100644 --- a/utils/file_utils.py +++ b/utils/file_utils.py @@ -27,15 +27,23 @@ from .token_utils import estimate_tokens, MAX_CONTEXT_TOKENS # Get project root from environment or use current directory # This defines the sandbox directory where file access is allowed # Security: All file operations are restricted to this directory and its children -PROJECT_ROOT = Path(os.environ.get("MCP_PROJECT_ROOT", os.getcwd())).resolve() +default_root = os.environ.get("MCP_PROJECT_ROOT", os.getcwd()) + +# If current directory is "/" (can happen when launched from Claude Desktop), +# use the user's home directory as a safe default +if default_root == "/" or os.getcwd() == "/": + default_root = os.path.expanduser("~") + +PROJECT_ROOT = Path(default_root).resolve() # Critical Security Check: Prevent running with overly permissive root # Setting PROJECT_ROOT to "/" would allow access to the entire filesystem, # which is a severe security vulnerability if str(PROJECT_ROOT) == "/": raise RuntimeError( - "Security Error: MCP_PROJECT_ROOT cannot be set to '/'. " - "This would give access to the entire filesystem." + "Security Error: PROJECT_ROOT cannot be '/'. " + "This would give access to the entire filesystem. " + "Please set MCP_PROJECT_ROOT environment variable to a specific directory." )