This playbook breaks down exactly how the install_context_aware.sh script works, step by step.
Purpose: Install the Qdrant RAG MCP Server globally so it works from any project directory
Result: Context-aware MCP server that automatically scopes to your current project
Your System:
├── ~/mcp-servers/qdrant-rag/ # The MCP server code
├── ~/.claude-code/mcp-servers.json # Claude's MCP configuration
└── ~/.mcp-servers/ # May or may not exist
#!/bin/bash
set -e # Exit on any errorWhat happens:
- Script will stop if any command fails
- Ensures clean installation or clear failure
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"What happens:
- Finds where the install script is running from
- Example:
/Users/antoncoleman/Documents/repos/mcp-servers/qdrant-rag - This is where all the MCP server code lives
GLOBAL_MCP_DIR="$HOME/.mcp-servers"
mkdir -p "$GLOBAL_MCP_DIR"What happens:
- Creates
~/.mcp-servers/directory if it doesn't exist - This will be the central location for all MCP servers
- The
-pflag prevents errors if directory exists
Result:
~/.mcp-servers/ # Now exists
ln -sfn "$SCRIPT_DIR" "$GLOBAL_MCP_DIR/qdrant-rag"What happens:
- Creates a symbolic link from
~/.mcp-servers/qdrant-rag→ your actual code -s= symbolic link-f= force (overwrite if exists)-n= treat destination as normal file if it's a symlink
Result:
~/.mcp-servers/
└── qdrant-rag -> /Users/antoncoleman/Documents/repos/mcp-servers/qdrant-rag
cat > "$GLOBAL_MCP_DIR/qdrant-rag-context.sh" << 'EOF'
#!/bin/bash
# Context-aware runner for Qdrant RAG MCP Server
# Get the real path of the MCP server
MCP_SERVER_DIR="$(readlink -f "$HOME/.mcp-servers/qdrant-rag")"
# Save current directory (this is important for context detection)
CURRENT_DIR="$(pwd)"
# Change to the server directory to load environment
cd "$MCP_SERVER_DIR"
# Load environment variables
if [ -f .env ]; then
set -a
source .env
set +a
fi
# Change back to the original directory so the server detects the correct project
cd "$CURRENT_DIR"
# Run the context-aware version with the current directory as context
exec uv run --directory "$MCP_SERVER_DIR" python "$MCP_SERVER_DIR/src/qdrant_mcp_context_aware.py"
EOFWhat this runner script does:
- Resolves the symlink to find actual code location
- Saves your current directory (critical for project detection!)
- Temporarily changes to MCP directory to load
.envfile - Returns to your original directory so Python script sees correct context
- Runs the Python server with
uvfrom the MCP directory
Why this matters: This allows the server to:
- Load its configuration from its install location
- But detect your project from where you're actually working
chmod +x "$GLOBAL_MCP_DIR/qdrant-rag-context.sh"What happens:
- Makes the runner script executable
- Now it can be run as a command
CLAUDE_CONFIG="$HOME/.claude-code/mcp-servers.json"
if [ -f "$CLAUDE_CONFIG" ]; then
cp "$CLAUDE_CONFIG" "$CLAUDE_CONFIG.backup.$(date +%Y%m%d_%H%M%S)"
fiWhat happens:
- Locates Claude's MCP configuration file
- If it exists, creates a timestamped backup
- Example:
mcp-servers.json.backup.20240522_143022
cat > "$CLAUDE_CONFIG" << EOF
{
"servers": [
{
"name": "qdrant-rag",
"command": "$GLOBAL_MCP_DIR/qdrant-rag-context.sh"
}
]
}
EOFWhat happens:
- Overwrites Claude's MCP config
- Points to our context-aware runner script
- Claude will now run this script when starting the MCP server
Final config looks like:
{
"servers": [
{
"name": "qdrant-rag",
"command": "/Users/antoncoleman/.mcp-servers/qdrant-rag-context.sh"
}
]
}Your System:
├── ~/mcp-servers/qdrant-rag/ # Original code (unchanged)
├── ~/.mcp-servers/
│ ├── qdrant-rag -> ~/mcp-servers/... # Symlink to code
│ └── qdrant-rag-context.sh # Smart runner script
└── ~/.claude-code/
├── mcp-servers.json # Updated config
└── mcp-servers.json.backup.20240522... # Backup
When you start Claude CLI:
- Claude reads
~/.claude-code/mcp-servers.json - Claude executes
~/.mcp-servers/qdrant-rag-context.sh - Runner script:
- Remembers your current directory (e.g.,
~/projects/my-app) - Loads environment from MCP install directory
- Returns to your project directory
- Starts Python server
- Remembers your current directory (e.g.,
- Python server:
- Sees your current directory as
~/projects/my-app - Detects this as the project context
- Scopes all operations to this project
- Sees your current directory as
# You're in your React project
cd ~/projects/my-react-app
claude # Start Claude CLI
# Behind the scenes:
# 1. Claude runs: ~/.mcp-servers/qdrant-rag-context.sh
# 2. Script saves: CURRENT_DIR="/Users/you/projects/my-react-app"
# 3. Script loads: .env from MCP install location
# 4. Script returns to: /Users/you/projects/my-react-app
# 5. Python starts and detects: "Current project is my-react-app"
# 6. All searches/indexes now scoped to my-react-app collections| Component | Purpose | What breaks without it |
|---|---|---|
| Symlink | Points to actual code | Can't find MCP server code |
| Runner script | Preserves working directory | Wrong project detection |
| Current dir save/restore | Enables context detection | Always uses global context |
| Environment loading | Gets database config | Can't connect to Qdrant |
| Claude config | Tells Claude what to run | Claude can't find MCP server |
If something goes wrong, check:
- Symlink exists:
ls -la ~/.mcp-servers/ - Runner is executable:
ls -la ~/.mcp-servers/qdrant-rag-context.sh - Claude config is correct:
cat ~/.claude-code/mcp-servers.json - Runner script works:
~/.mcp-servers/qdrant-rag-context.sh(should start server)
This playbook shows how a seemingly simple install script actually sets up a sophisticated context-aware system!