fix: handle root directory startup error from Claude Desktop

- When started from Claude Desktop, working directory might be "/"
- Now defaults to user home directory if cwd is "/"
- Startup scripts change to script directory for consistency
- Simplified README to remove implementation details about PROJECT_ROOT

This fixes the "MCP_PROJECT_ROOT cannot be set to '/'" error
while maintaining security by preventing filesystem-wide access.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Fahad
2025-06-09 20:18:24 +04:00
parent 00b805e0f5
commit 0b424cdd6a
4 changed files with 22 additions and 18 deletions

View File

@@ -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."
)